peace_love 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source :rubygems
1
+ source :rubygems
2
2
 
3
- gem 'angry_hash', '0.0.5'
3
+ gem 'angry_hash', '~>0.1.1'
4
4
  gem 'mongo'
5
5
  gem 'bson_ext'
6
6
 
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ begin
11
11
  gemspec.test_files = []
12
12
 
13
13
  gemspec.add_dependency("mongo", ['~>1.0.0'])
14
- gemspec.add_dependency("angry_hash", ['=0.0.5'])
14
+ gemspec.add_dependency("angry_hash", ['~>0.1.0'])
15
15
  end
16
16
  rescue LoadError
17
17
  puts "Jeweler not available. Install it with: gem install jeweler"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.3
@@ -46,7 +46,7 @@ module PeaceLove
46
46
  def __extend(doc)
47
47
  if mixin
48
48
  doc.extend mixin
49
- doc.__source_collection = self if doc.respond_to?(:__source_collection=)
49
+ doc.__collection = self if doc.respond_to?(:__collection=)
50
50
  end
51
51
 
52
52
  doc
@@ -7,24 +7,20 @@ module PeaceLove
7
7
 
8
8
  base.module_eval do
9
9
  def self.extend_object(obj)
10
- Doc.mark_extension(obj,self)
11
10
  super
11
+ Doc.mark_extension(obj,self)
12
12
  end
13
13
  end
14
14
  end
15
15
 
16
-
17
- def object_extensions
18
- @object_extensions ||= {}
19
- end
20
-
21
16
  def mark_extension(doc,mod)
22
- # puts "mark_extension doc=#{doc.class} mod=#{mod}"
17
+ #puts "mark_extension doc=#{doc.class} mod=#{mod}"
23
18
 
24
- if (previous_mod = object_extensions[doc.__id__]) && previous_mod != mod
19
+ # TODO store extension on the doc!
20
+ if (previous_mod = doc.__peace_love_extension) && previous_mod != mod
25
21
  raise "doc #{doc} has already been extended by a different PeaceLove::Doc (was: #{previous_mod}, now: #{mod})"
26
22
  end
27
- object_extensions[doc.__id__] = mod
23
+ doc.__peace_love_extension = mod
28
24
 
29
25
  setup_extended_doc(doc,mod)
30
26
  end
@@ -45,10 +41,10 @@ module PeaceLove
45
41
  mixin_registry[target_class][field.to_s] = [:hash, mod, options]
46
42
  end
47
43
 
48
- def extend_doc(doc,mod,parent_obj)
44
+ def extend_doc(doc,mod,parent_doc)
49
45
  # puts "extend_doc doc=#{doc.class} mod=#{mod} parent_obj=#{parent_obj.class}"
50
46
 
51
- if !parent_obj.nil? && doc.nil?
47
+ if !parent_doc.nil? && doc.nil?
52
48
  doc = AngryHash.new
53
49
  end
54
50
 
@@ -64,7 +60,10 @@ module PeaceLove
64
60
  end
65
61
 
66
62
  def mixin_to(parent_obj,field,obj)
67
- extension = object_extensions[parent_obj.__id__]
63
+ # puts "mixin_to field=#{field}"
64
+
65
+ extension = parent_obj.__peace_love_extension
66
+ # puts "found extension=#{extension.inspect}"
68
67
 
69
68
  if mixin = mixin_registry[extension][field.to_s]
70
69
  kind,mod,options = *mixin
@@ -73,15 +72,15 @@ module PeaceLove
73
72
  obj = options[:default]
74
73
  end
75
74
 
76
- # XXX - what happens when obj is nil
77
-
78
75
  case kind
79
76
  when :single
80
77
  obj = extend_doc(obj,mod,parent_obj)
81
78
  when :array
82
79
  # XXX - this is ok for now... we really need to typecheck, perhaps wrap in a smart-array
80
+ obj ||= []
83
81
  obj = obj.map {|elt| extend_doc(elt, mod, parent_obj)}
84
82
  when :hash
83
+ obj ||= {}
85
84
  obj = obj.inject(AngryHash.new) do |h,(k,elt)|
86
85
  h[k] = extend_doc(elt,mod,parent_obj)
87
86
  h
@@ -101,12 +100,12 @@ module PeaceLove
101
100
  self['id']
102
101
  end
103
102
 
104
- def __source_collection=(col)
105
- @source_collection = col
103
+ def __collection=(col)
104
+ @collection = col
106
105
  end
107
106
 
108
- def __parent_doc(doc)
109
- self.__source_collection = doc.__source_collection if doc.respond_to?(:__source_collection)
107
+ def __parent_doc=(doc)
108
+ self.__collection = doc.__collection if doc.respond_to?(:__collection)
110
109
  @parent_doc = doc
111
110
  end
112
111
 
@@ -114,8 +113,16 @@ module PeaceLove
114
113
  @parent_doc
115
114
  end
116
115
 
117
- def __source_collection
118
- @source_collection
116
+ def __collection
117
+ @collection
118
+ end
119
+
120
+ def __peace_love_extension=(mod)
121
+ @__peace_love_extension = mod
122
+ end
123
+
124
+ def __peace_love_extension
125
+ @__peace_love_extension
119
126
  end
120
127
 
121
128
  module ClassMethods
@@ -9,7 +9,11 @@ module Rails #:nodoc:
9
9
  config_file = Rails.root + "config/database.yml"
10
10
  if config_file.file?
11
11
  settings = YAML.load( ERB.new(config_file.read).result )[Rails.env]
12
- ::PeaceLove.connect(settings)
12
+ if settings
13
+ ::PeaceLove.connect(settings)
14
+ else
15
+ raise "Unable to connect to mongo; #{config_file.relative_path_from(Rails.root)} doesn't have an entry for the #{Rails.env} environment."
16
+ end
13
17
  end
14
18
  end
15
19
 
@@ -24,7 +28,7 @@ You need to set up a #{cfg_file} looking like\n
24
28
  host: localhost
25
29
 
26
30
  EOMSG
27
- raise( "Unable to connect to mongodb using #{Rails.root+'config/database.yml'}" )
31
+ raise( "Unable to connect to mongodb using #{Rails.root+'config/database.yml'} env=#{Rails.env}" )
28
32
  end
29
33
  end
30
34
  end
data/peace_love.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{peace_love}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Lachie Cox"]
12
- s.date = %q{2010-08-02}
12
+ s.date = %q{2010-08-23}
13
13
  s.description = %q{A simple mixin layer for enhancing hashes retrieved from MongoDB. It eschews the normal 'mapping' compulsion of mongo libraries.}
14
14
  s.email = %q{lachie@smartbomb.com.au}
15
15
  s.files = [
@@ -40,14 +40,14 @@ Gem::Specification.new do |s|
40
40
 
41
41
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
42
42
  s.add_runtime_dependency(%q<mongo>, ["~> 1.0.0"])
43
- s.add_runtime_dependency(%q<angry_hash>, ["= 0.0.5"])
43
+ s.add_runtime_dependency(%q<angry_hash>, ["~> 0.1.0"])
44
44
  else
45
45
  s.add_dependency(%q<mongo>, ["~> 1.0.0"])
46
- s.add_dependency(%q<angry_hash>, ["= 0.0.5"])
46
+ s.add_dependency(%q<angry_hash>, ["~> 0.1.0"])
47
47
  end
48
48
  else
49
49
  s.add_dependency(%q<mongo>, ["~> 1.0.0"])
50
- s.add_dependency(%q<angry_hash>, ["= 0.0.5"])
50
+ s.add_dependency(%q<angry_hash>, ["~> 0.1.0"])
51
51
  end
52
52
  end
53
53
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 3
9
+ version: 0.1.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Lachie Cox
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-02 00:00:00 +10:00
17
+ date: 2010-08-23 00:00:00 +10:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -36,13 +36,13 @@ dependencies:
36
36
  prerelease: false
37
37
  requirement: &id002 !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "="
39
+ - - ~>
40
40
  - !ruby/object:Gem::Version
41
41
  segments:
42
42
  - 0
43
+ - 1
43
44
  - 0
44
- - 5
45
- version: 0.0.5
45
+ version: 0.1.0
46
46
  type: :runtime
47
47
  version_requirements: *id002
48
48
  description: A simple mixin layer for enhancing hashes retrieved from MongoDB. It eschews the normal 'mapping' compulsion of mongo libraries.