Module: Spree::Core::ControllerHelpers::RespondWith::ClassMethods

Defined in:
lib/spree/core/controller_helpers/respond_with.rb

Instance Method Summary collapse

Instance Method Details

#clear_overrides!Object



44
45
46
# File 'lib/spree/core/controller_helpers/respond_with.rb', line 44

def clear_overrides!
  self.spree_responders = {}
end

#respond_override(options = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/spree/core/controller_helpers/respond_with.rb', line 48

def respond_override(options={})
  unless options.blank?
    action_name = options.keys.first
    action_value = options.values.first

    if action_name.blank? || action_value.blank?
      raise ArgumentError, "invalid values supplied #{options.inspect}"
    end

    format_name = action_value.keys.first
    format_value = action_value.values.first

    if format_name.blank? || format_value.blank?
      raise ArgumentError, "invalid values supplied #{options.inspect}"
    end

    if format_value.is_a?(Proc)
      options = {action_name.to_sym => {format_name.to_sym => {:success => format_value}}}
    end

    self.spree_responders.deep_merge!(self.name.to_sym => options)
  end
end