Class: Awsm::Spinulator

Inherits:
Object
  • Object
show all
Defined in:
lib/awsm/configure.rb

Instance Method Summary collapse

Constructor Details

#initialize(default = nil) ⇒ Spinulator

Returns a new instance of Spinulator.



122
123
124
125
126
127
128
129
130
131
# File 'lib/awsm/configure.rb', line 122

def initialize( default=nil )
  @config = { tags: {} }
  if default
    @config[:instance_type] = default.instance_type
    @config[:key_name] = default.key_name
    @config[:subnet] = default.subnet
    @config[:security_groups] = default.security_groups
    @config[:tags] = default.tags || {}
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/awsm/configure.rb', line 133

def method_missing( name, *args )
  n_args = args.length

  write = ( n_args > 0 || block_given? )

  if write
    if block_given?
      args << yield
    end

    @config[ name ] = args.first
  else
    return @config[ name ]
  end
end

Instance Method Details

#security_group(security_group) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/awsm/configure.rb', line 161

def security_group( security_group )
  if @config[:security_groups].nil?
    @config[:security_groups] = []
  end

  if security_group.nil? && block_given?
    @config[:security_groups] << yield
  elsif security_group && !block_given?
    @config[:security_groups] << security_group
  elsif security_group.nil? && !block_given?
    raise StandardError, "You need to specify something."
  elsif !security_group.nil? && block_given?
    raise StandardError, "You can't specify both a value and a block. Choose."
  end
end

#tag(name, value = nil) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
# File 'lib/awsm/configure.rb', line 149

def tag( name, value=nil )
  if value.nil? && block_given?
    @config[:tags][ name ] = yield
  elsif value && !block_given?
    @config[:tags][ name ] = value
  elsif value.nil? && !block_given?
    raise StandardError, "You need to specify something."
  elsif !value.nil? && block_given?
    raise StandardError, "You can't specify both a value and a block. Choose."
  end
end