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
1 change: 1 addition & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ jobs:
rubygems: ${{ matrix.rubygems }}
bundler: ${{ matrix.bundler }}
bundler-cache: true
cache-version: v2
- name: Run Rubocop
run: bundle exec rubocop -DESP
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ Style/TrailingCommaInArguments:
Enabled: false
Style/UnlessElse:
Enabled: false
Style/OneClassPerFile:
Exclude:
- 'README.md'

# We aren't so brave to tackle all these issues right now
Layout/LineLength:
Expand Down
4 changes: 4 additions & 0 deletions .rubocop_rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ RSpec/StubbedMock:

RSpec/IndexedLet:
Enabled: false

# Disable while callbacks specs use printing into output
RSpec/Output:
Enabled: false
86 changes: 51 additions & 35 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ PATH
GEM
remote: https://rubygems.org/
specs:
activemodel (8.1.0)
activesupport (= 8.1.0)
activesupport (8.1.0)
activemodel (8.1.2)
activesupport (= 8.1.2)
activesupport (8.1.2)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.3.1)
Expand All @@ -24,68 +24,83 @@ GEM
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
uri (>= 0.13.1)
addressable (2.8.9)
public_suffix (>= 2.0.2, < 8.0)
appraisal (2.5.0)
bundler
rake
thor (>= 0.14.0)
ast (2.4.3)
aws-eventstream (1.4.0)
aws-partitions (1.1176.0)
aws-sdk-core (3.234.0)
aws-partitions (1.1221.0)
aws-sdk-core (3.242.0)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.992.0)
aws-sigv4 (~> 1.9)
base64
bigdecimal
jmespath (~> 1, >= 1.6.1)
logger
aws-sdk-dynamodb (1.155.0)
aws-sdk-core (~> 3, >= 3.234.0)
aws-sdk-dynamodb (1.163.0)
aws-sdk-core (~> 3, >= 3.241.4)
aws-sigv4 (~> 1.5)
aws-sigv4 (1.12.1)
aws-eventstream (~> 1, >= 1.0.2)
base64 (0.3.0)
bigdecimal (3.3.1)
byebug (12.0.0)
bigdecimal (4.0.1)
byebug (13.0.0)
reline (>= 0.6.0)
childprocess (5.1.0)
logger (~> 1.5)
codecov (0.6.0)
simplecov (>= 0.15, < 0.22)
coderay (1.1.3)
concurrent-ruby (1.3.5)
connection_pool (2.5.4)
concurrent-ruby (1.3.6)
connection_pool (3.0.2)
diff-lcs (1.6.2)
docile (1.4.1)
drb (2.2.3)
i18n (1.14.7)
i18n (1.14.8)
concurrent-ruby (~> 1.0)
iniparse (1.5.0)
io-console (0.8.2)
jmespath (1.6.2)
json (2.15.1)
json (2.18.1)
json-schema (6.1.0)
addressable (~> 2.8)
bigdecimal (>= 3.1, < 5)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
logger (1.7.0)
mcp (0.8.0)
json-schema (>= 4.1)
method_source (1.1.0)
minitest (5.26.0)
minitest (6.0.2)
drb (~> 2.0)
prism (~> 1.5)
overcommit (0.68.0)
childprocess (>= 0.6.3, < 6)
iniparse (~> 1.4)
rexml (>= 3.3.9)
parallel (1.27.0)
parser (3.3.9.0)
parser (3.3.10.2)
ast (~> 2.4.1)
racc
prism (1.6.0)
pry (0.15.2)
prism (1.9.0)
pry (0.16.0)
coderay (~> 1.1)
method_source (~> 1.0)
pry-byebug (3.11.0)
byebug (~> 12.0)
pry (>= 0.13, < 0.16)
reline (>= 0.6.0)
pry-byebug (3.12.0)
byebug (~> 13.0)
pry (>= 0.13, < 0.17)
public_suffix (7.0.5)
racc (1.8.1)
rainbow (3.1.1)
rake (13.3.0)
rake (13.3.1)
regexp_parser (2.11.3)
reline (0.6.3)
io-console (~> 0.5)
rexml (3.4.4)
rspec (3.13.2)
rspec-core (~> 3.13.0)
Expand All @@ -96,25 +111,26 @@ GEM
rspec-expectations (3.13.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.6)
rspec-mocks (3.13.8)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.6)
rubocop (1.81.6)
rspec-support (3.13.7)
rubocop (1.85.1)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
mcp (~> 0.6)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.47.1, < 2.0)
rubocop-ast (>= 1.49.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.47.1)
rubocop-ast (1.49.0)
parser (>= 3.3.7.2)
prism (~> 1.4)
rubocop-md (2.0.3)
prism (~> 1.7)
rubocop-md (2.0.4)
lint_roller (~> 1.1)
rubocop (>= 1.72.1)
rubocop-packaging (0.6.0)
Expand All @@ -127,9 +143,9 @@ GEM
rubocop-rake (0.7.1)
lint_roller (~> 1.1)
rubocop (>= 1.72.1)
rubocop-rspec (3.7.0)
rubocop-rspec (3.9.0)
lint_roller (~> 1.1)
rubocop (~> 1.72, >= 1.72.1)
rubocop (~> 1.81)
rubocop-thread_safety (0.7.3)
lint_roller (~> 1.1)
rubocop (~> 1.72, >= 1.72.1)
Expand All @@ -149,18 +165,18 @@ GEM
simplecov
simplecov-lcov (0.9.0)
simplecov_json_formatter (0.1.4)
thor (1.4.0)
thor (1.5.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (3.2.0)
unicode-emoji (~> 4.1)
unicode-emoji (4.1.0)
uri (1.0.4)
yard (0.9.37)
unicode-emoji (4.2.0)
uri (1.1.1)
yard (0.9.38)

PLATFORMS
ruby
x86_64-linux
x86_64-darwin-24

DEPENDENCIES
appraisal
Expand Down
2 changes: 1 addition & 1 deletion lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def set(values)
# delete explicitly attributes if assigned nil value and configured
# to not store nil values
values_to_update = values_sanitized.reject { |_, v| v.nil? }
values_to_delete = values_sanitized.select { |_, v| v.nil? }
values_to_delete = values_sanitized.select { |_, v| v.nil? } # rubocop:disable Style/PartitionInsteadOfDoubleSelect

@updates.merge!(values_to_update)
@deletions.merge!(values_to_delete)
Expand Down
2 changes: 1 addition & 1 deletion lib/dynamoid/fields/declare.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def generate_instance_methods_for_alias
end

def warn_if_method_exists(method)
if @source.instance_methods.include?(method.to_sym)
if @source.method_defined?(method.to_sym)
Dynamoid.logger.warn("Method #{method} generated for the field #{@name} overrides already existing method")
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/dynamoid/transaction_write/destroy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def initialize(model, **options)
end

def on_registration
validate_model!

@aborted = true
@model.run_callbacks(:destroy) do
validate_primary_key!

@aborted = false
true
end
Expand Down Expand Up @@ -70,7 +70,7 @@ def action_request

private

def validate_model!
def validate_primary_key!
raise Dynamoid::Errors::MissingHashKey if @model.hash_key.nil?
raise Dynamoid::Errors::MissingRangeKey if @model_class.range_key? && @model.range_value.nil?
end
Expand Down
6 changes: 3 additions & 3 deletions lib/dynamoid/transaction_write/save.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def initialize(model, **options)
end

def on_registration
validate_model!

if @options[:validate] != false && !(@valid = @model.valid?)
if @options[:raise_error]
raise Dynamoid::Errors::DocumentNotValid, @model
Expand All @@ -35,6 +33,8 @@ def on_registration
@model.run_callbacks(:save) do
@model.run_callbacks(callback_name) do
@model.run_callbacks(:validate) do
validate_primary_key!

@aborted = false
true
end
Expand Down Expand Up @@ -88,7 +88,7 @@ def action_request

private

def validate_model!
def validate_primary_key!
raise Dynamoid::Errors::MissingHashKey if !@was_new_record && @model.hash_key.nil?
raise Dynamoid::Errors::MissingRangeKey if @model_class.range_key? && @model.range_value.nil?
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dynamoid/transaction_write/update_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def action_request
builder.set_attributes(changes_dumped)
else
nil_attributes = changes_dumped.select { |_, v| v.nil? }
non_nil_attributes = changes_dumped.reject { |_, v| v.nil? }
non_nil_attributes = changes_dumped.reject { |_, v| v.nil? } # rubocop:disable Style/PartitionInsteadOfDoubleSelect

builder.remove_attributes(nil_attributes.keys)
builder.set_attributes(non_nil_attributes)
Expand Down
12 changes: 6 additions & 6 deletions spec/dynamoid/adapter_plugin/aws_sdk_v3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
4 => [:id, { range_key: { range: :number } }],
5 => [:id, { read_capacity: 10_000, write_capacity: 1000 }]
}.each do |n, args|
name = "dynamoid_tests_TestTable#{n}"
name = "dynamoid_tests_TestTable#{n}" # rubocop:disable RSpec/LeakyLocalVariable
let(:"test_table#{n}") do
Dynamoid.adapter.create_table(name, *args)
name
Expand Down Expand Up @@ -987,14 +987,14 @@ def dynamo_request(table_name, conditions = [], options = {})
it 'performs query on a table and returns items' do
Dynamoid.adapter.put_item(test_table1, id: '1', name: 'Josh')

expect(Dynamoid.adapter.query(test_table1, { id: [[:eq, '1']] }).first).to eq([[id: '1', name: 'Josh'], { last_evaluated_key: nil }])
expect(Dynamoid.adapter.query(test_table1, { id: [[:eq, '1']] }).first).to eq([[{ id: '1', name: 'Josh' }], { last_evaluated_key: nil }])
end

it 'performs query on a table and returns items if there are multiple items' do
Dynamoid.adapter.put_item(test_table1, id: '1', name: 'Josh')
Dynamoid.adapter.put_item(test_table1, id: '2', name: 'Justin')

expect(Dynamoid.adapter.query(test_table1, { id: [[:eq, '1']] }).first).to eq([[id: '1', name: 'Josh'], { last_evaluated_key: nil }])
expect(Dynamoid.adapter.query(test_table1, { id: [[:eq, '1']] }).first).to eq([[{ id: '1', name: 'Josh' }], { last_evaluated_key: nil }])
end

context 'backoff is specified' do
Expand Down Expand Up @@ -1031,22 +1031,22 @@ def dynamo_request(table_name, conditions = [], options = {})
it 'performs scan on a table and returns items' do
Dynamoid.adapter.put_item(test_table1, id: '1', name: 'Josh')

expect(Dynamoid.adapter.scan(test_table1, [name: { eq: 'Josh' }]).to_a).to eq [[[{ id: '1', name: 'Josh' }], { last_evaluated_key: nil }]]
expect(Dynamoid.adapter.scan(test_table1, [{ name: { eq: 'Josh' } }]).to_a).to eq [[[{ id: '1', name: 'Josh' }], { last_evaluated_key: nil }]]
end

it 'performs scan on a table and returns items if there are multiple items but only one match' do
Dynamoid.adapter.put_item(test_table1, id: '1', name: 'Josh')
Dynamoid.adapter.put_item(test_table1, id: '2', name: 'Justin')

expect(Dynamoid.adapter.scan(test_table1, [name: { eq: 'Josh' }]).to_a).to eq [[[{ id: '1', name: 'Josh' }], { last_evaluated_key: nil }]]
expect(Dynamoid.adapter.scan(test_table1, [{ name: { eq: 'Josh' } }]).to_a).to eq [[[{ id: '1', name: 'Josh' }], { last_evaluated_key: nil }]]
end

it 'performs scan on a table and returns multiple items if there are multiple matches' do
Dynamoid.adapter.put_item(test_table1, id: '1', name: 'Josh')
Dynamoid.adapter.put_item(test_table1, id: '2', name: 'Josh')

expect(
Dynamoid.adapter.scan(test_table1, [name: { eq: 'Josh' }]).to_a
Dynamoid.adapter.scan(test_table1, [{ name: { eq: 'Josh' } }]).to_a
).to match(
[
[
Expand Down
2 changes: 1 addition & 1 deletion spec/dynamoid/adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_table
3 => [:id, { range_key: { range: :number } }],
4 => [:id, { range_key: { range: :number } }]
}.each do |n, args|
name = "dynamoid_tests_TestTable#{n}"
name = "dynamoid_tests_TestTable#{n}" # rubocop:disable RSpec/LeakyLocalVariable
let(:"test_table#{n}") do
Dynamoid.adapter.create_table(name, *args)
name
Expand Down
Loading
Loading