denormalizer 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/VERSION +1 -1
- data/denormalizer.gemspec +2 -2
- data/lib/denormalizer/denormalize.rb +11 -6
- data/spec/method_denormalization_spec.rb +4 -4
- metadata +3 -3
data/CHANGELOG
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/denormalizer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "denormalizer"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
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 = "2012-
|
12
|
+
s.date = "2012-12-03"
|
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 = [
|
@@ -29,22 +29,27 @@ module Denormalizer
|
|
29
29
|
# create scopes
|
30
30
|
# note that at some point, we probably need to identify these as denormalized scopes (JH 7-5-2012)
|
31
31
|
# dn_method_name maybe
|
32
|
+
#
|
33
|
+
# Table aliases have been added so that denormalized scopes can be chained (JH 12-3-2012)
|
34
|
+
# Note that you can chain a method with it's false version
|
32
35
|
args.each do |method_name|
|
36
|
+
table_alias = "dnmos_#{table_name}_#{self.denormalized_methods.size - 1}"
|
33
37
|
# setup true scope
|
34
38
|
true_attributes = {
|
35
|
-
"
|
36
|
-
"
|
39
|
+
"#{table_alias}.denormalized_object_method" => method_name.to_s,
|
40
|
+
"#{table_alias}.method_output" => Denormalizer::MethodOutput::TrueOutput
|
37
41
|
}
|
38
42
|
true_scope_name = "denormalized_#{method_name.to_s.gsub('?', '')}".pluralize.to_sym
|
39
|
-
scope true_scope_name, lambda { joins(
|
43
|
+
scope true_scope_name, lambda { joins("INNER JOIN denormalizer_method_outputs AS #{table_alias} on #{table_alias}.denormalized_object_type='#{to_s}' AND #{table_alias}.denormalized_object_id=#{table_name}.id").where(true_attributes)}
|
40
44
|
|
41
45
|
# setup false scope
|
46
|
+
# the false query uses the same table alias
|
42
47
|
false_attributes = {
|
43
|
-
"
|
44
|
-
"
|
48
|
+
"#{table_alias}.denormalized_object_method" => method_name.to_s,
|
49
|
+
"#{table_alias}.method_output" => Denormalizer::MethodOutput::FalseOutput
|
45
50
|
}
|
46
51
|
false_scope_name = "denormalized_not_#{method_name.to_s.gsub('?', '')}".pluralize.to_sym
|
47
|
-
scope false_scope_name, lambda { joins(
|
52
|
+
scope false_scope_name, lambda { joins("INNER JOIN denormalizer_method_outputs AS #{table_alias} on #{table_alias}.denormalized_object_type='#{to_s}' AND #{table_alias}.denormalized_object_id=#{table_name}.id").where(false_attributes)}
|
48
53
|
|
49
54
|
instance_method_name = "denormalized_#{method_name.to_s}"
|
50
55
|
define_method instance_method_name do
|
@@ -32,16 +32,16 @@ describe "method denormalization" do
|
|
32
32
|
describe "denormalized_short_names" do
|
33
33
|
it "should match this sql" do
|
34
34
|
sql = Book.denormalized_short_names.to_sql
|
35
|
-
sql.should match "INNER JOIN
|
36
|
-
sql.should match "WHERE \"
|
35
|
+
sql.should match "INNER JOIN denormalizer_method_outputs AS dnmos_books_0 on dnmos_books_0.denormalized_object_type='Book' AND dnmos_books_0.denormalized_object_id=books.id"
|
36
|
+
sql.should match "WHERE \"dnmos_books_0\".\"denormalized_object_method\" = 'short_name.' AND \"dnmos_books_0\".\"method_output\" = 1"
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
describe "denormalized_not_short_names" do
|
41
41
|
it "should match this sql" do
|
42
42
|
sql = Book.denormalized_not_short_names.to_sql
|
43
|
-
sql.should match "INNER JOIN
|
44
|
-
sql.should match "WHERE \"
|
43
|
+
sql.should match "INNER JOIN denormalizer_method_outputs AS dnmos_books_0 on dnmos_books_0.denormalized_object_type='Book' AND dnmos_books_0.denormalized_object_id=books.id"
|
44
|
+
sql.should match "WHERE \"dnmos_books_0\".\"denormalized_object_method\" = 'short_name.' AND \"dnmos_books_0\".\"method_output\" = 0"
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: denormalizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jeremiah Hemphill
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-12-03 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -207,7 +207,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
207
207
|
requirements:
|
208
208
|
- - ">="
|
209
209
|
- !ruby/object:Gem::Version
|
210
|
-
hash:
|
210
|
+
hash: -921716589672485106
|
211
211
|
segments:
|
212
212
|
- 0
|
213
213
|
version: "0"
|