Module: Curator::Model

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::Conversion
Defined in:
lib/curator/model.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



36
37
38
# File 'lib/curator/model.rb', line 36

def ==(other)
  self.id == other.id
end

#initialize(args = {}) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/curator/model.rb', line 14

def initialize(args = {})
  method_strings = methods.map(&:to_s)
  args.each do |attribute, value|
    send("#{attribute}=", value) if method_strings.include?("#{attribute}=")
    instance_variable_set("@#{attribute}", value) if method_strings.include?(attribute.to_s)
  end
end

#persisted?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/curator/model.rb', line 22

def persisted?
  id.present?
end

#touchObject



26
27
28
29
30
# File 'lib/curator/model.rb', line 26

def touch
  now = Time.now.utc
  @created_at = now if @created_at.nil?
  @updated_at = now
end

#versionObject



32
33
34
# File 'lib/curator/model.rb', line 32

def version
  @version || self.class.version
end