Skip to content

Commit

Permalink
add field 'single' and processor 'counter'
Browse files Browse the repository at this point in the history
pc4-15459
  • Loading branch information
sergei-kucher committed Oct 22, 2015
1 parent 2957b41 commit bb6ce63
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/treasury/fields/single.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Treasury
module Fields
module Single
extend ActiveSupport::Concern

module ClassMethods
protected

def init_accessor(params)
@accessing_object = extract_object(params)
@accessing_field = nil
end
end
end
end
end
37 changes: 37 additions & 0 deletions lib/treasury/processors/counter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Treasury
module Processors
module Counter
include Single

protected

def process_insert
increment_current_value if satisfied?
end

def process_update
if satisfied?
increment_current_value unless was_counted?
else
decrement_current_value if was_counted?
end
end

def process_delete
decrement_current_value if was_counted?
end

def satisfied?
condition? @event.raw_data
end

def was_counted?
condition? @event.raw_prev_data
end

def condition?(data)
raise NotImplemenedError
end
end
end
end

0 comments on commit bb6ce63

Please sign in to comment.