Module: Supplejack::Record
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/supplejack/record.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
95
96
97
98
|
# File 'lib/supplejack/record.rb', line 95
def method_missing(symbol, *args, &block)
raise NoMethodError, "undefined method '#{symbol.to_s}' for Supplejack::Record:Module" unless @attributes.has_key?(symbol)
@attributes[symbol]
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
14
15
16
|
# File 'lib/supplejack/record.rb', line 14
def attributes
@attributes
end
|
Instance Method Details
70
71
72
73
|
# File 'lib/supplejack/record.rb', line 70
def format
raise NoMethodError, "undefined method 'format' for Supplejack::Record:Module" unless @attributes.has_key?(:format)
@attributes[:format]
end
|
#id ⇒ Object
29
30
31
32
|
# File 'lib/supplejack/record.rb', line 29
def id
id = @attributes[:id] || @attributes[:record_id]
id.to_i
end
|
#initialize(attributes = {}) ⇒ Object
22
23
24
25
26
27
|
# File 'lib/supplejack/record.rb', line 22
def initialize(attributes={})
if attributes.is_a?(String)
attributes = JSON.parse(attributes) rescue {}
end
@attributes = attributes.symbolize_keys rescue {}
end
|
Returns a array of hashes containing all the record attributes and the schema each attribute belongs to. To set what fields belong to each schema there is a config option to set supplejack_fields and admin_fields
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/supplejack/record.rb', line 49
def metadata
metadata = []
['supplejack', 'admin'].each do |schema|
Supplejack.send("#{schema}_fields").each do |field|
if @attributes.has_key?(field)
values = @attributes[field]
values ||= [] unless !!values == values
values = [values] unless values.is_a?(Array)
field = field.to_s.camelcase(:lower) if schema == "dcterms"
field = field.to_s.sub(/#{schema}_/, '')
values.each do |value|
metadata << {:name => field, :schema => schema, :value => value }
end
end
end
end
metadata
end
|
#persisted? ⇒ Boolean
91
92
93
|
# File 'lib/supplejack/record.rb', line 91
def persisted?
true
end
|
#title ⇒ Object
38
39
40
|
# File 'lib/supplejack/record.rb', line 38
def title
@attributes[:title].present? ? @attributes[:title] : "Untitled"
end
|
#to_param ⇒ Object
34
35
36
|
# File 'lib/supplejack/record.rb', line 34
def to_param
self.id
end
|