Module: Commutator::Model::ClassMethods

Defined in:
lib/commutator/model.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



197
198
199
200
# File 'lib/commutator/model.rb', line 197

def method_missing(method, *args)
  super unless respond_to?(method)
  query_options.send(method, *args)
end

Instance Attribute Details

#clientObject



147
148
149
# File 'lib/commutator/model.rb', line 147

def client
  @client ||= ::Commutator::SimpleClient.new
end

Instance Method Details

#build_options_proxy(operation, context = self) ⇒ Object



184
185
186
# File 'lib/commutator/model.rb', line 184

def build_options_proxy(operation, context = self)
  Options::Proxy.new(context, operation)
end

#create(attrs) ⇒ Object



151
152
153
# File 'lib/commutator/model.rb', line 151

def create(attrs)
  new(attrs).tap { |dp| dp.put_item_options.execute }
end

#get_item(options = build_options_proxy(:get_item)) ⇒ Object



171
172
173
174
# File 'lib/commutator/model.rb', line 171

def get_item(options = build_options_proxy(:get_item))
  item = client.get_item(options).item
  new(item) unless item.nil?
end

#get_item_optionsObject



159
160
161
# File 'lib/commutator/model.rb', line 159

def get_item_options
  build_options_proxy(:get_item)
end

#inherited(subclass) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
# File 'lib/commutator/model.rb', line 135

def inherited(subclass)
  subclass.attribute_names.merge(attribute_names)
  before_hooks.each { |k, v| subclass.before_hooks[k] = v.dup }

  subclass.table_name(table_name)
  subclass.primary_key(hash: primary_key_hash_name,
                       range: primary_key_range_name)

  scopes = const_defined?("Scopes", false) ? const_get("Scopes") : nil
  subclass.const_set("Scopes", Module.new { include scopes }) if scopes
end

#modify_collection_items_with(*modifiers, factory: false) ⇒ Object



155
156
157
# File 'lib/commutator/model.rb', line 155

def modify_collection_items_with(*modifiers, factory: false)
  self.collection_item_modifiers = [ItemModifiers.new(modifiers, factory: factory)].unshift(*collection_item_modifiers)
end

#options_class(operation) ⇒ Object



188
189
190
191
192
193
194
195
# File 'lib/commutator/model.rb', line 188

def options_class(operation)
  @scoped_options ||= Hash.new do |h, k|
    scopes = self.const_defined?("Scopes", false) ? self.const_get("Scopes") : nil
    const_name = k.to_s.camelize
    h[k] = enhance_options(const_name, scopes)
  end
  @scoped_options[operation]
end

#query(options = build_options_proxy(:query)) ⇒ Object



176
177
178
# File 'lib/commutator/model.rb', line 176

def query(options = build_options_proxy(:query))
  collection_for(:query, options)
end

#query_optionsObject



163
164
165
# File 'lib/commutator/model.rb', line 163

def query_options
  build_options_proxy(:query)
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


202
203
204
# File 'lib/commutator/model.rb', line 202

def respond_to?(method)
  super || (const_defined?(:Scopes, false) && const_get(:Scopes).method_defined?(method))
end

#scan(options = build_options_proxy(:scan)) ⇒ Object



180
181
182
# File 'lib/commutator/model.rb', line 180

def scan(options = build_options_proxy(:scan))
  collection_for(:scan, options)
end

#scan_optionsObject



167
168
169
# File 'lib/commutator/model.rb', line 167

def scan_options
  build_options_proxy(:scan)
end