Module: Libis::Workflow::Mongoid::WorkItemBase
Class Method Summary collapse
Instance Method Summary collapse
- #add_item(item) ⇒ Object
- #get_items ⇒ Object
- #log_history ⇒ Object
- #status_log ⇒ Object
- #to_hash ⇒ Object
Class Method Details
.included(klass) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/libis/workflow/mongoid/work_item_base.rb', line 10 def self.included(klass) klass.class_eval do include Libis::Workflow::Base::WorkItem include Libis::Workflow::Mongoid::Base store_in collection: 'workflow_items' field :_options, type: Hash, default: -> { Hash.new } field :_properties, type: Hash, default: -> { Hash.new } field :_summary, type: Hash, default: -> { Hash.new } has_many :logs, as: :logger, class_name: Libis::Workflow::Mongoid::LogEntry.to_s, dependent: :destroy, autosave: true, order: :_id.asc do def log_history where(:status.exists => false) end def status_log where(:status.exists => true) end end has_many :items, as: :parent, class_name: Libis::Workflow::Mongoid::WorkItem.to_s, dependent: :destroy, autosave: true, order: :c_at.asc belongs_to :parent, polymorphic: true set_callback(:destroy, :before) do |document| # noinspection RubyResolve document.logs.each { |log| log.destroy! } end indifferent_hash :_options, :options indifferent_hash :_properties, :properties indifferent_hash :_summary, :summary end end |
Instance Method Details
#add_item(item) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/libis/workflow/mongoid/work_item_base.rb', line 67 def add_item(item) if item.parent item.parent = nil end super end |
#get_items ⇒ Object
74 75 76 |
# File 'lib/libis/workflow/mongoid/work_item_base.rb', line 74 def get_items self.items.to_a end |
#log_history ⇒ Object
57 58 59 60 |
# File 'lib/libis/workflow/mongoid/work_item_base.rb', line 57 def log_history # noinspection RubyResolve self.logs.log_history.all || [] end |
#status_log ⇒ Object
62 63 64 65 |
# File 'lib/libis/workflow/mongoid/work_item_base.rb', line 62 def status_log # noinspection RubyResolve self.logs.status_log.all || [] end |
#to_hash ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/libis/workflow/mongoid/work_item_base.rb', line 49 def to_hash result = super result[:options] = result.delete(:_options) result[:properties] = result.delete(:_properties) result[:summary] = result.delete(:_summary) result end |