Module: Supplejack::Concept
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/supplejack/concept.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/supplejack/concept.rb', line 52
def method_missing(symbol, *args, &block)
unless @attributes.has_key?(symbol)
raise NoMethodError, "undefined method '#{symbol.to_s}' for Supplejack::Concept:Module"
end
@attributes[symbol]
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
14
15
16
|
# File 'lib/supplejack/concept.rb', line 14
def attributes
@attributes
end
|
Instance Method Details
#id ⇒ Object
29
30
31
32
|
# File 'lib/supplejack/concept.rb', line 29
def id
id = @attributes[:id] || @attributes[:concept_id]
id.to_i
end
|
#initialize(attributes = {}) ⇒ Object
22
23
24
25
26
27
|
# File 'lib/supplejack/concept.rb', line 22
def initialize(attributes={})
if attributes.is_a?(String)
attributes = JSON.parse(attributes) rescue {}
end
@attributes = attributes.symbolize_keys rescue {}
end
|
#name ⇒ Object
38
39
40
|
# File 'lib/supplejack/concept.rb', line 38
def name
@attributes[:name].present? ? @attributes[:name] : "Unknown"
end
|
#persisted? ⇒ Boolean
48
49
50
|
# File 'lib/supplejack/concept.rb', line 48
def persisted?
true
end
|
#to_param ⇒ Object
34
35
36
|
# File 'lib/supplejack/concept.rb', line 34
def to_param
self.id
end
|