Class: Glossarist::Model
- Inherits:
-
Object
show all
- Defined in:
- lib/glossarist/model.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attributes = {}) ⇒ Model
Returns a new instance of Model.
14
15
16
|
# File 'lib/glossarist/model.rb', line 14
def initialize(attributes = {})
attributes.each_pair { |k, v| set_attribute(k, v) }
end
|
Class Method Details
.from_h(hash) ⇒ Object
29
30
31
|
# File 'lib/glossarist/model.rb', line 29
def self.from_h(hash)
new(hash)
end
|
.new(params = {}) ⇒ Object
8
9
10
11
12
|
# File 'lib/glossarist/model.rb', line 8
def self.new(params = {})
return params if params.is_a?(self)
super
end
|
Instance Method Details
#set_attribute(name, value) ⇒ Object
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/glossarist/model.rb', line 18
def set_attribute(name, value)
public_send("#{name}=", value)
rescue NoMethodError
if Config.extension_attributes.include?(name)
extension_attributes[name] = value
else
raise ArgumentError, "#{self.class.name} does not have " +
"attribute #{name} defined or the attribute is read only."
end
end
|