sdb_dal 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ module SdbDal
2
+ module ActsAsSdbApplication
3
+ def self.included(base)
4
+ base.before_filter :prepare_repository
5
+ end
6
+ def prepare_repository
7
+ puts "prepare repo"
8
+ SdbDal::RepositoryFactory.instance.clear_session_cache
9
+ end
10
+ end
11
+ end
@@ -7,7 +7,6 @@ require File.dirname(__FILE__) +"/lazy_loading_text.rb"
7
7
  module SdbDal
8
8
  class DomainObject
9
9
 
10
- @@repository =nil
11
10
  @@items_to_commit=nil
12
11
  @@transaction_depth=0
13
12
  attr_accessor :sdb_key
@@ -542,10 +541,8 @@ def destroy(options={})
542
541
  if @repository
543
542
  return @repository
544
543
  end
545
- if @@repository
546
- return @@repository
547
- end
548
- return $repository
544
+
545
+ return self.class.repository
549
546
  end
550
547
  class << self
551
548
  def repository(options=nil)
@@ -553,9 +550,9 @@ def destroy(options={})
553
550
  if options and options.has_key?(:repository)
554
551
  return options[:repository]
555
552
  end
556
- if @repository
557
- return @repository
558
- end
553
+
554
+ $repository ||= RepositoryFactory.instance(options)
555
+
559
556
  return $repository
560
557
  end
561
558
  def find(*arguments)
@@ -0,0 +1,95 @@
1
+ require "sdb_dal/repository.rb"
2
+ require "sdb_dal/memory_repository.rb"
3
+
4
+ module SdbDal
5
+ class RepositoryFactory
6
+ #if this is rails insert code into application
7
+
8
+
9
+ def self.instance(options={})
10
+ if options and options.has_key?(:repository)
11
+ return options[:repository]
12
+ end
13
+ if @repository
14
+ return @repository
15
+ end
16
+
17
+ sdb_dal_config=find_config_section
18
+
19
+ if sdb_dal_config
20
+ if sdb_dal_config.has_key?("repository_class")
21
+ repo_class=eval sdb_dal_config["repository_class"]
22
+ else
23
+ repo_class=SdbDal::Repository
24
+ end
25
+ domain_prefix= sdb_dal_config["sdb_domain_prefix"]
26
+ clob_bucket= sdb_dal_config["s3_clob_bucket"]
27
+ aws_key_id = sdb_dal_config["aws_key_id"]
28
+ aws_secret_key = sdb_dal_config["aws_secret_key"]
29
+ memcache_servers= sdb_dal_config['memcache_servers']
30
+ memcache_servers = memcache_servers.split(",") if memcache_servers
31
+
32
+ return repo_class.new(domain_prefix,clob_bucket,aws_key_id,aws_secret_key,memcache_servers)
33
+ end
34
+ end
35
+
36
+
37
+
38
+ def self.find_config_section
39
+ return $sdb_dal_config if $sdb_dal_config
40
+ config_file_path=nil
41
+ config_section=nil
42
+
43
+ #when using rails use config/database.yml
44
+ if const_defined?(:RAILS_ROOT) and ENV.has_key?('RAILS_ENV')
45
+ config_file_path = File.join("#{RAILS_ROOT}","config","database.yml")
46
+
47
+ config_section =ENV['RAILS_ENV']+"_sdb_dal"
48
+
49
+
50
+
51
+ else
52
+ #when not using rails use try database.yml then try config/database.yml
53
+
54
+ if File.exists?("database.yml")
55
+
56
+ config_file_path = "database.yml"
57
+ elsif File.exists?(File.join("config", "database.yml"))
58
+ config_file_path = File.join("config", "database.yml")
59
+ end
60
+
61
+ config_section =(ENV['SDB_DAL_ENV'] || "production")+"_sdb_dal"
62
+ end
63
+ if config_file_path and config_section
64
+ config_file = YAML.load(File.open( config_file_path))
65
+
66
+ $sdb_dal_config = config_file[config_section]
67
+ end
68
+ return $sdb_dal_config
69
+ end
70
+ def self.set_repository(repository)
71
+ @repository=repository
72
+ end
73
+
74
+ end
75
+ def self.qualified_const_get(str)
76
+ path = str.to_s.split('::')
77
+ from_root = path[0].empty?
78
+ if from_root
79
+ from_root = []
80
+ path = path[1..-1]
81
+ else
82
+ start_ns = ((Class === self)||(Module === self)) ? self : self.class
83
+ from_root = start_ns.to_s.split('::')
84
+ end
85
+ until from_root.empty?
86
+ begin
87
+ return (from_root+path).inject(Object) { |ns,name| ns.const_get(name) }
88
+ rescue NameError
89
+ from_root.delete_at(-1)
90
+ end
91
+ end
92
+ path.inject(Object) { |ns,name| ns.const_get(name) }
93
+ end
94
+ end
95
+
data/lib/sdb_dal.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require "sdb_dal/repository.rb"
2
+ require "sdb_dal/repository_factory.rb"
3
+ require "sdb_dal/acts_as_sdb_application.rb"
2
4
  require "sdb_dal/memory_repository.rb"
3
5
  require "sdb_dal/domain_object.rb"
4
6
  require "sdb_dal/storage.rb"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sdb_dal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Knight
@@ -23,6 +23,7 @@ extra_rdoc_files: []
23
23
 
24
24
  files:
25
25
  - ./lib/sdb_dal.rb
26
+ - ./lib/sdb_dal/acts_as_sdb_application.rb
26
27
  - ./lib/sdb_dal/and_condition.rb
27
28
  - ./lib/sdb_dal/attribute_range.rb
28
29
  - ./lib/sdb_dal/domain_attribute_description.rb
@@ -39,6 +40,7 @@ files:
39
40
  - ./lib/sdb_dal/query_string_auth_generator.rb
40
41
  - ./lib/sdb_dal/reference.rb
41
42
  - ./lib/sdb_dal/repository.rb
43
+ - ./lib/sdb_dal/repository_factory.rb
42
44
  - ./lib/sdb_dal/s3.rb
43
45
  - ./lib/sdb_dal/sdb_formatter.rb
44
46
  - ./lib/sdb_dal/starts_with_condition.rb