Module: SimpleSDKBuilder::Resource::ClassMethods

Defined in:
lib/simple_sdk_builder/resource.rb

Instance Method Summary collapse

Instance Method Details

#simple_sdk_attribute(*attrs) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/simple_sdk_builder/resource.rb', line 91

def simple_sdk_attribute(*attrs)
  attrs.each do |attr|
    attr = attr.to_s
    simple_sdk_attributes.push(attr)
    define_method attr do
      @attributes[attr]
    end
    define_method "#{attr}=" do |value|
      write_attribute(attr, value)
    end
  end
end

#simple_sdk_attributesObject



121
122
123
# File 'lib/simple_sdk_builder/resource.rb', line 121

def simple_sdk_attributes
  @simple_sdk_attributes ||= []
end

#simple_sdk_nested_attribute(attr, options = {}) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/simple_sdk_builder/resource.rb', line 104

def simple_sdk_nested_attribute(attr, options = {})
  options = {
    :nested => true
  }.merge(options)
  attr = attr.to_s
  simple_sdk_attributes.push(attr)
  simple_sdk_attributes.push("#{attr}_attributes") # for ActiveRecord nested attributes
  define_method attr do
    @attributes[attr] ||= []
  end
  alias_method :"#{attr}_attributes", :"#{attr}" # for ActiveRecord nested attributes
  define_method "#{attr}=" do |value|
    write_attribute(attr, value, options)
  end
  alias_method :"#{attr}_attributes=", :"#{attr}=" # for ActiveRecord nested attributes
end