Skip to content

Commit

Permalink
Merge d9eddde into 88cf7fd
Browse files Browse the repository at this point in the history
  • Loading branch information
brenden committed Jan 31, 2016
2 parents 88cf7fd + d9eddde commit ebfdd5c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Then you need to initialize Dynamoid config to get it going. Put code similar to
```ruby
Dynamoid.configure do |config|
config.adapter = 'aws_sdk_v2' # This adapter establishes a connection to the DynamoDB servers using Amazon's own AWS gem.
config.namespace = "dynamoid_app_development" # To namespace tables created by Dynamoid from other tables you might have.
config.namespace = "dynamoid_app_development" # To namespace tables created by Dynamoid from other tables you might have. Set to nil to avoid namespacing.
config.warn_on_scan = true # Output a warning to the logger when you perform a scan rather than a query on a table.
config.read_capacity = 100 # Read capacity for your tables
config.write_capacity = 20 # Write capacity for your tables
Expand Down
10 changes: 9 additions & 1 deletion lib/dynamoid/persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ module Persistence
module ClassMethods

def table_name
@table_name ||= "#{Dynamoid::Config.namespace}_#{options[:name] || base_class.name.split('::').last.downcase.pluralize}"
table_base_name = options[:name] || base_class.name.split('::').last
.downcase.pluralize
table_prefix = if Dynamoid::Config.namespace.nil? then
''
else
"#{Dynamoid::Config.namespace}_"
end

@table_name ||= "#{table_prefix}#{table_base_name}"
end

# Creates a table.
Expand Down
28 changes: 28 additions & 0 deletions spec/dynamoid/persistence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,34 @@
expect(Address.table_name).to eq 'dynamoid_tests_addresses'
end

context 'with namespace set to nil' do
def reload_address
Object.send(:remove_const, 'Address')
load 'app/models/address.rb'
end

namespace = Dynamoid::Config.namespace

before do
reload_address
Dynamoid.configure do |config|
config.namespace = nil
end
end

after do
reload_address
Dynamoid.configure do |config|
config.namespace = namespace
end
end

it 'does not add a namespace prefix to table names' do
table_name = Address.table_name
expect(table_name).to eq 'addresses'
end
end

it 'deletes an item completely' do
@user = User.create(:name => 'Josh')
@user.destroy
Expand Down

0 comments on commit ebfdd5c

Please sign in to comment.