module Libis::Workflow::ActiveRecord::Base

Public Class Methods

included(klass) click to toggle source
# File lib/libis/workflow/activerecord/base.rb, line 10
def self.included(klass)
  klass.extend(ClassMethods)

  # def [](key)
  #   self.send(key.to_sym)
  # end
  #
  # def []=(key,value)
  #   self.send(key.to_s + '=', value)
  # end
end

Public Instance Methods

to_hash() click to toggle source
# File lib/libis/workflow/activerecord/base.rb, line 45
def to_hash
  result = self.attributes.reject { |k, v| v.blank? || volatile_attributes.include?(k) }
  result = result.to_yaml
  # noinspection RubyResolve
  YAML.load(result)
end
to_s() click to toggle source
# File lib/libis/workflow/activerecord/base.rb, line 52
def to_s
  self.name || "#{self.class.name}_#{self.id}"
end

Protected Instance Methods

volatile_attributes() click to toggle source
# File lib/libis/workflow/activerecord/base.rb, line 58
def volatile_attributes
  %w'id created_at updated_at'
end

Private Instance Methods

copy_attributes(other) click to toggle source
# File lib/libis/workflow/activerecord/base.rb, line 64
def copy_attributes(other)
  self.set(
      other.attributes.reject do |k, _|
        volatile_attributes.include? k.to_s
      end.each_with_object({}) do |(k, v), h|
        h[k] = v.duplicable? ? v.dup : v
      end
  )
  self
end