Class: Dynectastic::RecordFactory
- Inherits:
-
Resource
- Object
- Resource
- Dynectastic::RecordFactory
show all
- Defined in:
- lib/dynectastic/factories/record_factory.rb
Instance Attribute Summary
Attributes inherited from Resource
#factory, #last_request, #session
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Resource
#attributes=, #delete, #get, #initialize, #post, #put
Class Method Details
.record_types(*attrs) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/dynectastic/factories/record_factory.rb', line 5
def self.record_types(*attrs)
attrs.each do |attr_name|
class_eval do
attr_reader :record_type
end
eval %Q[
def #{ attr_name }
@record_type = "#{ attr_name }".upcase
self
end
]
end
end
|
Instance Method Details
#build(attributes) ⇒ Object
21
22
23
24
25
26
|
# File 'lib/dynectastic/factories/record_factory.rb', line 21
def build(attributes)
record = Dynectastic::Record.new(session, self)
record.type = record_type
record.attributes = attributes
record
end
|
#entity_base ⇒ Object
41
42
43
|
# File 'lib/dynectastic/factories/record_factory.rb', line 41
def entity_base
"/REST/#{ entity_name }"
end
|
#entity_name ⇒ Object
45
46
47
|
# File 'lib/dynectastic/factories/record_factory.rb', line 45
def entity_name
"#{ record_type }Record"
end
|
#find_all(options = {}) ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/dynectastic/factories/record_factory.rb', line 32
def find_all(options={})
records = []
get("#{ entity_base }/#{ options[:zone] }/#{ options[:node] }/").each do |record_url|
record_id = record_url.split("/").last
records << find_by_id(record_id, options)
end
records
end
|
#find_by_id(id, options = {}) ⇒ Object
28
29
30
|
# File 'lib/dynectastic/factories/record_factory.rb', line 28
def find_by_id(id, options={})
build get("#{ entity_base }/#{ options[:zone] }/#{ options[:node] }/#{ id }")
end
|