Module: Aws::Record::RecordClassMethods
- Included in:
- Aws::Record
- Defined in:
- lib/aws-record/record.rb
Instance Method Summary collapse
-
#configure_client(opts = {}) ⇒ Object
Configures the Amazon DynamoDB client used by this class and all instances of this class.
-
#disable_mutation_tracking ⇒ Object
Turns off mutation tracking for all attributes in the model.
-
#dynamodb_client ⇒ Aws::DynamoDB::Client
Gets the Aws::DynamoDB::Client instance that this model uses.
-
#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
#configure_client(opts = {}) ⇒ Object
Configures the Amazon DynamoDB client used by this class and all instances of this class.
Please note that this method is also called internally when you first attempt to perform an operation against the remote end, if you have not already configured a client. As such, please read and understand the documentation in the AWS SDK for Ruby V2 around configuration to ensure you understand how default configuration behavior works. When in doubt, call this method to ensure your client is configured the way you want it to be configured.
169 170 171 172 173 174 |
# File 'lib/aws-record/record.rb', line 169 def configure_client(opts = {}) provided_client = opts.delete(:client) opts[:user_agent_suffix] = _user_agent(opts.delete(:user_agent_suffix)) client = provided_client || Aws::DynamoDB::Client.new(opts) @dynamodb_client = client end |
#disable_mutation_tracking ⇒ Object
Turns off mutation tracking for all attributes in the model.
188 189 190 |
# File 'lib/aws-record/record.rb', line 188 def disable_mutation_tracking @track_mutations = false end |
#dynamodb_client ⇒ Aws::DynamoDB::Client
Gets the Aws::DynamoDB::Client instance that this model uses. When called for the first time, if #configure_client has not yet been called, will configure a new client for you with default parameters.
183 184 185 |
# File 'lib/aws-record/record.rb', line 183 def dynamodb_client @dynamodb_client ||= configure_client 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.
197 198 199 |
# File 'lib/aws-record/record.rb', line 197 def enable_mutation_tracking @track_mutations = true end |
#model_valid? ⇒ Boolean
207 208 209 210 211 |
# File 'lib/aws-record/record.rb', line 207 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.
203 204 205 |
# File 'lib/aws-record/record.rb', line 203 def mutation_tracking_enabled? @track_mutations == false ? false : true 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 |