Module: Aws::Record::RecordClassMethods
- Included in:
- Aws::Record
- Defined in:
- lib/aws-record/record.rb
Instance Method Summary collapse
-
#disable_mutation_tracking ⇒ Object
Turns off mutation tracking for all attributes in the model.
-
#enable_mutation_tracking ⇒ Object
Turns on mutation tracking for all attributes in the model.
- #model_valid? ⇒ Boolean
-
#mutation_tracking_enabled? ⇒ Boolean
level, false otherwise.
-
#provisioned_throughput ⇒ Hash
Fetches the table’s provisioned throughput from the associated Amazon DynamoDB table.
-
#set_table_name(name) ⇒ Object
Allows you to set a custom Amazon DynamoDB table name for this model class.
-
#table_exists? ⇒ Boolean
Checks if the model’s table name exists in Amazon DynamoDB.
-
#table_name ⇒ Object
Returns the Amazon DynamoDB table name for this model class.
Instance Method Details
#disable_mutation_tracking ⇒ Object
Turns off mutation tracking for all attributes in the model.
Note: disable_mutation_tracking
is inherited from a parent model when it is explicitly specified in the parent.
222 223 224 |
# File 'lib/aws-record/record.rb', line 222 def disable_mutation_tracking @track_mutations = false end |
#enable_mutation_tracking ⇒ Object
Turns on mutation tracking for all attributes in the model. Note that mutation tracking is on by default, so you generally would not need to call this. It is provided in case there is a need to dynamically turn this feature on and off, though that would be generally discouraged and could cause inaccurate mutation tracking at runtime.
Note: enable_mutation_tracking
is inherited from a parent model when it is explicitly specified in the parent.
234 235 236 |
# File 'lib/aws-record/record.rb', line 234 def enable_mutation_tracking @track_mutations = true end |
#model_valid? ⇒ Boolean
248 249 250 251 252 |
# File 'lib/aws-record/record.rb', line 248 def model_valid? if @keys.hash_key.nil? raise Errors::InvalidModel.new("Table models must include a hash key") end end |
#mutation_tracking_enabled? ⇒ Boolean
level, false otherwise.
240 241 242 243 244 245 246 |
# File 'lib/aws-record/record.rb', line 240 def mutation_tracking_enabled? if defined?(@track_mutations) @track_mutations else @track_mutations = true end end |
#provisioned_throughput ⇒ Hash
Fetches the table’s provisioned throughput from the associated Amazon DynamoDB table.
189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/aws-record/record.rb', line 189 def provisioned_throughput begin resp = dynamodb_client.describe_table(table_name: table_name) throughput = resp.table.provisioned_throughput return { read_capacity_units: throughput.read_capacity_units, write_capacity_units: throughput.write_capacity_units } rescue DynamoDB::Errors::ResourceNotFoundException raise Record::Errors::TableDoesNotExist end end |
#set_table_name(name) ⇒ Object
Allows you to set a custom Amazon DynamoDB table name for this model class.
Inheritance Support
table_name
is inherited from a parent model when it is explicitly specified in the parent.
The parent model will need to have set_table_name
defined in their model for the child model to inherit the table_name
. If no set_table_name
is defined, the parent and child models will have separate table names based on their class name.
If both parent and child models have defined set_table_name
in their model, the child model will override the table_name
with theirs.
178 179 180 |
# File 'lib/aws-record/record.rb', line 178 def set_table_name(name) @table_name = name end |
#table_exists? ⇒ Boolean
Checks if the model’s table name exists in Amazon DynamoDB.
205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/aws-record/record.rb', line 205 def table_exists? begin resp = dynamodb_client.describe_table(table_name: table_name) if resp.table.table_status == "ACTIVE" true else false end rescue DynamoDB::Errors::ResourceNotFoundException false end end |
#table_name ⇒ Object
Returns the Amazon DynamoDB table name for this model class.
By default, this will simply be the name of the class. However, you can also define a custom table name at the class level to be anything that you want.
Note: table_name
is inherited from a parent model when #set_table_name is explicitly specified in the parent.
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/aws-record/record.rb', line 118 def table_name @table_name ||= begin if Aws::Record.extends_record?(self) && default_table_name(self.superclass) != self.superclass.table_name self.superclass.instance_variable_get('@table_name') else default_table_name(self) end end end |