Module: Collector::Model
- Defined in:
- lib/collector/model.rb
Class Method Summary collapse
Instance Method Summary collapse
- #==(other_model) ⇒ Object
- #attributes ⇒ Object
- #initialize(attributes = {}) ⇒ Object
- #touch ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 7 |
# File 'lib/collector/model.rb', line 4 def self.included(base) attr_accessor :id attr_reader :created_at, :updated_at end |
Instance Method Details
#==(other_model) ⇒ Object
27 28 29 30 |
# File 'lib/collector/model.rb', line 27 def ==(other_model) return nil if self.id.nil? || other_model.id.nil? self.id == other_model.id end |
#attributes ⇒ Object
21 22 23 24 25 |
# File 'lib/collector/model.rb', line 21 def attributes instance_variables.each_with_object({}) do |instance_variable, hash| hash[instance_variable.to_s[1..-1]] = instance_variable_get(instance_variable) end end |
#initialize(attributes = {}) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/collector/model.rb', line 9 def initialize(attributes = {}) attributes.each do |key, value| instance_variable_set("@#{key}", value) if methods.include? "#{key}".to_sym send("#{key}=", value) if methods.include? "#{key}=".to_sym end end |
#touch ⇒ Object
16 17 18 19 |
# File 'lib/collector/model.rb', line 16 def touch @created_at ||= Time.now.utc @updated_at = Time.now.utc end |