denormalizer 0.0.2 → 0.0.3

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.
data/CHANGELOG CHANGED
@@ -1,5 +1,10 @@
1
1
  == unreleased changes
2
2
 
3
+ == 0.0.3
4
+
5
+ * Updated the generated scopes so that they are chainable with each other. Rails
6
+ has issues when you try to join to the same table twice.
7
+
3
8
  == 0.0.2
4
9
 
5
10
  * Added basic testing for the mixins
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
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.2"
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-07-13"
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
- "denormalizer_method_outputs.denormalized_object_method" => method_name.to_s,
36
- "denormalizer_method_outputs.method_output" => Denormalizer::MethodOutput::TrueOutput
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(:denormalized_method_outputs).where(true_attributes)}
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
- "denormalizer_method_outputs.denormalized_object_method" => method_name.to_s,
44
- "denormalizer_method_outputs.method_output" => Denormalizer::MethodOutput::FalseOutput
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(:denormalized_method_outputs).where(false_attributes)}
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 \"denormalizer_method_outputs\" ON \"denormalizer_method_outputs\".\"denormalized_object_id\" = \"books\".\"id\" AND \"denormalizer_method_outputs\".\"denormalized_object_type\" = 'Book'"
36
- sql.should match "WHERE \"denormalizer_method_outputs\".\"denormalized_object_method\" = 'short_name.' AND \"denormalizer_method_outputs\".\"method_output\" = 1"
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 \"denormalizer_method_outputs\" ON \"denormalizer_method_outputs\".\"denormalized_object_id\" = \"books\".\"id\" AND \"denormalizer_method_outputs\".\"denormalized_object_type\" = 'Book'"
44
- sql.should match "WHERE \"denormalizer_method_outputs\".\"denormalized_object_method\" = 'short_name.' AND \"denormalizer_method_outputs\".\"method_output\" = 0"
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.2
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-07-13 00:00:00 Z
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: 3695816084296706715
210
+ hash: -921716589672485106
211
211
  segments:
212
212
  - 0
213
213
  version: "0"