Class: Patterns::Calculation
- Inherits:
-
Object
- Object
- Patterns::Calculation
- Defined in:
- lib/patterns/calculation.rb
Class Method Summary collapse
- .calculate ⇒ Object
- .result(*args) ⇒ Object
- .result_for ⇒ Object
- .set_cache_expiry_every(period) ⇒ Object
Instance Method Summary collapse
- #cached_result ⇒ 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) = args. @subject = args.first end |
Class Method Details
.calculate ⇒ Object
18 19 20 |
# File 'lib/patterns/calculation.rb', line 18 def self.result(*args) new(*args).cached_result end |
.result(*args) ⇒ Object
12 13 14 |
# File 'lib/patterns/calculation.rb', line 12 def self.result(*args) new(*args).cached_result end |
.result_for ⇒ Object
17 18 19 |
# File 'lib/patterns/calculation.rb', line 17 def self.result(*args) new(*args).cached_result 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 ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/patterns/calculation.rb', line 25 def cached_result if cache_expiry_period.blank? result else Rails.cache.fetch(cache_key, expires_in: cache_expiry_period) do result end end end |