Module: Todoist::Resource
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#temp_id ⇒ Object
Returns the value of attribute temp_id.
Instance Method Summary collapse
- #attributes ⇒ Object
- #attributes=(attributes) ⇒ Object
- #command_class ⇒ Object
- #create_command(name, arguments, tmp_id = nil) ⇒ Object
- #initialize(attributes = {}) ⇒ Object
- #logger ⇒ Object
- #persisted? ⇒ Boolean
- #resource_type ⇒ Object
- #to_hash ⇒ Object
- #to_submittable_hash ⇒ Object
Instance Attribute Details
#temp_id ⇒ Object
Returns the value of attribute temp_id.
16 17 18 |
# File 'lib/todoist/resource.rb', line 16 def temp_id @temp_id end |
Instance Method Details
#attributes ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/todoist/resource.rb', line 22 def attributes self.class.attributes.inject({}) do |attributes, attribute| value = send(attribute) if !value.nil? attributes[attribute] = value end; attributes end end |
#attributes=(attributes) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/todoist/resource.rb', line 31 def attributes=(attributes) attributes.each do |attribute, value| if respond_to?(writer = attribute.to_s + '=') send(writer, value) else logger.warn "#{self.class} does not have an `#{attribute}' attribute" end end end |
#command_class ⇒ Object
53 54 55 |
# File 'lib/todoist/resource.rb', line 53 def command_class @command_class ||= Command end |
#create_command(name, arguments, tmp_id = nil) ⇒ Object
49 50 51 |
# File 'lib/todoist/resource.rb', line 49 def create_command(name, arguments, tmp_id = nil) command_class.new(name, arguments, tmp_id) end |
#initialize(attributes = {}) ⇒ Object
18 19 20 |
# File 'lib/todoist/resource.rb', line 18 def initialize(attributes={}) self.attributes = attributes || {} end |
#logger ⇒ Object
45 46 47 |
# File 'lib/todoist/resource.rb', line 45 def logger @logger ||= Logger.new end |
#persisted? ⇒ Boolean
69 70 71 |
# File 'lib/todoist/resource.rb', line 69 def persisted? !id.nil? end |
#resource_type ⇒ Object
65 66 67 |
# File 'lib/todoist/resource.rb', line 65 def resource_type self.class.name.split('::').last.downcase end |
#to_hash ⇒ Object
41 42 43 |
# File 'lib/todoist/resource.rb', line 41 def to_hash attributes end |
#to_submittable_hash ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/todoist/resource.rb', line 57 def to_submittable_hash if self.class.read_only_attributes attributes.delete_if { |key, value| self.class.read_only_attributes.include?(key)} else attributes end end |