piggyback 0.2.0 → 0.2.1

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,3 +1,16 @@
1
- v0.2 Leaner codebase by taking better advantage of AR-ecosystem. Improved specs.
1
+ = 0.2.1 / 2011-03-21
2
2
 
3
- v0.1 Initial version
3
+ * Added `piggyback_sql` method for getting the SQL generated for the SELECT
4
+ statement. This can be used for GROUP_BY clauses in standards compliant
5
+ databases, such as PostgreSQL.
6
+
7
+ = 0.2.0 / 2011-03-21
8
+
9
+ * Leaner codebase by taking better advantage of ActiveRecord attribute
10
+ method generation.
11
+
12
+ * Improved specs.
13
+
14
+ = 0.1.0 / 2011-03-20
15
+
16
+ Initial release
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rake'
2
2
  require 'echoe'
3
3
 
4
- Echoe.new('piggyback', '0.2.0') do |p|
4
+ Echoe.new('piggyback', '0.2.1') do |p|
5
5
  p.description = "Piggyback attributes from associated models with ActiveRecord"
6
6
  p.url = "http://github.com/juni0r/piggyback"
7
7
  p.author = "Andreas Korth"
data/lib/piggyback.rb CHANGED
@@ -86,9 +86,10 @@ module Piggyback
86
86
  end
87
87
  end
88
88
  end
89
-
90
- def piggyback(*associations)
91
- columns = piggyback_associations.values_at(*associations).map do |association|
89
+
90
+ def piggyback_select(*assoc_names)
91
+ assoc_names.map do |assoc_name|
92
+ association = piggyback_associations[assoc_name]
92
93
  association.map do |attr_name, mapped_name|
93
94
  if attr_name != mapped_name
94
95
  if mapped_name.is_a? Arel::Nodes::SqlLiteral
@@ -100,9 +101,13 @@ module Piggyback
100
101
  "#{association.quoted_table_name}.#{connection.quote_column_name(attr_name)}"
101
102
  end
102
103
  end
103
- end
104
- columns.unshift("#{quoted_table_name}.*") unless scoped.select_values.any?
105
- select(columns.flatten.join(', ')).joins(*associations)
104
+ end.flatten.join(', ')
105
+ end
106
+
107
+ def piggyback(*assoc_names)
108
+ selection = piggyback_select(*assoc_names)
109
+ selection = "#{quoted_table_name}.*, #{selection}" unless scoped.select_values.any?
110
+ select(selection).joins(*assoc_names)
106
111
  end
107
112
  end
108
113
  end
data/piggyback.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{piggyback}
5
- s.version = "0.2.0"
5
+ s.version = "0.2.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Andreas Korth"]
@@ -74,4 +74,17 @@ describe Piggyback do
74
74
  essential.name.should eql("John Doe")
75
75
  end
76
76
  end
77
+
78
+ it "should generate SQL for selecting piggybacked attributes" do
79
+ Essential.piggyback_select(:detail).split(', ').should =~ [
80
+ %("details"."first_name"),
81
+ %("details"."last_name"),
82
+ %("details"."count"),
83
+ %("details"."checked"),
84
+ %("details"."birthday"),
85
+ %("details"."baggage"),
86
+ %(details.first_name || ' ' || details.last_name AS name),
87
+ %("details"."updated_at" AS detail_updated_at)
88
+ ]
89
+ end
77
90
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: piggyback
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Andreas Korth