Module: Mara::Model::Dsl::ClassMethods
- Defined in:
- lib/mara/model/dsl.rb
Overview
Helper method added at the class level.
Instance Method Summary collapse
-
#add_gsi(name, partition_key, sort_key = nil) ⇒ void
Add a global secondary index definition.
-
#add_lsi(name, key_name) ⇒ void
Add a local secondary index definition.
-
#global_secondary_index(name) ⇒ GlobalSecondaryIndex
Get a defined global secondary index by name.
-
#global_secondary_indices ⇒ Hash<String, GlobalSecondaryIndex>
All registered global secondary indices.
-
#local_secondary_index(name) ⇒ LocalSecondaryIndex
Get a defined local secondary index by name.
-
#local_secondary_indices ⇒ Hash<String, LocalSecondaryIndex>
All registered local secondary indices.
-
#partition_key(partition_key = nil) ⇒ String
Set the partion key name for the model.
-
#primary_key(partition_key, sort_key = nil) ⇒ void
Set a partion_key and sort_key for a model.
-
#sort_key(sort_key = nil) ⇒ String
Set the sort key name for the model.
Instance Method Details
#add_gsi(name, partition_key, sort_key = nil) ⇒ void
This is only required for querying.
This method returns an undefined value.
Add a global secondary index definition.
175 176 177 |
# File 'lib/mara/model/dsl.rb', line 175 def add_gsi(name, partition_key, sort_key = nil) global_secondary_indices[name.to_s] = GlobalSecondaryIndex.new(name.to_s, partition_key.to_s, sort_key) end |
#add_lsi(name, key_name) ⇒ void
This is only required for querying.
This method returns an undefined value.
Add a local secondary index definition.
132 133 134 |
# File 'lib/mara/model/dsl.rb', line 132 def add_lsi(name, key_name) local_secondary_indices[name.to_s] = LocalSecondaryIndex.new(name.to_s, key_name.to_s) end |
#global_secondary_index(name) ⇒ GlobalSecondaryIndex
Get a defined global secondary index by name.
197 198 199 200 201 202 203 204 |
# File 'lib/mara/model/dsl.rb', line 197 def global_secondary_index(name) index = global_secondary_indices[name.to_s] if index.nil? raise Mara::Model::IndexError, "Can't find a GSI with the name `#{name}`" end index end |
#global_secondary_indices ⇒ Hash<String, GlobalSecondaryIndex>
All registered global secondary indices
185 186 187 |
# File 'lib/mara/model/dsl.rb', line 185 def global_secondary_indices @global_secondary_indices ||= {} end |
#local_secondary_index(name) ⇒ LocalSecondaryIndex
Get a defined local secondary index by name.
154 155 156 157 158 159 160 161 |
# File 'lib/mara/model/dsl.rb', line 154 def local_secondary_index(name) index = local_secondary_indices[name.to_s] if index.nil? raise Mara::Model::IndexError, "Can't find a LSI with the name `#{name}`" end index end |
#local_secondary_indices ⇒ Hash<String, LocalSecondaryIndex>
All registered local secondary indices
142 143 144 |
# File 'lib/mara/model/dsl.rb', line 142 def local_secondary_indices @local_secondary_indices ||= {} end |
#partition_key(partition_key = nil) ⇒ String
Set the partion key name for the model. This value is required.
99 100 101 102 103 104 105 |
# File 'lib/mara/model/dsl.rb', line 99 def partition_key(partition_key = nil) unless partition_key.nil? @partition_key = partition_key.to_s validates_presence_of :partition_key end @partition_key end |
#primary_key(partition_key, sort_key = nil) ⇒ void
This method returns an undefined value.
Set a partion_key and sort_key for a model.
88 89 90 91 |
# File 'lib/mara/model/dsl.rb', line 88 def primary_key(partition_key, sort_key = nil) partition_key(partition_key) sort_key(sort_key) end |
#sort_key(sort_key = nil) ⇒ String
Set the sort key name for the model.
113 114 115 116 117 118 119 120 |
# File 'lib/mara/model/dsl.rb', line 113 def sort_key(sort_key = nil) unless sort_key.nil? @sort_key = sort_key.to_s validates_presence_of :sort_key end @sort_key end |