thingtank 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thingtank
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-09 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &11429140 !ruby/object:Gem::Requirement
16
+ requirement: &18327300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *11429140
24
+ version_requirements: *18327300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: couchrest
27
- requirement: &11428380 !ruby/object:Gem::Requirement
27
+ requirement: &18326380 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *11428380
35
+ version_requirements: *18326380
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: couchrest_model
38
- requirement: &11427640 !ruby/object:Gem::Requirement
38
+ requirement: &18325560 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *11427640
46
+ version_requirements: *18325560
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard
49
- requirement: &11426640 !ruby/object:Gem::Requirement
49
+ requirement: &18324940 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *11426640
57
+ version_requirements: *18324940
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: libnotify
60
- requirement: &11425640 !ruby/object:Gem::Requirement
60
+ requirement: &18324160 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *11425640
68
+ version_requirements: *18324160
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rb-inotify
71
- requirement: &11409560 !ruby/object:Gem::Requirement
71
+ requirement: &18323560 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *11409560
79
+ version_requirements: *18323560
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: guard-minitest
82
- requirement: &11408740 !ruby/object:Gem::Requirement
82
+ requirement: &18322820 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *11408740
90
+ version_requirements: *18322820
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: linecache19
93
- requirement: &11407820 !ruby/object:Gem::Requirement
93
+ requirement: &18322220 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *11407820
101
+ version_requirements: *18322220
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: ruby-debug19
104
- requirement: &11407120 !ruby/object:Gem::Requirement
104
+ requirement: &18321600 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *11407120
112
+ version_requirements: *18321600
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: yard
115
- requirement: &11406360 !ruby/object:Gem::Requirement
115
+ requirement: &18321000 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ~>
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: 0.6.0
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *11406360
123
+ version_requirements: *18321000
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: bundler
126
- requirement: &11405540 !ruby/object:Gem::Requirement
126
+ requirement: &18320380 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ~>
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: 1.0.0
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *11405540
134
+ version_requirements: *18320380
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: jeweler
137
- requirement: &11404340 !ruby/object:Gem::Requirement
137
+ requirement: &18292320 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ~>
@@ -142,7 +142,7 @@ dependencies:
142
142
  version: 1.6.4
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *11404340
145
+ version_requirements: *18292320
146
146
  description:
147
147
  email: ! 'Base64.decode64(bGludXhAbWFyY3JlbmVhcm5zLmRl
148
148
 
@@ -169,12 +169,12 @@ files:
169
169
  - lib/couchrest/extensions/view.rb
170
170
  - lib/thingtank.rb
171
171
  - lib/thingtank/callbacks.rb
172
+ - lib/thingtank/character.rb
173
+ - lib/thingtank/character_handling.rb
172
174
  - lib/thingtank/dependencies.rb
173
175
  - lib/thingtank/fakebase.rb
174
176
  - lib/thingtank/force_update.rb
175
177
  - lib/thingtank/instance_methods.rb
176
- - lib/thingtank/role.rb
177
- - lib/thingtank/role_handling.rb
178
178
  - lib/thingtank/shared_methods.rb
179
179
  - lib/thingtank/shortcuts.rb
180
180
  - lib/thingtank/thingtank.rb
@@ -202,7 +202,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
202
  version: '0'
203
203
  segments:
204
204
  - 0
205
- hash: 3392017887304112040
205
+ hash: -405721453140054073
206
206
  required_rubygems_version: !ruby/object:Gem::Requirement
207
207
  none: false
208
208
  requirements:
@@ -214,5 +214,5 @@ rubyforge_project:
214
214
  rubygems_version: 1.8.15
215
215
  signing_key:
216
216
  specification_version: 3
217
- summary: thin wrapper around couchrest
217
+ summary: let couchrest docs have multiple characters at the same time
218
218
  test_files: []
@@ -1,198 +0,0 @@
1
- class ThingTank
2
- module RoleHandling
3
- def self.included(klass)
4
- klass.class_eval do
5
-
6
- def properties_of_role(klass)
7
- hsh = {}
8
- (klass.role_properties || []).each do |k|
9
- hsh.update(k.to_s => self[k.to_s]) unless self[k.to_s].nil?
10
- end
11
- hsh
12
- end
13
-
14
- def get_role(klass, db)
15
- hsh = properties_of_role(klass)
16
- hsh.update "_id" => self["_id"], "_rev" => self["_rev"] if (had?(klass) && !hsh.empty?)
17
- inst = klass.new hsh, :directly_set_attributes => true, :database => db
18
- @dependencies.save_role(inst)
19
- inst
20
- end
21
-
22
- # get property as pseudo doc to play with
23
- def with(key, &code)
24
- self[key] ||= {}
25
- case self[key]
26
- when String # assume we got a doc id
27
- doc = ThingTank.get(self[key])
28
- (code.call(doc) ; doc.save) if code
29
- doc
30
- when Hash
31
- doc = self.class.new self[key], :directly_set_attributes => true, :database => FakeBase.new(self, nil)
32
- @dependencies.add_child(key, doc)
33
- @dependencies.refresh(false)
34
- (code.call(doc) ; doc.save) if code
35
- doc
36
- when Array
37
- with_all(key)
38
- else
39
- raise "not supported: #{self[key].inspect}"
40
- end
41
- end
42
-
43
- def with_all(key, props=nil)
44
- self[key] ||= []
45
- props ||= [self[key]].flatten
46
- docs = props.collect { |prop| self.class.new prop, :directly_set_attributes => true, :database => FakeBase.new(self, nil) }
47
- @dependencies.add_child(key, docs)
48
- docs.each { |doc| yield doc ; doc.save } if block_given?
49
- docs
50
- end
51
-
52
- def with_nth(key,n)
53
- self[key] ||= []
54
- props = [self[key]].flatten
55
- n = 0 if n == :first
56
- n = props.size-1 if n == :last
57
- n = 0 if n < 0
58
- while n > props.size - 1
59
- props << {}
60
- end
61
- docs = with_all(key, props)
62
- (yield docs[n] ; docs[n].save) if block_given?
63
- docs[n]
64
- end
65
-
66
- def with_first(key,&code)
67
- with_nth(key,:first, &code)
68
- end
69
-
70
- def with_last(key,&code)
71
- with_nth(key,:last, &code)
72
- end
73
-
74
- def property_to_role(key, klass)
75
- case self[key]
76
- when Hash
77
- with(key).to_role(klass)
78
- when Array
79
- with_all(key).collect { |doc| doc.to_role(klass) }
80
- end
81
- end
82
-
83
- # register a role
84
- def register_role(klass)
85
- self['roles'] ||= []
86
- self['roles'] << klass.to_s unless self['roles'].include? klass.to_s
87
- end
88
-
89
- def unregister_role(role)
90
- if has?(role)
91
- self["roles"] ||= []
92
- self["roles"].delete role.to_s
93
- end
94
- end
95
-
96
- def add_role(klass, key=nil, &code)
97
- if key
98
- key = key.to_s
99
- if val = self[key]
100
- self[key] = [val] unless val.is_a? Array
101
- self[key] << {}
102
- last_role(klass, key, &code)
103
- else
104
- self[key] = {}
105
- to_role(klass, key, &code)
106
- end
107
- else
108
- to_role(klass, &code)
109
- end
110
- end
111
-
112
- def _root
113
- @dependencies.find_root_doc
114
- end
115
-
116
- def delete_role(role_doc)
117
- klass = role_doc.class
118
- deleteable_attributes(klass).each { |k| delete(k) ; role_doc[k] = nil }
119
- @dependencies.already_saved(role_doc) # prevent an endless loop
120
- unregister_role(klass)
121
- @dependencies.remove_role(klass)
122
- @dependencies.refresh_parent()
123
- end
124
-
125
- def deleteable_attributes(klass)
126
- role_attrs = attributes_by_roles
127
- role = klass.to_s
128
- deleteable_attrs = klass.role_properties.select do |prop|
129
- role_attrs[prop].empty? || (role_attrs[prop].size == 1 && role_attrs[prop].first == role)
130
- end
131
- %w| _id _rev type update_me roles|.each{ |k| deleteable_attrs.delete k }
132
- return deleteable_attrs
133
- end
134
-
135
- def attributes_by_roles()
136
- attributes = {}
137
- self["roles"].each do |role|
138
- role.constantize.role_properties.each do |prop|
139
- attributes[prop] ||= []
140
- attributes[prop] << role unless attributes[prop].include?(role)
141
- end
142
- end
143
- return attributes
144
- end
145
-
146
- def to_role(klass, key=nil, add_role=true, &code)
147
- @dependencies.add_role(klass) if add_role && key.nil?
148
- role = key ? property_to_role(key, klass) : FakeBase.new(self, klass, add_role).get()
149
- (code.call(role) ; role.flush_to_doc) if code
150
- role
151
- end
152
-
153
- alias :as :to_role
154
- alias :has :to_role
155
- alias :act_as :to_role
156
- alias :be :to_role
157
- alias :have :to_role
158
- alias :are :to_role
159
- alias :is :to_role
160
-
161
- def save_role_attributes(role_doc)
162
- @dependencies.already_saved(role_doc) # prevent an endless loop
163
- attributes = role_doc.to_role_hash(true)
164
- unsavebales = attributes.keys - (role_doc.class.role_properties || [])
165
- raise "role #{role_doc.class} tried to save properties that it does not have: #{unsavebales.inspect}" unless unsavebales.empty?
166
- self.update_attributes attributes
167
- @dependencies.refresh_parent()
168
- end
169
-
170
- # if the doc when coming from db already had this role
171
- def had?(klass)
172
- return false unless self["roles"] and self["roles"].include? klass.name
173
- return true
174
- end
175
-
176
- # has the document the role, is it supposed to have it and does it have the necessary properties
177
- def has?(klass)
178
- return true if @dependencies.has_role?(klass)
179
- return false unless self["roles"] and self["roles"].include? klass.name
180
- could_be? klass
181
- end
182
- alias :is? :has?
183
-
184
- # could the document have the role
185
- def could_have?(klass)
186
- to_role(klass, nil, false).valid?
187
- end
188
- alias :could_be? :could_have?
189
-
190
- # roles that are not valid
191
- def invalid_roles
192
- (self["roles"] || []).select { |role| !self.as(role.constantize).valid? }
193
- end
194
-
195
- end
196
- end
197
- end
198
- end