Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aws-record.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
spec.summary = 'AWS Record library for Amazon DynamoDB'
spec.description = 'Provides an object mapping abstraction for Amazon DynamoDB.'
spec.homepage = 'https://github.com/aws/aws-sdk-ruby-record'
spec.license = 'Apache 2.0'
spec.license = 'Apache-2.0'

spec.require_paths = ['lib']
spec.files = Dir['lib/**/*.rb', 'LICENSE', 'CHANGELOG.md', 'VERSION']
Expand Down
2 changes: 0 additions & 2 deletions features/batch/step_definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@
expect(expected.all? { |e| actual.include?(e) }).to be_truthy
end

private

def remove_model_key(item)
item.delete(:model)
item
Expand Down
2 changes: 1 addition & 1 deletion lib/aws-record/record/batch_read.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def find(klass, key = {})
# See {Batch.read} for example usage.
# @return [Array] an array of unordered new items
def execute!
operation_keys = unprocessed_keys[0..BATCH_GET_ITEM_LIMIT - 1]
operation_keys = unprocessed_keys[0..(BATCH_GET_ITEM_LIMIT - 1)]
@unprocessed_keys = unprocessed_keys[BATCH_GET_ITEM_LIMIT..] || []

operations = build_operations(operation_keys)
Expand Down
2 changes: 1 addition & 1 deletion lib/aws-record/record/model_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _validate_attr_name(name)
end

def _check_if_reserved(name)
return unless @model_class.instance_methods.include?(name)
return unless @model_class.method_defined?(name)

raise Errors::ReservedName, "Cannot name an attribute #{name}, that would collide with an " \
'existing instance method.'
Expand Down
10 changes: 5 additions & 5 deletions lib/aws-record/record/table_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def migrate!
# we will only alter TTL status if we have a TTL attribute defined. We
# may someday support explicit TTL deletion, but we do not yet do this.
return unless @ttl_attribute
return if _ttl_compatibility_check
return if ttl_compatibility_check?

client.update_time_to_live(
table_name: @model_class.table_name,
Expand All @@ -268,7 +268,7 @@ def migrate!
# @return [Boolean] true if remote is compatible, false otherwise.
def compatible?
resp = @client.describe_table(table_name: @model_class.table_name)
_compatible_check(resp) && _ttl_compatibility_check
_compatible_check(resp) && ttl_compatibility_check?
rescue DynamoDB::Errors::ResourceNotFoundException
false
end
Expand All @@ -285,14 +285,14 @@ def exact_match?
_keys_equal(resp) &&
_ad_equal(resp) &&
_gsi_equal(resp) &&
_ttl_match_check
ttl_match_check?
rescue DynamoDB::Errors::ResourceNotFoundException
false
end

private

def _ttl_compatibility_check
def ttl_compatibility_check?
if @ttl_attribute
ttl_status = @client.describe_time_to_live(
table_name: @model_class.table_name
Expand All @@ -305,7 +305,7 @@ def _ttl_compatibility_check
end
end

def _ttl_match_check
def ttl_match_check?
ttl_status = @client.describe_time_to_live(
table_name: @model_class.table_name
)
Expand Down
4 changes: 2 additions & 2 deletions lib/aws-record/record/table_migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TableMigration
# class. If this option is not included, a client will be constructed for
# you with default parameters.
def initialize(model, opts = {})
_assert_model_valid(model)
valid_model?(model)
@model = model
@client = opts[:client] || model.dynamodb_client || Aws::DynamoDB::Client.new
@client.config.user_agent_frameworks << 'aws-record'
Expand Down Expand Up @@ -130,7 +130,7 @@ def wait_until_available

private

def _assert_model_valid(model)
def valid_model?(model)
_assert_required_include(model)
model.model_valid?
end
Expand Down
5 changes: 5 additions & 0 deletions spec/aws-record/record/attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Record
let(:model) do
Class.new do
include(Aws::Record)

string_attr(:id, hash_key: true)
string_attr(:body)
end
Expand Down Expand Up @@ -171,6 +172,7 @@ module Record
let(:klass) do
Class.new do
include(Aws::Record)

set_table_name('TestTable')
integer_attr(:id, hash_key: true)
atomic_counter(:counter)
Expand Down Expand Up @@ -244,6 +246,7 @@ module Record
let(:parent_model) do
Class.new do
include(Aws::Record)

integer_attr(:id, hash_key: true)
date_attr(:date, range_key: true)
list_attr(:list)
Expand All @@ -253,13 +256,15 @@ module Record
let(:child_model) do
Class.new(parent_model) do
include(Aws::Record)

string_attr(:body)
end
end

let(:child_model2) do
Class.new(parent_model) do
include(Aws::Record)

string_attr(:body2)
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/aws-record/record/batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
describe '.write' do
Planet = Class.new do
include(Aws::Record)

integer_attr(:id, hash_key: true)
string_attr(:name, range_key: true)
end
Expand Down Expand Up @@ -87,6 +88,7 @@
let(:food) do
Class.new do
include(Aws::Record)

set_table_name('FoodTable')
integer_attr(:id, hash_key: true, database_attribute_name: 'Food ID')
string_attr(:dish, range_key: true)
Expand All @@ -97,13 +99,15 @@
let(:breakfast) do
Class.new(food) do
include(Aws::Record)

boolean_attr(:gluten_free)
end
end

let(:drink) do
Class.new do
include(Aws::Record)

set_table_name('DrinkTable')
integer_attr(:id, hash_key: true)
string_attr(:drink)
Expand Down
6 changes: 6 additions & 0 deletions spec/aws-record/record/dirty_tracking_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
Class.new do
include(ActiveModel::Model)
include(Aws::Record)

set_table_name(:test_table)
string_attr(:mykey, hash_key: true)
string_attr(:body)
Expand Down Expand Up @@ -317,6 +318,7 @@
Class.new do
include(Aws::Record)
include(ActiveModel::Validations)

set_table_name('TestTable')
integer_attr(:id, hash_key: true)
string_attr(:body)
Expand All @@ -335,6 +337,7 @@
model = Class.new do
include(Aws::Record)
include(ActiveModel::Validations)

set_table_name('TestTable')
integer_attr(:id, hash_key: true)
string_attr(:body)
Expand Down Expand Up @@ -424,6 +427,7 @@
model = Class.new do
include(Aws::Record)
include(ActiveModel::Validations)

set_table_name('TestTable')
integer_attr(:id, hash_key: true)
string_attr(:body)
Expand Down Expand Up @@ -480,6 +484,7 @@
let(:klass) do
Class.new do
include(Aws::Record)

set_table_name(:test_table)
string_attr(:mykey, hash_key: true)
string_attr(:body)
Expand All @@ -493,6 +498,7 @@
let(:klass_with_defaults) do
Class.new do
include(Aws::Record)

set_table_name(:test_table)
string_attr(:mykey, hash_key: true)
map_attr(:dirty_map, default_value: {})
Expand Down
3 changes: 3 additions & 0 deletions spec/aws-record/record/item_collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Record
let(:model) do
Class.new do
include(Aws::Record)

set_table_name('TestTable')
integer_attr(:id, hash_key: true)
end
Expand Down Expand Up @@ -206,6 +207,7 @@ module Record
let(:model_a) do
Class.new do
include(Aws::Record)

set_table_name('TestTable')
integer_attr(:id, hash_key: true)
string_attr(:class_name)
Expand All @@ -216,6 +218,7 @@ module Record
let(:model_b) do
Class.new do
include(Aws::Record)

set_table_name('TestTable')
integer_attr(:id, hash_key: true)
string_attr(:class_name)
Expand Down
3 changes: 3 additions & 0 deletions spec/aws-record/record/item_operations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Record
let(:klass) do
Class.new do
include(Aws::Record)

set_table_name('TestTable')
integer_attr(:id, hash_key: true)
date_attr(:date, range_key: true, database_attribute_name: 'MyDate')
Expand Down Expand Up @@ -343,6 +344,7 @@ module Record
let(:klass_with_defaults) do
Class.new do
include(Aws::Record)

set_table_name('TestTable')
string_attr(:mykey, hash_key: true)
map_attr(:dirty_map, default_value: {})
Expand Down Expand Up @@ -828,6 +830,7 @@ module Record
::TEST_TABLE = Class.new do
include(Aws::Record)
include(ActiveModel::Validations)

set_table_name('TestTable')
integer_attr(:id, hash_key: true)
date_attr(:date, range_key: true)
Expand Down
1 change: 1 addition & 0 deletions spec/aws-record/record/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Record
let(:klass) do
Class.new do
include(Aws::Record)

set_table_name('TestTable')
integer_attr(:id, hash_key: true)
date_attr(:date, range_key: true)
Expand Down
3 changes: 3 additions & 0 deletions spec/aws-record/record/secondary_indexes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Record
let(:klass) do
Class.new do
include(Aws::Record)

set_table_name('TestTable')
integer_attr(:forum_id, hash_key: true)
integer_attr(:post_id, range_key: true)
Expand Down Expand Up @@ -161,6 +162,7 @@ module Record
let(:parent_model) do
Class.new do
include(Aws::Record)

integer_attr(:id, hash_key: true)
string_attr(:name, range_key: true)
string_attr(:message)
Expand All @@ -170,6 +172,7 @@ module Record
let(:child_model) do
Class.new(parent_model) do
include(Aws::Record)

string_attr(:foo)
string_attr(:bar)
end
Expand Down
2 changes: 2 additions & 0 deletions spec/aws-record/record/table_migration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module Record
let(:model) do
model = Class.new do
include(Aws::Record)

set_table_name('TestTable')
integer_attr(:id, hash_key: true)
end
Expand All @@ -57,6 +58,7 @@ module Record
let(:klass) do
Class.new do
include(Aws::Record)

set_table_name('TestTable')
integer_attr(:id, hash_key: true)
date_attr(:date, range_key: true, database_attribute_name: 'datekey')
Expand Down
2 changes: 2 additions & 0 deletions spec/aws-record/record/transactions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Record
let(:table_one) do
Class.new do
include(Aws::Record)

set_table_name('TableOne')
integer_attr(:id, hash_key: true)
string_attr(:range, range_key: true)
Expand All @@ -23,6 +24,7 @@ module Record
let(:table_two) do
Class.new do
include(Aws::Record)

set_table_name('TableTwo')
string_attr(:uuid, hash_key: true)
string_attr(:body)
Expand Down
Loading