Class: Atlas::Resource
Constant Summary
collapse
- INTERNAL_ATTRIBUTE_KEYS =
%w(@tag @url_builder).freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
included
Constructor Details
#initialize(tag, hash = {}) ⇒ Resource
Returns a new instance of Resource.
11
12
13
14
15
16
|
# File 'lib/atlas/resource.rb', line 11
def initialize(tag, hash = {})
@tag = tag
@url_builder = UrlBuilder.new tag
hash.each { |k, v| send("#{k}=", v) if respond_to?("#{k}=") }
end
|
Instance Attribute Details
#tag ⇒ Object
Returns the value of attribute tag.
9
10
11
|
# File 'lib/atlas/resource.rb', line 9
def tag
@tag
end
|
#url_builder ⇒ Object
Returns the value of attribute url_builder.
9
10
11
|
# File 'lib/atlas/resource.rb', line 9
def url_builder
@url_builder
end
|
Class Method Details
.date_accessor(*args) ⇒ Object
50
51
52
53
|
# File 'lib/atlas/resource.rb', line 50
def date_accessor(*args)
attr_reader(*args)
date_writer(*args)
end
|
.date_writer(*args) ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/atlas/resource.rb', line 41
def date_writer(*args)
args.each do |attr|
define_method("#{attr}=".to_sym) do |date|
date = date.is_a?(String) ? Time.parse(date) : date
instance_variable_set("@#{attr}", date)
end
end
end
|
Instance Method Details
#attributes ⇒ Object
25
26
27
28
29
|
# File 'lib/atlas/resource.rb', line 25
def attributes
instance_variables.map do |v|
INTERNAL_ATTRIBUTE_KEYS.include?(v.to_s) ? next : v.to_s.sub(/^@/, "")
end.compact!
end
|
#inspect ⇒ Object
35
36
37
38
|
# File 'lib/atlas/resource.rb', line 35
def inspect
objects = to_hash.map { |k, v| "#{k}=#{v.inspect}" }.join(' ')
"#<#{self.class.name}:#{object_id} #{objects}>"
end
|
#to_hash ⇒ Object
31
32
33
|
# File 'lib/atlas/resource.rb', line 31
def to_hash
Hash[attributes.map { |v| [v.to_sym, send(v)] }]
end
|
#update_with_response(response, except_keys = []) ⇒ Object
18
19
20
21
22
23
|
# File 'lib/atlas/resource.rb', line 18
def update_with_response(response, except_keys = [])
except_keys.each { |k| response.delete(k) }
response.each { |k, v| send("#{k}=", v) if respond_to?("#{k}=") }
end
|