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.
152 153 154 |
# File 'lib/aws-record/record.rb', line 152 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.
161 162 163 |
# File 'lib/aws-record/record.rb', line 161 def enable_mutation_tracking @track_mutations = true end |
#model_valid? ⇒ Boolean
175 176 177 178 179 |
# File 'lib/aws-record/record.rb', line 175 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.
167 168 169 170 171 172 173 |
# File 'lib/aws-record/record.rb', line 167 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.
122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/aws-record/record.rb', line 122 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.
111 112 113 |
# File 'lib/aws-record/record.rb', line 111 def set_table_name(name) @table_name = name end |
#table_exists? ⇒ Boolean
Checks if the model’s table name exists in Amazon DynamoDB.
138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/aws-record/record.rb', line 138 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.
87 88 89 90 91 92 93 |
# File 'lib/aws-record/record.rb', line 87 def table_name if @table_name @table_name else @table_name = self.name.split("::").join("_") end end |