Module: MadCart::Store::Base::ClassMethods

Defined in:
lib/mad_cart/store/base.rb

Instance Method Summary collapse

Instance Method Details

#after_initialize(*args) ⇒ Object



169
170
171
# File 'lib/mad_cart/store/base.rb', line 169

def after_initialize(*args)
  @after_init_delegate = parse_delegate(args.first, :after_initialize)
end

#create_connection_with(*args) ⇒ Object



147
148
149
150
151
# File 'lib/mad_cart/store/base.rb', line 147

def create_connection_with(*args)
  @connection_delegate = parse_delegate(args.first, :create_connection_with)
  opts = args[1] || {}
  @required_connection_args = opts[:requires] || []
end

#fetch(model, options = {}) ⇒ Object



153
154
155
156
157
158
159
# File 'lib/mad_cart/store/base.rb', line 153

def fetch(model, options={})
  @fetch_delegates ||= {}
  @format_delegates ||= {}
  @fetch_delegates[model] = parse_delegate(options, :fetch)

  define_method_for(model)
end

#format(model, options = {}) ⇒ Object



161
162
163
164
165
166
167
# File 'lib/mad_cart/store/base.rb', line 161

def format(model, options={})
  if @fetch_delegates[model].nil?
    raise ArgumentError, "Cannot define 'format' for a model that has not defined 'fetch'"
  end

  @format_delegates[model] = parse_delegate(options, :format)
end