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.
216 217 218 |
# File 'lib/aws-record/record.rb', line 216 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.
228 229 230 |
# File 'lib/aws-record/record.rb', line 228 def enable_mutation_tracking @track_mutations = true end |
#model_valid? ⇒ Boolean
242 243 244 |
# File 'lib/aws-record/record.rb', line 242 def model_valid? raise Errors::InvalidModel, 'Table models must include a hash key' if @keys.hash_key.nil? end |
#mutation_tracking_enabled? ⇒ Boolean
level, false otherwise.
234 235 236 237 238 239 240 |
# File 'lib/aws-record/record.rb', line 234 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.
191 192 193 194 195 196 197 198 199 200 |
# File 'lib/aws-record/record.rb', line 191 def provisioned_throughput resp = dynamodb_client.describe_table(table_name: table_name) throughput = resp.table.provisioned_throughput { read_capacity_units: throughput.read_capacity_units, write_capacity_units: throughput.write_capacity_units } rescue DynamoDB::Errors::ResourceNotFoundException raise Record::Errors::TableDoesNotExist 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.
180 181 182 |
# File 'lib/aws-record/record.rb', line 180 def set_table_name(name) # rubocop:disable Naming/AccessorMethodName @table_name = name end |
#table_exists? ⇒ Boolean
Checks if the model’s table name exists in Amazon DynamoDB.
205 206 207 208 209 210 |
# File 'lib/aws-record/record.rb', line 205 def table_exists? resp = dynamodb_client.describe_table(table_name: table_name) resp.table.table_status == 'ACTIVE' rescue DynamoDB::Errors::ResourceNotFoundException false 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 128 129 |
# File 'lib/aws-record/record.rb', line 118 def table_name # rubocop:disable Style/RedundantSelf @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 # rubocop:enable Style/RedundantSelf end |