Module: Dynamoid::Document::ClassMethods
- Defined in:
- lib/dynamoid/document.rb
Instance Method Summary collapse
- #attr_readonly(*read_only_attributes) ⇒ Object
-
#build(attrs = {}) ⇒ Dynamoid::Document
Initialize a new object.
-
#capacity_mode ⇒ Object
Returns the billing (capacity) mode for this table.
- #choose_right_class(attrs) ⇒ Object
-
#count ⇒ Object
Returns the number of items for this class.
- #deep_subclasses ⇒ Object
-
#exists?(id_or_conditions = {}) ⇒ Boolean
Does this object exist?.
-
#hash_key ⇒ Object
Returns the id field for this class.
-
#inheritance_field ⇒ Object
Returns the field name used to support STI for this table.
-
#read_capacity ⇒ Object
Returns the read_capacity for this table.
-
#table(options = {}) ⇒ Object
Set up table options, including naming it whatever you want, setting the id key, and manually overriding read and write capacity.
-
#write_capacity ⇒ Object
Returns the write_capacity for this table.
Instance Method Details
#attr_readonly(*read_only_attributes) ⇒ Object
35 36 37 38 |
# File 'lib/dynamoid/document.rb', line 35 def attr_readonly(*read_only_attributes) ActiveSupport::Deprecation.warn('[Dynamoid] .attr_readonly is deprecated! Call .find instead of') self.read_only_attributes.concat read_only_attributes.map(&:to_s) end |
#build(attrs = {}) ⇒ Dynamoid::Document
Initialize a new object.
87 88 89 |
# File 'lib/dynamoid/document.rb', line 87 def build(attrs = {}) choose_right_class(attrs).new(attrs) end |
#capacity_mode ⇒ Object
Returns the billing (capacity) mode for this table. Could be either :provisioned or :on_demand
57 58 59 |
# File 'lib/dynamoid/document.rb', line 57 def capacity_mode [:capacity_mode] || Dynamoid::Config.capacity_mode end |
#choose_right_class(attrs) ⇒ Object
129 130 131 |
# File 'lib/dynamoid/document.rb', line 129 def choose_right_class(attrs) attrs[inheritance_field] ? attrs[inheritance_field].constantize : self end |
#count ⇒ Object
Returns the number of items for this class.
76 77 78 |
# File 'lib/dynamoid/document.rb', line 76 def count Dynamoid.adapter.count(table_name) end |
#deep_subclasses ⇒ Object
125 126 127 |
# File 'lib/dynamoid/document.rb', line 125 def deep_subclasses subclasses + subclasses.map(&:deep_subclasses).flatten end |
#exists?(id_or_conditions = {}) ⇒ Boolean
Does this object exist?
Supports primary key in format that find call understands.
Multiple keys and single compound primary key should be passed only as Array explicitily.
Supports conditions in format that where call understands.
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/dynamoid/document.rb', line 112 def exists?(id_or_conditions = {}) case id_or_conditions when Hash then where(id_or_conditions).count >= 1 else begin find(id_or_conditions) true rescue Dynamoid::Errors::RecordNotFound false end end end |
#hash_key ⇒ Object
Returns the id field for this class.
69 70 71 |
# File 'lib/dynamoid/document.rb', line 69 def hash_key [:key] || :id end |
#inheritance_field ⇒ Object
Returns the field name used to support STI for this table.
62 63 64 |
# File 'lib/dynamoid/document.rb', line 62 def inheritance_field [:inheritance_field] || :type end |
#read_capacity ⇒ Object
Returns the read_capacity for this table.
43 44 45 |
# File 'lib/dynamoid/document.rb', line 43 def read_capacity [:read_capacity] || Dynamoid::Config.read_capacity end |
#table(options = {}) ⇒ Object
Set up table options, including naming it whatever you want, setting the id key, and manually overriding read and write capacity.
30 31 32 33 |
# File 'lib/dynamoid/document.rb', line 30 def table( = {}) self. = super if defined? super end |