Class: Transcriber::Resource
- Inherits:
-
Object
- Object
- Transcriber::Resource
show all
- Extended by:
- Builder, Parser
- Includes:
- InputParser, Response, Serialization
- Defined in:
- lib/transcriber/resource.rb,
lib/transcriber/resource/key.rb,
lib/transcriber/resource/parser.rb,
lib/transcriber/resource/builder.rb,
lib/transcriber/resource/key/href.rb,
lib/transcriber/resource/response.rb,
lib/transcriber/resource/input_path.rb,
lib/transcriber/resource/input_parser.rb,
lib/transcriber/resource/key/property.rb,
lib/transcriber/resource/key/relation.rb,
lib/transcriber/resource/key/embeddable.rb,
lib/transcriber/resource/key/association.rb,
lib/transcriber/resource/key/href/response.rb,
lib/transcriber/resource/serialization/date.rb,
lib/transcriber/resource/key/property/parser.rb,
lib/transcriber/resource/serialization/float.rb,
lib/transcriber/resource/key/property/builder.rb,
lib/transcriber/resource/key/relation/builder.rb,
lib/transcriber/resource/serialization/string.rb,
lib/transcriber/resource/key/embeddable/parser.rb,
lib/transcriber/resource/key/property/response.rb,
lib/transcriber/resource/key/relation/response.rb,
lib/transcriber/resource/serialization/boolean.rb,
lib/transcriber/resource/serialization/integer.rb,
lib/transcriber/resource/key/embeddable/builder.rb,
lib/transcriber/resource/key/embeddable/response.rb,
lib/transcriber/resource/serialization/enumerable.rb
Defined Under Namespace
Modules: Builder, InputParser, InputPath, Parser, Response, Serialization
Classes: Association, Embeddable, Href, Key, Property, Relation
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Builder
key, summarizes
#id, #properties, #property
#embeds, #embeds_many, #embeds_one
#belongs_to, #has_many, #has_one, #relation
Methods included from Parser
parse, parse!
Methods included from Response
#link, #resource, #resource_keys, #summarize?
#to_input, #to_input!
Constructor Details
#initialize(attrs = {}) ⇒ Resource
Returns a new instance of Resource.
12
13
14
15
16
17
18
19
20
|
# File 'lib/transcriber/resource.rb', line 12
def initialize(attrs = {})
return if attrs.nil? or attrs.empty?
attrs = attrs.with_indifferent_access
self.class.keys.each do |key|
__send__("#{key.name}=", key.from_hash(attrs[key.name])) if key.present?(self)
end
end
|
Class Method Details
54
55
56
57
|
# File 'lib/transcriber/resource.rb', line 54
def self.convert_input_keys(converter = nil)
@convert_input_keys = converter if converter
@convert_input_keys
end
|
.keys ⇒ Object
38
39
40
|
# File 'lib/transcriber/resource.rb', line 38
def self.keys
@keys ||= []
end
|
.method_added(method_name) ⇒ Object
63
64
65
66
|
# File 'lib/transcriber/resource.rb', line 63
def self.method_added(method_name)
return unless not_allowed_names.include?(method_name.to_s)
puts "warning: redefining '#{method_name}' may cause serious problems"
end
|
.not_allowed_names ⇒ Object
68
69
70
|
# File 'lib/transcriber/resource.rb', line 68
def self.not_allowed_names
%w(resource_id resource link)
end
|
.relations ⇒ Object
46
47
48
|
# File 'lib/transcriber/resource.rb', line 46
def self.relations
@keys.find_all {|k| k.kind_of?(Relation)}
end
|
.resource_name(custom_name = nil) ⇒ Object
50
51
52
|
# File 'lib/transcriber/resource.rb', line 50
def self.resource_name(custom_name = nil)
@resource_name ||= custom_name or to_s.demodulize.tableize
end
|
.summarized_keys ⇒ Object
42
43
44
|
# File 'lib/transcriber/resource.rb', line 42
def self.summarized_keys
@summarized_keys ||= []
end
|
Instance Method Details
#resource_id ⇒ Object
59
60
61
|
# File 'lib/transcriber/resource.rb', line 59
def resource_id
__send__(id_key.name)
end
|
#update_attributes(attrs = {}) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/transcriber/resource.rb', line 22
def update_attributes(attrs = {})
return if attrs.nil? or attrs.empty?
attrs = attrs.with_indifferent_access
self.class.keys.each do |key|
value = attrs[key.name]
if value and key.present?(self)
__send__("#{key.name}=", key.from_hash(value, __send__(key.name)))
end
end
self
end
|