lib/seam/effort.rb in seam-0.0.8 vs lib/seam/effort.rb in seam-0.0.9

- old
+ new

@@ -20,29 +20,36 @@ def find_all_by_step step Seam::Persistence.find_all_pending_executions_by_step step end def parse document - effort = Effort.new - effort.id = document['id'] - effort.created_at = Time.parse(document['created_at'].to_s) - effort.next_execute_at = document['next_execute_at'] - effort.next_step = document['next_step'] - effort.flow = HashWithIndifferentAccess.new document['flow'] - effort.data = HashWithIndifferentAccess.new document['data'] - effort.history = document['history'].map { |x| HashWithIndifferentAccess.new x } - effort.completed_steps = document['completed_steps'] - effort.complete = document['complete'] - effort.completed_at = document['completed_at'] - effort + Effort.new( { + id: document['id'], + created_at: Time.parse(document['created_at'].to_s), + next_execute_at: document['next_execute_at'], + next_step: document['next_step'], + flow: HashWithIndifferentAccess.new(document['flow']), + data: HashWithIndifferentAccess.new(document['data']), + history: document['history'].map { |x| HashWithIndifferentAccess.new x }, + completed_steps: document['completed_steps'], + complete: document['complete'], + completed_at: document['completed_at'] + } ) end end - def initialize + def initialize(args = {}) @completed_steps = [] @history = [] @complete = false + args.each { |k, v| self.send "#{k}=".to_sym, v } + end + + def self.create args + effort = Seam::Effort.new args + effort.save + effort end def save existing_record = Seam::Effort.find self.id if existing_record