Module: JsonResource::Model

Defined in:
lib/json_resource/model.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/json_resource/model.rb', line 8

def self.included(base)
  base.extend ClassMethods
  base.class_attribute :attributes, :collections, :objects, :inflection
  base.attributes = {}
  base.collections = {}
  base.objects = {}
  base.inflection = :lower_camelcase
end

Instance Method Details

#[](attr_name) ⇒ Object



227
228
229
# File 'lib/json_resource/model.rb', line 227

def [](attr_name)
  attributes[attr_name.to_sym]
end

#[]=(attr_name, value) ⇒ Object



231
232
233
# File 'lib/json_resource/model.rb', line 231

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

#attributesObject



223
224
225
# File 'lib/json_resource/model.rb', line 223

def attributes
  @attributes ||= {}
end

#attributes=(attrs) ⇒ Object



217
218
219
220
221
# File 'lib/json_resource/model.rb', line 217

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

#initialize(attrs = {}) ⇒ Object



208
209
210
211
# File 'lib/json_resource/model.rb', line 208

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

#valid?Boolean

Returns:

  • (Boolean)


213
214
215
# File 'lib/json_resource/model.rb', line 213

def valid?
  true
end