Module: Shrine::Plugins::KithePromotionDirectives::AttacherMethods
- Defined in:
- lib/shrine/plugins/kithe_promotion_directives.rb
Instance Method Summary collapse
-
#promotion_directives ⇒ Object
context, lazily initializing to hash for convenience.
-
#set_promotion_directives(hash) ⇒ Object
Set one or more promotion directives, stored context, that will be serialized and restored to context for bg promotion.
Instance Method Details
#promotion_directives ⇒ Object
context, lazily initializing to hash for convenience.
104 105 106 |
# File 'lib/shrine/plugins/kithe_promotion_directives.rb', line 104 def promotion_directives context[:promotion_directives] ||= {} end |
#set_promotion_directives(hash) ⇒ Object
Set one or more promotion directives, stored context, that will be serialized and restored to context for bg promotion. The values are intended to be simple strings or other json-serializable primitives.
set_promotion_directives will merge it’s results into existing promotion directives, existing keys will remain. So you can set multiple directives with multiple calls to set_promotion_directives, or pass multiple keys to one calls.
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/shrine/plugins/kithe_promotion_directives.rb', line 90 def set_promotion_directives(hash) # ActiveJob sometimes has trouble if there are symbols in there, somewhat # unpredictably. And for other reasons, standardize on everything a string. hash = hash.collect { |k, v| [k.to_s, v.to_s]}.to_h unrecognized = hash.keys.collect(&:to_sym) - KithePromotionDirectives.allowed_promotion_directives unless unrecognized.length == 0 raise ArgumentError.new("Unrecognized promotion directive key: #{unrecognized.join('')}") end context[:promotion_directives] = promotion_directives.merge(hash).freeze end |