Module: XmlResource::Model

Defined in:
lib/xml_resource/model.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

TRUE_VALUES =
[true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON'].to_set

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/xml_resource/model.rb', line 5

def self.included(base)
  base.extend ClassMethods
  base.class_eval do
    class_attribute :attributes, :collections, :objects, :root_path, :remove_namespaces, :inflection
    self.attributes = {}
    self.collections = {}
    self.objects = {}
    self.inflection = :underscore
  end
end

Instance Method Details

#[](attr_name) ⇒ Object



198
199
200
# File 'lib/xml_resource/model.rb', line 198

def [](attr_name)
  attributes[attr_name]
end

#[]=(attr_name, value) ⇒ Object



202
203
204
# File 'lib/xml_resource/model.rb', line 202

def []=(attr_name, value)
  attributes[attr_name] = value
end

#attributesObject



194
195
196
# File 'lib/xml_resource/model.rb', line 194

def attributes
  @attributes ||= {}.with_indifferent_access
end

#attributes=(attrs) ⇒ Object



188
189
190
191
192
# File 'lib/xml_resource/model.rb', line 188

def attributes=(attrs)
  attrs.each do |attr, value|
    self.public_send("#{attr}=", value)
  end
end

#initialize(attrs = {}) ⇒ Object



179
180
181
182
# File 'lib/xml_resource/model.rb', line 179

def initialize(attrs = {})
  self.attributes = attrs if attrs
  super()
end

#valid?Boolean

Returns:

  • (Boolean)


184
185
186
# File 'lib/xml_resource/model.rb', line 184

def valid?
  true
end