class Atlas::Resource
Constants
- INTERNAL_ATTRIBUTE_KEYS
Attributes
tag[RW]
url_builder[RW]
Public Class Methods
date_accessor(*args)
click to toggle source
# File lib/atlas/resource.rb, line 50 def date_accessor(*args) attr_reader(*args) date_writer(*args) end
date_writer(*args)
click to toggle source
# 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
new(tag, hash = {})
click to toggle source
# 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
Public Instance Methods
attributes()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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 = [])
click to toggle source
# File lib/atlas/resource.rb, line 18 def update_with_response(response, except_keys = []) # remove keys that shouldn't be included except_keys.each { |k| response.delete(k) } response.each { |k, v| send("#{k}=", v) if respond_to?("#{k}=") } end