Class: Awsum::Ec2::Region

Inherits:
Object show all
Defined in:
lib/awsum/ec2/region.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ec2, name, end_point) ⇒ Region

:nodoc:



8
9
10
11
12
# File 'lib/awsum/ec2/region.rb', line 8

def initialize(ec2, name, end_point) #:nodoc:
  @ec2 = ec2
  @name = name
  @end_point = end_point
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object (private)

– Will pass all missing methods onto the ec2 object



50
51
52
53
54
# File 'lib/awsum/ec2/region.rb', line 50

def method_missing(method_name, *args, &block)
  use do
    @ec2.send(method_name, *args, &block)
  end
end

Instance Attribute Details

#end_pointObject (readonly)

Returns the value of attribute end_point.



6
7
8
# File 'lib/awsum/ec2/region.rb', line 6

def end_point
  @end_point
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/awsum/ec2/region.rb', line 6

def name
  @name
end

Instance Method Details

#availability_zonesObject

List the AvailabilityZone(s) of this Region



15
16
17
18
19
# File 'lib/awsum/ec2/region.rb', line 15

def availability_zones
  use do
    @ec2.availability_zones
  end
end

#use(&block) ⇒ Object

Operate all Awsum::Ec2 methods against this Region

Example

ec2.region('eu-west-1').use
ec2.availability_zones #Will give you all the availability zones in the eu-west-1 region

Alternative:
ec2.region('eu-west-1') do |region|
  region.availability_zones
end


32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/awsum/ec2/region.rb', line 32

def use(&block)
  if block_given?
    begin
      old_host = @ec2.host
      @ec2.host = end_point
      block.arity < 1 ? instance_eval(&block) : block[self]
    ensure
      @ec2.host = old_host
    end
  else
    @ec2.host = end_point
    self
  end
end