module Libis::Workflow::Mongoid::Base
Public Class Methods
included(klass)
click to toggle source
# File lib/libis/workflow/mongoid/base.rb, line 15 def self.included(klass) klass.extend(ClassMethods) klass.class_eval do include ::Mongoid::Document include ::Mongoid::Timestamps::Created::Short # include ::Libis::Workflow::Mongoid::Sequence # # field :_id, type: Integer, overwrite: true # sequence :_id index({c_at: 1}, {name: 'by_created'}) end end
Public Instance Methods
to_hash()
click to toggle source
# File lib/libis/workflow/mongoid/base.rb, line 56 def to_hash result = self.attributes.reject { |k, v| v.blank? || volatile_attributes.include?(k) } result = result.to_yaml.gsub(/!ruby\/hash:BSON::Document/, '') # noinspection RubyResolve result = YAML.load(result) result.key_strings_to_symbols!(recursive: true) end
to_s()
click to toggle source
# File lib/libis/workflow/mongoid/base.rb, line 64 def to_s self.name || "#{self.class.name}_#{self.id}" end
Protected Instance Methods
volatile_attributes()
click to toggle source
# File lib/libis/workflow/mongoid/base.rb, line 70 def volatile_attributes %w'_id c_at' end
Private Instance Methods
copy_attributes(other)
click to toggle source
# File lib/libis/workflow/mongoid/base.rb, line 76 def copy_attributes(other) self.set( other.attributes.reject do |k, _| %W(_id c_at).include? k.to_s end.each_with_object({}) do |(k, v), h| h[k] = v.duplicable? ? v.dup : v end ) self end