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 +15 -2
- data/Rakefile +1 -1
- data/lib/piggyback.rb +11 -6
- data/piggyback.gemspec +1 -1
- data/spec/piggyback_spec.rb +13 -0
- metadata +1 -1
data/CHANGELOG
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
-
|
1
|
+
= 0.2.1 / 2011-03-21
|
2
2
|
|
3
|
-
|
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.
|
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
|
91
|
-
|
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
|
-
|
105
|
-
|
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
data/spec/piggyback_spec.rb
CHANGED
@@ -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
|