Class: AWS::Core::Resource::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/core/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Attribute

Returns a new instance of Attribute.



282
283
284
285
286
# File 'lib/aws/core/resource.rb', line 282

def initialize name, options = {}
  @name = name
  @options = options
  @request_types = []
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



288
289
290
# File 'lib/aws/core/resource.rb', line 288

def name
  @name
end

#request_typesObject (readonly)

Returns the value of attribute request_types.



290
291
292
# File 'lib/aws/core/resource.rb', line 290

def request_types
  @request_types
end

Instance Method Details

#get_asObject



292
293
294
# File 'lib/aws/core/resource.rb', line 292

def get_as
  @get_as ||= (@options[:get_as] || @options[:as] || name)
end

#mutable?Boolean

Returns:

  • (Boolean)


300
301
302
# File 'lib/aws/core/resource.rb', line 300

def mutable?
  @options[:mutable] == true
end

#set_asObject



296
297
298
# File 'lib/aws/core/resource.rb', line 296

def set_as
  @set_as ||= (@options[:set_as] || @options[:as] || name)
end

#static?Boolean

Returns:

  • (Boolean)


304
305
306
# File 'lib/aws/core/resource.rb', line 304

def static?
  @options[:static] == true
end

#translate_input_value(value) ⇒ Object



317
318
319
# File 'lib/aws/core/resource.rb', line 317

def translate_input_value value
  @input_translator ? @input_translator.call(value) : value
end

#translate_output_value(value) ⇒ Object



321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/aws/core/resource.rb', line 321

def translate_output_value value
  
  # by default nil values are not translated
  return nil if value.nil? and @translates_nil != true
  
  case
  when @options[:to_sym]    then value.tr('-','_').downcase.to_sym
  when @options[:timestamp] then Time.at(value.to_i)
  when @output_translator   then @output_translator.call(value)
  else value
  end
  
end

#translates_input(&block) ⇒ Object



308
309
310
# File 'lib/aws/core/resource.rb', line 308

def translates_input &block
  @input_translator = block
end

#translates_output(options = {}, &block) ⇒ Object



312
313
314
315
# File 'lib/aws/core/resource.rb', line 312

def translates_output options = {}, &block
  @translates_nil = options[:nil]
  @output_translator = block
end