Class: Patterns::Calculation
- Inherits:
-
Object
- Object
- Patterns::Calculation
- Defined in:
- lib/patterns/calculation.rb
Class Method Summary collapse
- .calculate ⇒ Object
- .result(*args, &block) ⇒ Object
- .result_for ⇒ Object
- .set_cache_expiry_every(period) ⇒ Object
Instance Method Summary collapse
- #cached_result(&block) ⇒ Object
-
#initialize(*args) ⇒ Calculation
constructor
A new instance of Calculation.
Constructor Details
#initialize(*args) ⇒ Calculation
Returns a new instance of Calculation.
7 8 9 10 |
# File 'lib/patterns/calculation.rb', line 7 def initialize(*args) @options = args. @subject = args.first end |
Class Method Details
.calculate ⇒ Object
18 19 20 |
# File 'lib/patterns/calculation.rb', line 18 def self.result(*args, &block) new(*args).cached_result(&block) end |
.result(*args, &block) ⇒ Object
12 13 14 |
# File 'lib/patterns/calculation.rb', line 12 def self.result(*args, &block) new(*args).cached_result(&block) end |
.result_for ⇒ Object
17 18 19 |
# File 'lib/patterns/calculation.rb', line 17 def self.result(*args, &block) new(*args).cached_result(&block) end |
.set_cache_expiry_every(period) ⇒ Object
21 22 23 |
# File 'lib/patterns/calculation.rb', line 21 def self.set_cache_expiry_every(period) self.cache_expiry_every = period end |
Instance Method Details
#cached_result(&block) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/patterns/calculation.rb', line 25 def cached_result(&block) if cache_expiry_period.blank? result(&block) else Rails.cache.fetch(cache_key, expires_in: cache_expiry_period) do result(&block) end end end |