class MoneyTracking::Domain::Expense
Constants
- SIMPLE_FIELDS
Attributes
fields[R]
id[R]
store[R]
Public Class Methods
new(store, fields)
click to toggle source
# File lib/money_tracking/domain/expense.rb, line 6 def initialize(store, fields) @store = store @fields = fields @id = fields[:id] end
Public Instance Methods
build_view(view_factory)
click to toggle source
# File lib/money_tracking/domain/expense.rb, line 30 def build_view(view_factory) view_factory.new(raw) end
create()
click to toggle source
# File lib/money_tracking/domain/expense.rb, line 12 def create set_created_at @id = store.create(raw) self end
delete()
click to toggle source
# File lib/money_tracking/domain/expense.rb, line 25 def delete store.delete(id) self end
update(updated_fields)
click to toggle source
# File lib/money_tracking/domain/expense.rb, line 18 def update(updated_fields) simple_update(updated_fields) update_tags(updated_fields) store.update(id, raw) self end
Private Instance Methods
raw()
click to toggle source
# File lib/money_tracking/domain/expense.rb, line 38 def raw return fields unless id fields.merge(id: id) end
set_created_at()
click to toggle source
# File lib/money_tracking/domain/expense.rb, line 43 def set_created_at fields[:created_at] ||= Time.now end
simple_update(updated_fields)
click to toggle source
# File lib/money_tracking/domain/expense.rb, line 47 def simple_update(updated_fields) SIMPLE_FIELDS.each do |name| fields[name] = updated_fields[name] if updated_fields[name] end end