module Shrine::Plugins::KithePromotionDirectives::AttacherMethods
Public Instance Methods
promotion_directives()
click to toggle source
context, lazily initializing to hash for convenience.
# File lib/shrine/plugins/kithe_promotion_directives.rb, line 104 def promotion_directives context[:promotion_directives] ||= {} end
set_promotion_directives(hash)
click to toggle source
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.
@example
some_model.file_attacher.set_promotion_directives(skip_callbacks: true) some_model.save!
# 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