denormalizer 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +2 -2
- data/VERSION +1 -1
- data/app/models/denormalizer/method_output.rb +2 -2
- data/denormalizer.gemspec +4 -4
- data/lib/denormalizer/denormalize.rb +11 -5
- data/spec/dummy/app/models/book.rb +1 -2
- data/spec/dummy/app/models/printing.rb +1 -1
- metadata +135 -90
data/Gemfile.lock
CHANGED
@@ -90,7 +90,7 @@ GEM
|
|
90
90
|
rack-ssl (~> 1.3.2)
|
91
91
|
rake (>= 0.8.7)
|
92
92
|
rdoc (~> 3.4)
|
93
|
-
thor (
|
93
|
+
thor (>= 0.14.6, < 2.0)
|
94
94
|
rake (0.9.2.2)
|
95
95
|
rdoc (3.12)
|
96
96
|
json (~> 1.4)
|
@@ -126,7 +126,7 @@ GEM
|
|
126
126
|
sprockets (2.1.3)
|
127
127
|
hike (~> 1.2)
|
128
128
|
rack (~> 1.0)
|
129
|
-
tilt (
|
129
|
+
tilt (~> 1.1, != 1.3.0)
|
130
130
|
sqlite3 (1.3.6)
|
131
131
|
thor (0.15.4)
|
132
132
|
tilt (1.3.3)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
@@ -7,9 +7,9 @@ class Denormalizer::MethodOutput < ActiveRecord::Base
|
|
7
7
|
FalseOutput = 0
|
8
8
|
TrueOutput = 1
|
9
9
|
|
10
|
-
def self.by_object_and_method_name(obj, method_name)
|
10
|
+
def self.by_object_and_method_name(obj, method_name, class_name)
|
11
11
|
attributes = {
|
12
|
-
:denormalized_object_type =>
|
12
|
+
:denormalized_object_type => class_name,
|
13
13
|
:denormalized_object_id => obj.id,
|
14
14
|
:denormalized_object_method => method_name
|
15
15
|
}
|
data/denormalizer.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in
|
3
|
+
# Instead, edit Jeweler::Tasks in rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "denormalizer"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jeremiah Hemphill"]
|
12
|
-
s.date = "
|
12
|
+
s.date = "2013-08-02"
|
13
13
|
s.description = "Cache method outputs and automatically create chainable scopes based on their outputs"
|
14
14
|
s.email = "jeremiah@cloudspace.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -83,7 +83,7 @@ Gem::Specification.new do |s|
|
|
83
83
|
s.homepage = "http://github.com/jeremiahishere/denormalizer"
|
84
84
|
s.licenses = ["MIT"]
|
85
85
|
s.require_paths = ["lib"]
|
86
|
-
s.rubygems_version = "1.8.
|
86
|
+
s.rubygems_version = "1.8.25"
|
87
87
|
s.summary = "Cache method outputs"
|
88
88
|
|
89
89
|
if s.respond_to? :specification_version then
|
@@ -14,11 +14,13 @@ module Denormalizer
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def denormalize(args)
|
17
|
+
def denormalize(args, options = {} )
|
18
18
|
# setup list of denormalized methods
|
19
19
|
mattr_accessor :denormalized_methods unless respond_to? :denormalized_methods
|
20
20
|
self.denormalized_methods = [] unless self.denormalized_methods.is_a?(Array)
|
21
21
|
|
22
|
+
mattr_accessor :denormalization_class unless respond_to? :denormalization_class
|
23
|
+
|
22
24
|
# add association
|
23
25
|
has_many :denormalized_method_outputs, :class_name => 'Denormalizer::MethodOutput', :as => :denormalized_object, :dependent => :destroy
|
24
26
|
|
@@ -26,6 +28,9 @@ module Denormalizer
|
|
26
28
|
args = [args] unless args.is_a?(Array)
|
27
29
|
self.denormalized_methods |= args
|
28
30
|
|
31
|
+
# setting class name if one is passed in, otherwise use class of model with mixin (AU 8-1-13)
|
32
|
+
self.denormalization_class = options.has_key?(:class_name) ? options[:class_name] : self.to_s
|
33
|
+
|
29
34
|
# create scopes
|
30
35
|
# note that at some point, we probably need to identify these as denormalized scopes (JH 7-5-2012)
|
31
36
|
# dn_method_name maybe
|
@@ -33,6 +38,7 @@ module Denormalizer
|
|
33
38
|
# Table aliases have been added so that denormalized scopes can be chained (JH 12-3-2012)
|
34
39
|
# Note that you can chain a method with it's false version
|
35
40
|
args.each do |method_name|
|
41
|
+
# table_name is called on the model of the mixin
|
36
42
|
table_alias = "dnmos_#{table_name}_#{self.denormalized_methods.size - 1}"
|
37
43
|
# setup true scope
|
38
44
|
true_attributes = {
|
@@ -40,7 +46,7 @@ module Denormalizer
|
|
40
46
|
"#{table_alias}.method_output" => Denormalizer::MethodOutput::TrueOutput
|
41
47
|
}
|
42
48
|
true_scope_name = "denormalized_#{method_name.to_s.gsub('?', '')}".pluralize.to_sym
|
43
|
-
scope true_scope_name, lambda { joins("INNER JOIN denormalizer_method_outputs AS #{table_alias} on #{table_alias}.denormalized_object_type='#{
|
49
|
+
scope true_scope_name, lambda { joins("INNER JOIN denormalizer_method_outputs AS #{table_alias} on #{table_alias}.denormalized_object_type='#{denormalization_class}' AND #{table_alias}.denormalized_object_id=#{table_name}.id").where(true_attributes)}
|
44
50
|
|
45
51
|
# setup false scope
|
46
52
|
# the false query uses the same table alias
|
@@ -53,7 +59,7 @@ module Denormalizer
|
|
53
59
|
|
54
60
|
instance_method_name = "denormalized_#{method_name.to_s}"
|
55
61
|
define_method instance_method_name do
|
56
|
-
saved_output = Denormalizer::MethodOutput.by_object_and_method_name(self, method_name).first
|
62
|
+
saved_output = Denormalizer::MethodOutput.by_object_and_method_name(self, method_name, self.denormalization_class).first
|
57
63
|
return saved_output.method_output == Denormalizer::MethodOutput::TrueOutput
|
58
64
|
end
|
59
65
|
end
|
@@ -88,10 +94,10 @@ module Denormalizer
|
|
88
94
|
|
89
95
|
# find a match then create or update based on success
|
90
96
|
# TODO: refactor this entire section to metho on Denormalizer::MethodOutput (JH 7-13-2012)
|
91
|
-
saved_output = Denormalizer::MethodOutput.by_object_and_method_name(self, method_name).first
|
97
|
+
saved_output = Denormalizer::MethodOutput.by_object_and_method_name(self, method_name, self.denormalization_class).first
|
92
98
|
if saved_output.nil?
|
93
99
|
attributes = {
|
94
|
-
:denormalized_object_type => self.
|
100
|
+
:denormalized_object_type => self.denormalization_class,
|
95
101
|
:denormalized_object_id => self.id,
|
96
102
|
:denormalized_object_method => method_name,
|
97
103
|
:method_output => method_output
|
@@ -6,10 +6,9 @@ class Book < ActiveRecord::Base
|
|
6
6
|
def short_name?
|
7
7
|
name.length < 5
|
8
8
|
end
|
9
|
-
denormalize :short_name?
|
9
|
+
denormalize [:short_name?, :printed?], :class_name => "different 'class' name"
|
10
10
|
|
11
11
|
def printed?
|
12
12
|
!printings.empty?
|
13
13
|
end
|
14
|
-
denormalize :printed?
|
15
14
|
end
|
metadata
CHANGED
@@ -1,137 +1,185 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: denormalizer
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.3
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Jeremiah Hemphill
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-08-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: rails
|
17
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
|
-
requirements:
|
20
|
-
- -
|
21
|
-
- !ruby/object:Gem::Version
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
22
21
|
version: 3.0.0
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements:
|
26
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
27
31
|
name: capybara
|
28
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
29
33
|
none: false
|
30
|
-
requirements:
|
31
|
-
- -
|
32
|
-
- !ruby/object:Gem::Version
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
33
37
|
version: 0.4.0
|
34
38
|
type: :development
|
35
39
|
prerelease: false
|
36
|
-
version_requirements:
|
37
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.4.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
38
47
|
name: sqlite3
|
39
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
40
49
|
none: false
|
41
|
-
requirements:
|
42
|
-
- -
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
version:
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
45
54
|
type: :development
|
46
55
|
prerelease: false
|
47
|
-
version_requirements:
|
48
|
-
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
49
63
|
name: ruby-debug19
|
50
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
51
65
|
none: false
|
52
|
-
requirements:
|
53
|
-
- -
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version:
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
56
70
|
type: :development
|
57
71
|
prerelease: false
|
58
|
-
version_requirements:
|
59
|
-
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
60
79
|
name: rspec
|
61
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
62
81
|
none: false
|
63
|
-
requirements:
|
82
|
+
requirements:
|
64
83
|
- - ~>
|
65
|
-
- !ruby/object:Gem::Version
|
84
|
+
- !ruby/object:Gem::Version
|
66
85
|
version: 2.6.0
|
67
86
|
type: :development
|
68
87
|
prerelease: false
|
69
|
-
version_requirements:
|
70
|
-
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 2.6.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
71
95
|
name: rspec-rails
|
72
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
73
97
|
none: false
|
74
|
-
requirements:
|
98
|
+
requirements:
|
75
99
|
- - ~>
|
76
|
-
- !ruby/object:Gem::Version
|
100
|
+
- !ruby/object:Gem::Version
|
77
101
|
version: 2.6.1
|
78
102
|
type: :development
|
79
103
|
prerelease: false
|
80
|
-
version_requirements:
|
81
|
-
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 2.6.1
|
110
|
+
- !ruby/object:Gem::Dependency
|
82
111
|
name: yard
|
83
|
-
requirement:
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
84
113
|
none: false
|
85
|
-
requirements:
|
114
|
+
requirements:
|
86
115
|
- - ~>
|
87
|
-
- !ruby/object:Gem::Version
|
116
|
+
- !ruby/object:Gem::Version
|
88
117
|
version: 0.6.0
|
89
118
|
type: :development
|
90
119
|
prerelease: false
|
91
|
-
version_requirements:
|
92
|
-
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 0.6.0
|
126
|
+
- !ruby/object:Gem::Dependency
|
93
127
|
name: database_cleaner
|
94
|
-
requirement:
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
95
129
|
none: false
|
96
|
-
requirements:
|
97
|
-
- -
|
98
|
-
- !ruby/object:Gem::Version
|
99
|
-
version:
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
100
134
|
type: :development
|
101
135
|
prerelease: false
|
102
|
-
version_requirements:
|
103
|
-
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
104
143
|
name: jeweler
|
105
|
-
requirement:
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
106
145
|
none: false
|
107
|
-
requirements:
|
146
|
+
requirements:
|
108
147
|
- - ~>
|
109
|
-
- !ruby/object:Gem::Version
|
148
|
+
- !ruby/object:Gem::Version
|
110
149
|
version: 1.6.3
|
111
150
|
type: :development
|
112
151
|
prerelease: false
|
113
|
-
version_requirements:
|
114
|
-
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ~>
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: 1.6.3
|
158
|
+
- !ruby/object:Gem::Dependency
|
115
159
|
name: ci_reporter
|
116
|
-
requirement:
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
117
161
|
none: false
|
118
|
-
requirements:
|
119
|
-
- -
|
120
|
-
- !ruby/object:Gem::Version
|
121
|
-
version:
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
122
166
|
type: :development
|
123
167
|
prerelease: false
|
124
|
-
version_requirements:
|
125
|
-
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
description: Cache method outputs and automatically create chainable scopes based
|
175
|
+
on their outputs
|
126
176
|
email: jeremiah@cloudspace.com
|
127
177
|
executables: []
|
128
|
-
|
129
178
|
extensions: []
|
130
|
-
|
131
|
-
extra_rdoc_files:
|
179
|
+
extra_rdoc_files:
|
132
180
|
- LICENSE.txt
|
133
181
|
- README.rdoc
|
134
|
-
files:
|
182
|
+
files:
|
135
183
|
- .document
|
136
184
|
- .rspec
|
137
185
|
- CHANGELOG
|
@@ -195,34 +243,31 @@ files:
|
|
195
243
|
- spec/method_denormalization_spec.rb
|
196
244
|
- spec/spec_helper.rb
|
197
245
|
homepage: http://github.com/jeremiahishere/denormalizer
|
198
|
-
licenses:
|
246
|
+
licenses:
|
199
247
|
- MIT
|
200
248
|
post_install_message:
|
201
249
|
rdoc_options: []
|
202
|
-
|
203
|
-
require_paths:
|
250
|
+
require_paths:
|
204
251
|
- lib
|
205
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
252
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
206
253
|
none: false
|
207
|
-
requirements:
|
208
|
-
- -
|
209
|
-
- !ruby/object:Gem::Version
|
210
|
-
|
211
|
-
segments:
|
254
|
+
requirements:
|
255
|
+
- - ! '>='
|
256
|
+
- !ruby/object:Gem::Version
|
257
|
+
version: '0'
|
258
|
+
segments:
|
212
259
|
- 0
|
213
|
-
|
214
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
260
|
+
hash: -3214271311698412174
|
261
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
215
262
|
none: false
|
216
|
-
requirements:
|
217
|
-
- -
|
218
|
-
- !ruby/object:Gem::Version
|
219
|
-
version:
|
263
|
+
requirements:
|
264
|
+
- - ! '>='
|
265
|
+
- !ruby/object:Gem::Version
|
266
|
+
version: '0'
|
220
267
|
requirements: []
|
221
|
-
|
222
268
|
rubyforge_project:
|
223
|
-
rubygems_version: 1.8.
|
269
|
+
rubygems_version: 1.8.25
|
224
270
|
signing_key:
|
225
271
|
specification_version: 3
|
226
272
|
summary: Cache method outputs
|
227
273
|
test_files: []
|
228
|
-
|