passive_record 0.4.6 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50c7310ba09f037ee279f9ee0fb42cadb875c7b8
|
4
|
+
data.tar.gz: 6d61cec9dca1338c117a996fa2330580e66861b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7422229e4baeac8309309ab02e043a1bda67ecdec36be394eea4ec29ad5c25dc21eeda9384c5f3e6b46120a3f28cfe36a81e350050596ce9f8d846e093d61fc9
|
7
|
+
data.tar.gz: ef897faa83e6699f666f46c29334045ae1962ebe071ac87a19efbf840c9b3716d2c0e6ea176ec4b868f9d007dab8d0d75796a3c344538a714aa548fb6d7e26cd
|
@@ -20,7 +20,7 @@ module PassiveRecord
|
|
20
20
|
child_class.where(parent_model_id_field => parent_model.id).all
|
21
21
|
end
|
22
22
|
|
23
|
-
def_delegators :all, :each, :last, :all?, :empty
|
23
|
+
def_delegators :all, :each, :last, :all?, :empty?, :sample
|
24
24
|
|
25
25
|
def where(conditions={})
|
26
26
|
child_class.where(conditions.merge(parent_model_id_field.to_sym => parent_model.id))
|
@@ -91,20 +91,22 @@ module PassiveRecord
|
|
91
91
|
end
|
92
92
|
|
93
93
|
def intermediary_conditions
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
94
|
+
intermediary_key = if intermediary_relation.association.is_a?(HasManyAssociation)
|
95
|
+
intermediary_relation.association.children_name_sym.to_s.singularize.to_sym
|
96
|
+
elsif intermediary_relation.association.is_a?(HasManyThroughAssociation)
|
97
|
+
intermediary_relation.association.through_class.to_s.singularize.to_sym
|
98
|
+
else
|
99
|
+
raise "Intermediary association #{intermediary_relation.association} is not has many or has many through...?"
|
100
|
+
end
|
101
|
+
|
102
|
+
nested_conds = { intermediary_key => { parent_model_id_field.to_sym => parent_model.id } }
|
99
103
|
|
100
104
|
if nested_association.is_a?(HasManyThroughAssociation)
|
101
105
|
n = nested_association
|
102
106
|
hash = nested_conds
|
103
|
-
compound_key = []
|
104
107
|
|
105
|
-
until n.is_a?(
|
108
|
+
until !n.is_a?(HasManyThroughAssociation)
|
106
109
|
key = n.through_class.to_s.singularize.to_sym
|
107
|
-
compound_key.push(key)
|
108
110
|
hash = {key => hash}
|
109
111
|
n = n.nested_association
|
110
112
|
end
|
@@ -5,6 +5,8 @@ module PassiveRecord
|
|
5
5
|
extend Forwardable
|
6
6
|
include PassiveRecord::ArithmeticHelpers
|
7
7
|
|
8
|
+
attr_reader :conditions
|
9
|
+
|
8
10
|
def initialize(klass,conditions={},scope=nil)
|
9
11
|
@klass = klass
|
10
12
|
@conditions = conditions
|
@@ -20,19 +22,41 @@ module PassiveRecord
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def all
|
23
|
-
return [] unless @conditions
|
24
|
-
matching = method(:matching_instances)
|
25
25
|
if @scope
|
26
|
+
matching = @scope.method(:matching_instances)
|
26
27
|
if negated?
|
27
|
-
@klass.reject(
|
28
|
+
@klass.reject(&matching)
|
28
29
|
else
|
29
|
-
@klass.select(
|
30
|
+
@klass.select(&matching)
|
30
31
|
end
|
31
32
|
else
|
33
|
+
matching = method(:matching_instances)
|
32
34
|
@klass.select(&matching)
|
33
35
|
end
|
34
36
|
end
|
35
|
-
def_delegators :all, :
|
37
|
+
def_delegators :all, :sample
|
38
|
+
|
39
|
+
def each
|
40
|
+
if @scope
|
41
|
+
matching = @scope.method(:matching_instances)
|
42
|
+
if negated?
|
43
|
+
@klass.all.each do |instance| #reject(&matching)
|
44
|
+
yield instance unless matching[instance]
|
45
|
+
end
|
46
|
+
else
|
47
|
+
@klass.all.each do |instance|
|
48
|
+
yield instance if matching[instance]
|
49
|
+
end
|
50
|
+
# @klass.select(&matching)
|
51
|
+
end
|
52
|
+
else
|
53
|
+
matching = method(:matching_instances)
|
54
|
+
@klass.all.each do |instance|
|
55
|
+
yield instance if matching[instance]
|
56
|
+
end
|
57
|
+
# @klass.select(&matching)
|
58
|
+
end
|
59
|
+
end
|
36
60
|
|
37
61
|
def matching_instances(instance)
|
38
62
|
@conditions.all? do |(field,value)|
|
@@ -49,7 +73,7 @@ module PassiveRecord
|
|
49
73
|
end
|
50
74
|
|
51
75
|
def where(new_conditions={})
|
52
|
-
@conditions
|
76
|
+
@conditions.merge!(new_conditions)
|
53
77
|
self
|
54
78
|
end
|
55
79
|
|
@@ -61,6 +85,14 @@ module PassiveRecord
|
|
61
85
|
false
|
62
86
|
end
|
63
87
|
|
88
|
+
def conjoined?
|
89
|
+
false
|
90
|
+
end
|
91
|
+
|
92
|
+
def basic?
|
93
|
+
!negated? && !disjoined? && !conjoined?
|
94
|
+
end
|
95
|
+
|
64
96
|
def and(scope_query)
|
65
97
|
ConjoinedQuery.new(@klass, self, scope_query)
|
66
98
|
end
|
@@ -71,6 +103,9 @@ module PassiveRecord
|
|
71
103
|
if negated? && @scope.nil? && @conditions.empty?
|
72
104
|
@scope = scope_query
|
73
105
|
self
|
106
|
+
elsif basic? && scope_query.basic?
|
107
|
+
@conditions.merge!(scope_query.conditions)
|
108
|
+
self
|
74
109
|
else
|
75
110
|
scope_query.and(self)
|
76
111
|
end
|
@@ -81,12 +116,10 @@ module PassiveRecord
|
|
81
116
|
|
82
117
|
protected
|
83
118
|
def evaluate_condition(instance, field, value)
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
elsif value.is_a?(Array)
|
89
|
-
value.include?(instance.send(field))
|
119
|
+
case value
|
120
|
+
when Hash then evaluate_nested_conditions(instance, field, value)
|
121
|
+
when Range then value.cover?(instance.send(field))
|
122
|
+
when Array then value.include?(instance.send(field))
|
90
123
|
else
|
91
124
|
instance.send(field) == value
|
92
125
|
end
|
@@ -97,12 +130,10 @@ module PassiveRecord
|
|
97
130
|
association && value.all? do |(association_field,val)|
|
98
131
|
if association.is_a?(Associations::Relation) && !association.singular?
|
99
132
|
association.where(association_field => val).any?
|
133
|
+
elsif val.is_a?(Hash)
|
134
|
+
evaluate_nested_conditions(association, association_field, val)
|
100
135
|
else
|
101
|
-
|
102
|
-
evaluate_nested_conditions(association, association_field, val)
|
103
|
-
else
|
104
|
-
association.send(association_field) == val
|
105
|
-
end
|
136
|
+
association.send(association_field) == val
|
106
137
|
end
|
107
138
|
end
|
108
139
|
end
|
@@ -146,6 +177,14 @@ module PassiveRecord
|
|
146
177
|
def all
|
147
178
|
@first_query.all & @second_query.all
|
148
179
|
end
|
180
|
+
|
181
|
+
def where(new_conditions={})
|
182
|
+
@first_query.where(new_conditions)
|
183
|
+
end
|
184
|
+
|
185
|
+
def conjoined?
|
186
|
+
true
|
187
|
+
end
|
149
188
|
end
|
150
189
|
end
|
151
190
|
end
|
data/notes.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
(channel spec) (stream spec)
|
2
|
+
|
3
|
+
Stream -> [parent]
|
4
|
+
Channel -> [from parent model] [intermed]
|
5
|
+
Feed -> [intermediary relation] [from nested...]
|
6
|
+
(*) Blog -> [ from nested assn...? ]
|
7
|
+
Post
|
8
|
+
|
9
|
+
we need a process that starts the other way, and 'completes' the through
|
10
|
+
like a belongs_to :through ... ?
|
11
|
+
|
12
|
+
for stream spec:
|
13
|
+
|
14
|
+
- nested assn is (channel has_many posts through feeds)
|
15
|
+
if we could get at (feed has_many posts through blogs)
|
16
|
+
i think we could recurse?
|
17
|
+
note: it should be the 'nested assn' for (channels has_many posts)...
|
18
|
+
|
19
|
+
- intermediray relation is (stream has many channels...) # through
|
20
|
+
can we get at channels has many posts?
|
21
|
+
|
22
|
+
in this context Channel is
|
23
|
+
|
24
|
+
`intermediary_relation.child_class_name.to_s.singularize.constantize' [ ugh! ]
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
Post.where(blog_id: 1)
|
30
|
+
|
31
|
+
Post.where(blog: { feed_id: 234 })
|
32
|
+
|
33
|
+
Post.where(blog: { feed: { channel_id: 567 }})
|
34
|
+
|
35
|
+
Post.where(blog: { feed: { channel: { stream: 890 }}})
|
36
|
+
|
37
|
+
|
38
|
+
# network.posts.recent
|
39
|
+
|
40
|
+
Post.where(published_at: 1.day.ago...Time.now, blog: { feed: { channel: { stream: { network_id: 1234 }}}})
|
41
|
+
|
42
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: passive_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Weissman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -131,6 +131,7 @@ extra_rdoc_files:
|
|
131
131
|
- ChangeLog.md
|
132
132
|
- LICENSE.txt
|
133
133
|
- README.md
|
134
|
+
- notes.md
|
134
135
|
files:
|
135
136
|
- ".document"
|
136
137
|
- ".gitignore"
|
@@ -162,6 +163,7 @@ files:
|
|
162
163
|
- lib/passive_record/pretty_printing.rb
|
163
164
|
- lib/passive_record/version.rb
|
164
165
|
- logo.png
|
166
|
+
- notes.md
|
165
167
|
- passive_record.gemspec
|
166
168
|
- spec/passive_record_spec.rb
|
167
169
|
- spec/spec_helper.rb
|