Class: Kithe::TimingPromotionDirective
- Inherits:
-
Object
- Object
- Kithe::TimingPromotionDirective
- Defined in:
- app/models/kithe/timing_promotion_directive.rb
Overview
Just a handy class for handling logic with our promotion directives for “timing” promotion directives whose values are “false”, “background”, or “inline”, where the default is “background”
These directives are :promote, :create_derivatives, and :delete
You might use like:
Kithe::LifecyclePromotionDirective.new(key: :promotion, directives: asset.file_attacher.promotion_directives) do |directive|
if directive.inline?
run_something
elsif directive.background?
SomeJob.perform_later
end
end
Constant Summary collapse
- DEFAULT_VALUE =
"background"
- ALLOWED_VALUES =
["background", "inline", "false"]
Instance Attribute Summary collapse
-
#directive_key ⇒ Object
readonly
Returns the value of attribute directive_key.
-
#directives ⇒ Object
readonly
Returns the value of attribute directives.
Instance Method Summary collapse
- #background? ⇒ Boolean
- #directive_value ⇒ Object
- #disabled? ⇒ Boolean
-
#initialize(key:, directives:) {|_self| ... } ⇒ TimingPromotionDirective
constructor
A new instance of TimingPromotionDirective.
- #inline? ⇒ Boolean
Constructor Details
#initialize(key:, directives:) {|_self| ... } ⇒ TimingPromotionDirective
Returns a new instance of TimingPromotionDirective.
23 24 25 26 27 28 29 30 31 32 |
# File 'app/models/kithe/timing_promotion_directive.rb', line 23 def initialize(key:, directives: ) @directive_key = key.to_s @directives = directives unless ALLOWED_VALUES.include?(directive_value) raise ArgumentError.new("Unrecognized value `#{directive_value}` for `#{key}`; must be #{ALLOWED_VALUES}") end yield self end |
Instance Attribute Details
#directive_key ⇒ Object (readonly)
Returns the value of attribute directive_key.
21 22 23 |
# File 'app/models/kithe/timing_promotion_directive.rb', line 21 def directive_key @directive_key end |
#directives ⇒ Object (readonly)
Returns the value of attribute directives.
21 22 23 |
# File 'app/models/kithe/timing_promotion_directive.rb', line 21 def directives @directives end |
Instance Method Details
#background? ⇒ Boolean
46 47 48 |
# File 'app/models/kithe/timing_promotion_directive.rb', line 46 def background? directive_value == "background" end |
#directive_value ⇒ Object
34 35 36 37 38 39 40 |
# File 'app/models/kithe/timing_promotion_directive.rb', line 34 def directive_value @directive_value ||= begin value = (directives || {})[directive_key] # not blank?, cause false we want to recognize. (value.nil? || value == "") ? DEFAULT_VALUE : value.to_s end end |
#disabled? ⇒ Boolean
50 51 52 |
# File 'app/models/kithe/timing_promotion_directive.rb', line 50 def disabled? directive_value == "false" end |
#inline? ⇒ Boolean
42 43 44 |
# File 'app/models/kithe/timing_promotion_directive.rb', line 42 def inline? directive_value == "inline" end |