Class: Count
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Count
- Defined in:
- lib/count.rb
Class Method Summary collapse
- .create(card) ⇒ Object
- .fetch(card) ⇒ Object
- .fetch_value(card) ⇒ Object
- .find_by_card(card) ⇒ Object
- .find_value_by_card(card) ⇒ Object
- .refresh(card) ⇒ Object
- .step(card) ⇒ Object
Instance Method Summary collapse
Class Method Details
.create(card) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/count.rb', line 12 def create card validate_count_card card count = Count.new left_id: left_id(card), right_id: right_id(card), value: card.recount count.save! count end |
.fetch(card) ⇒ Object
25 26 27 |
# File 'lib/count.rb', line 25 def fetch card find_by_card(card) || create(card) end |
.fetch_value(card) ⇒ Object
21 22 23 |
# File 'lib/count.rb', line 21 def fetch_value card find_value_by_card(card) || create(card).value end |
.find_by_card(card) ⇒ Object
45 46 47 |
# File 'lib/count.rb', line 45 def find_by_card card where_card(card).take end |
.find_value_by_card(card) ⇒ Object
41 42 43 |
# File 'lib/count.rb', line 41 def find_value_by_card card where_card(card).pluck(:value).first end |
.refresh(card) ⇒ Object
35 36 37 38 39 |
# File 'lib/count.rb', line 35 def refresh card count = find_by_card(card) return create(card).value unless count count.update card.recount end |
.step(card) ⇒ Object
29 30 31 32 33 |
# File 'lib/count.rb', line 29 def step card count = find_by_card(card) return create(card).value unless count count.step end |
Instance Method Details
#step ⇒ Object
2 3 4 |
# File 'lib/count.rb', line 2 def step update value + 1 end |
#update(new_value) ⇒ Object
6 7 8 9 |
# File 'lib/count.rb', line 6 def update new_value update! value: new_value new_value end |