Module: Commutator::Model::ClassMethods
- Defined in:
- lib/commutator/model.rb
Overview
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
194
195
196
197
|
# File 'lib/commutator/model.rb', line 194
def method_missing(method, *args)
super unless respond_to?(method)
query_options.send(method, *args)
end
|
Instance Method Details
#build_options_proxy(operation, context = self) ⇒ Object
186
187
188
|
# File 'lib/commutator/model.rb', line 186
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
173
174
175
176
|
# File 'lib/commutator/model.rb', line 173
def get_item(options = build_options_proxy(:get_item))
item = client.get_item(options).item
new(item) unless item.nil?
end
|
#get_item_options ⇒ Object
161
162
163
|
# File 'lib/commutator/model.rb', line 161
def get_item_options
build_options_proxy(:get_item)
end
|
#inherited(subclass) ⇒ Object
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/commutator/model.rb', line 138
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)
subclass.scoped_options = options_cache_class
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
158
159
|
# 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
190
191
192
|
# File 'lib/commutator/model.rb', line 190
def options_class(operation)
scoped_options[operation]
end
|
#query(options = build_options_proxy(:query)) ⇒ Object
178
179
180
|
# File 'lib/commutator/model.rb', line 178
def query(options = build_options_proxy(:query))
collection_for(:query, options)
end
|
#query_options ⇒ Object
165
166
167
|
# File 'lib/commutator/model.rb', line 165
def query_options
build_options_proxy(:query)
end
|
#respond_to?(method, *args) ⇒ Boolean
199
200
201
|
# File 'lib/commutator/model.rb', line 199
def respond_to?(method, *args)
super || (const_defined?(:Scopes, false) && const_get(:Scopes).method_defined?(method))
end
|
#scan(options = build_options_proxy(:scan)) ⇒ Object
182
183
184
|
# File 'lib/commutator/model.rb', line 182
def scan(options = build_options_proxy(:scan))
collection_for(:scan, options)
end
|
#scan_options ⇒ Object
169
170
171
|
# File 'lib/commutator/model.rb', line 169
def scan_options
build_options_proxy(:scan)
end
|