1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
# Copyright 2011-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
module AWS
class SimpleWorkflow
# The primary interface for registering, listing and deprecating
# domains.
#
# ## Creating a Domain
#
# To create a domain you need to pass a unique name to #create.
#
# domain = simple_workflow.domains.create('my-domain', :none)
# #=> #<AWS::SimpleWorkflow::Domain name:my-domain>
#
# ## Getting a Domain
#
# Domains are indexed by their name.
#
# domain = simple_workflow.domains['my-domain']
#
# ## Enumerating Domains
#
# You can call Enumerable methods on a domain collection to iterate
# the domains controlled by your account.
#
# simple_workflow.domains.each {|domain| ... }
#
# By default only registered domains are enumerated. If you would like
# to enumerate deprecated (deleted) domains you need to pass the
# `:deprecated` option.
#
# # returns an array of names for all deprecated domains
# simple_workflow.domains.deprecated.map(&:name)
#
# See {AWS::Core::Collection} to see other useful methods you can
# call against a domain collection (e.g. #enum, #page, #each_batch).
#
class DomainCollection
include OptionFormatters
include Core::Collection::WithLimitAndNextToken
def initialize options = {}
@registration_status = options[:registration_status] ?
options[:registration_status].to_s.upcase : 'REGISTERED'
@reverse_order = options.key?(:reverse_order) ?
!!options[:reverse_order] : false
super(options)
end
# Registers a new domain.
#
# # register a domain named 'domain' that has no expiry on workflow
# # execution history
# domain = AWS::SimpleWorkflow.new.domains.register('domain', :none)
#
# @param [String] name Name of the domain to register. The name must
# be unique.
#
# @param [Integer,:none] retention_period A duration (in days)
# for which the record (including the history) of workflow
# executions in this domain should be kept by the service.
# After the retention period, the workflow execution will not be
# available in the results of visibility calls.
#
# If you pass the symbol `:none` then there is no expiration for
# workflow execution history (effectively an infinite retention
# period).
#
# @param [Hash] options
#
# @option [String] :description (nil) Textual description of the domain.
#
# @return [Domain] Returns the newly created {Domain} object.
#
def register name, retention_period, options = {}
client_opts = {}
client_opts[:name] = name
client_opts[:workflow_execution_retention_period_in_days] = retention_period
client_opts[:description] = options[:description] if options[:description]
duration_opts(client_opts, :workflow_execution_retention_period_in_days)
client.register_domain(client_opts)
client_opts[:retention_period] = retention_period.to_s =~ /^\d+$/ ?
retention_period.to_i : retention_period.to_s.downcase.to_sym
Domain.new(name, client_opts.merge(:config => config))
end
alias_method :create, :register
# @return [Domain] Returns the domain with the given name.
def [] name
Domain.new(name, :config => config)
end
# @return [DomainCollection] Returns a domain collection that
# will only enumerate registered domains.
def registered
collection_with(:registration_status => 'REGISTERED')
end
# @return [DomainCollection] Returns a domain collection that
# will only enumerate deprecated (deleted) domains.
def deprecated
collection_with(:registration_status => 'DEPRECATED')
end
# @return [DomainCollection] Returns a domain collection that
# enumerates domains in reverse alphabetical order. Default
# ordering is ascending alphabetical.
def reverse_order
collection_with(:reverse_order => true)
end
protected
def collection_with options = {}
self.class.new({
:registration_status => @registration_status,
:reverse_order => @reverse_order,
:config => config,
}.merge(options))
end
protected
def _each_item next_token, limit, options = {}, &block
options[:maximum_page_size] = limit if limit
options[:next_page_token] = next_token if next_token
options[:registration_status] ||= @registration_status
options[:reverse_order] = @reverse_order unless
options.has_key?(:reverse_order)
response = client.list_domains(options)
response.data['domainInfos'].each do |desc|
domain = Domain.new_from(:list_domains, desc,
desc['name'], :config => config)
yield(domain)
end
response.data['nextPageToken']
end
end
end
end
|