Permalink
Browse files

Move connection management to a separate module.

  • Loading branch information...
1 parent 8682707 commit c6bc7d0c84771912cb092b20b96f09480708f879 @leeatchison committed Jan 25, 2012
Showing with 53 additions and 49 deletions.
  1. +1 −1 lib/active_dynamodb.rb
  2. +5 −0 lib/active_dynamodb/base.rb
  3. +47 −48 lib/active_dynamodb/dynamodb_connection.rb
View
@@ -1,5 +1,4 @@
require "active_dynamodb/version"
-require "active_dynamodb/base"
require "active_dynamodb/errors"
require "active_dynamodb/dynamodb_connection"
require "active_dynamodb/table_config"
@@ -10,6 +9,7 @@
require "active_dynamodb/relation"
require "active_dynamodb/validators"
require "active_dynamodb/persistence"
+require "active_dynamodb/base"
#
# TODOs:
@@ -12,5 +12,10 @@ class Base
define_model_callbacks :create, :update, :save, :destroy
+ include ActiveDynamoDB::ConnectionInstance
+ class << self
+ include ActiveDynamoDB::Connection
+ end
+
end
end
@@ -1,52 +1,10 @@
module ActiveDynamoDB
- class Base
- #
- #
- # Connection Management
- #
- #
- class << self
- #
- # Names (default or configured)
- #
- def table_name
- @dynamodb_table_name||=substitutions("%RailsEnvName%_%AppName%_%PluralModelName%")
- end
- def counter_table_name
- @dynamodb_counter_table_name||=substitutions("%RailsEnvName%_Counter")
- end
- def counter_key_name
- @dynamodb_counter_key_name||=substitutions("%AppName%_%ModelName%")
- end
-
- #
- # Various connections to DynamoDB
- #
- def dynamodb
- @dynamodb||=AWS::DynamoDB.new
- end
- def dynamodb_counter_table
- return @dynamodb_counter_table unless @dynamodb_counter_table.nil?
- the_table=dynamodb.tables[counter_table_name]
- raise CantFindTable,table_name if the_table.nil?
- the_table.load_schema
- @dynamodb_counter_table=the_table
- end
- def dynamodb_table
- return @dynamodb_table unless @dynamodb_table.nil?
- the_table=dynamodb.tables[table_name]
- raise CantFindTable,table_name if the_table.nil?
- the_table.load_schema
- @dynamodb_table=the_table
- end
- def counter_hash_key
- dynamodb_counter_table.hash_key.name
- end
- def hash_key
- dynamodb_table.hash_key.name
- end
- end
-
+ #
+ #
+ # Connection Management
+ #
+ #
+ module ConnectionInstance
#
#
# Helpers to call class versions...
@@ -61,5 +19,46 @@ def dynamodb_table
def validate_dynamodb
raise ConnectionNotDefined if dynamodb.nil?
end
+ end
+ module Connection
+ #
+ # Names (default or configured)
+ #
+ def table_name
+ @dynamodb_table_name||=substitutions("%RailsEnvName%_%AppName%_%PluralModelName%")
+ end
+ def counter_table_name
+ @dynamodb_counter_table_name||=substitutions("%RailsEnvName%_Counter")
+ end
+ def counter_key_name
+ @dynamodb_counter_key_name||=substitutions("%AppName%_%ModelName%")
+ end
+
+ #
+ # Various connections to DynamoDB
+ #
+ def dynamodb
+ @dynamodb||=AWS::DynamoDB.new
+ end
+ def dynamodb_counter_table
+ return @dynamodb_counter_table unless @dynamodb_counter_table.nil?
+ the_table=dynamodb.tables[counter_table_name]
+ raise CantFindTable,table_name if the_table.nil?
+ the_table.load_schema
+ @dynamodb_counter_table=the_table
+ end
+ def dynamodb_table
+ return @dynamodb_table unless @dynamodb_table.nil?
+ the_table=dynamodb.tables[table_name]
+ raise CantFindTable,table_name if the_table.nil?
+ the_table.load_schema
+ @dynamodb_table=the_table
+ end
+ def counter_hash_key
+ dynamodb_counter_table.hash_key.name
+ end
+ def hash_key
+ dynamodb_table.hash_key.name
end
+ end
end

0 comments on commit c6bc7d0

Please sign in to comment.