-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add field 'single' and processor 'counter'
pc4-15459
- Loading branch information
1 parent
2957b41
commit bb6ce63
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |