Class: Dynamoid::Fields::Declare

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamoid/fields/declare.rb

Instance Method Summary collapse

Constructor Details

#initialize(source, name, type, options) ⇒ Declare

Returns a new instance of Declare.


7
8
9
10
11
12
# File 'lib/dynamoid/fields/declare.rb', line 7

def initialize(source, name, type, options)
  @source = source
  @name = name.to_sym
  @type = type
  @options = options
end

Instance Method Details

#callObject


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dynamoid/fields/declare.rb', line 14

def call
  # Register new field metadata
  @source.attributes = @source.attributes.merge(
    @name => { type: @type }.merge(@options)
  )

  # Should be called before `define_attribute_methods` method because it
  # defines an attribute getter itself
  warn_about_method_overriding

  # Dirty API
  @source.define_attribute_method(@name)

  # Generate getters and setters as well as other helper methods
  generate_instance_methods

  # If alias name specified - generate the same instance methods
  if @options[:alias]
    generate_instance_methods_for_alias
  end
end