has_dynamic_columns 0.3.6 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/has_dynamic_columns/active_record/v3/query_methods.rb +3 -3
- data/lib/has_dynamic_columns/active_record/v4/query_methods.rb +3 -3
- data/lib/has_dynamic_columns/dynamic_column_boolean_datum.rb +1 -1
- data/lib/has_dynamic_columns/dynamic_column_date_datum.rb +1 -1
- data/lib/has_dynamic_columns/dynamic_column_datetime_datum.rb +1 -1
- data/lib/has_dynamic_columns/dynamic_column_enum_datum.rb +1 -1
- data/lib/has_dynamic_columns/dynamic_column_float_datum.rb +1 -1
- data/lib/has_dynamic_columns/dynamic_column_integer_datum.rb +1 -1
- data/lib/has_dynamic_columns/dynamic_column_model_datum.rb +1 -1
- data/lib/has_dynamic_columns/dynamic_column_string_datum.rb +1 -1
- data/lib/has_dynamic_columns/dynamic_column_text_datum.rb +1 -1
- data/lib/has_dynamic_columns/dynamic_column_time_datum.rb +1 -1
- data/lib/has_dynamic_columns/dynamic_column_timestamp_datum.rb +1 -1
- data/lib/has_dynamic_columns/model/class_methods.rb +3 -0
- data/lib/has_dynamic_columns/version.rb +1 -1
- data/spec/factories/account.rb +1 -1
- data/spec/has_dynamic_columns/dynamic_columns_model_datum_spec.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0b1ecc13bba58282485955da6aeb21a51273498
|
4
|
+
data.tar.gz: ebfb6b3d4ce705e8e7cc3252c5ec08481511e1a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db67f6150244898ad99a6ed6b92fe48a8f39e9a66b7073dfda0ec4083430f4f06cd57353f8e6dc1e1bc4ed908f15ef9b629076ab61aa3b3c41eb9bad5647880d
|
7
|
+
data.tar.gz: 3f484bdd7d0d1964630f5c646607380475f74aeffd622527ee426c0ddf3db0598baf92e4ee6b45e13dfcbe0446ae84942506f5245eb69a5d4625234a34e78ba4
|
@@ -80,12 +80,12 @@ module HasDynamicColumns
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
def order_with_dynamic_columns(
|
83
|
+
def order_with_dynamic_columns(*args)
|
84
84
|
# Chain - by_dynamic_columns
|
85
|
-
if
|
85
|
+
if args.empty?
|
86
86
|
::ActiveRecord::QueryMethods::OrderChain.new(clone)
|
87
87
|
else
|
88
|
-
order_without_dynamic_columns(
|
88
|
+
order_without_dynamic_columns(*args)
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
@@ -54,12 +54,12 @@ module HasDynamicColumns
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
def order_with_dynamic_columns(
|
57
|
+
def order_with_dynamic_columns(*args)
|
58
58
|
# Chain - by_dynamic_columns
|
59
|
-
if
|
59
|
+
if args.empty?
|
60
60
|
::ActiveRecord::QueryMethods::OrderChain.new(spawn)
|
61
61
|
else
|
62
|
-
order_without_dynamic_columns(
|
62
|
+
order_without_dynamic_columns(*args)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module HasDynamicColumns
|
2
2
|
class DynamicColumnModelDatum < ::ActiveRecord::Base
|
3
|
-
|
3
|
+
has_one :dynamic_column_datum, :as => :datum
|
4
4
|
belongs_to :value, :polymorphic => true
|
5
5
|
end
|
6
6
|
end
|
@@ -285,6 +285,9 @@ module HasDynamicColumns
|
|
285
285
|
v = i.value
|
286
286
|
v = v.as_json(:root => nil) if as_json && v.respond_to?(:as_json)
|
287
287
|
|
288
|
+
# If a specific column is used, use it in the as_json method
|
289
|
+
v = v[i.dynamic_column.column_name] if as_json && v && v.is_a?(Hash) && !i.dynamic_column.column_name.to_s.empty?
|
290
|
+
|
288
291
|
if i.dynamic_column.multiple
|
289
292
|
h[i.dynamic_column.key] << v
|
290
293
|
else
|
data/spec/factories/account.rb
CHANGED
@@ -14,7 +14,7 @@ FactoryGirl.define do
|
|
14
14
|
account.activerecord_dynamic_columns.build(:dynamic_type => "Customer", :key => "total_purchases", :data_type => "integer")
|
15
15
|
account.activerecord_dynamic_columns.build(:dynamic_type => "Customer", :key => "tags", :data_type => "string", :multiple => true)
|
16
16
|
account.activerecord_dynamic_columns.build(:dynamic_type => "Customer", :key => "address", :data_type => "model", :class_name => "CustomerAddress", :column_name => "name")
|
17
|
-
account.activerecord_dynamic_columns.build(:dynamic_type => "Customer", :key => "products", :data_type => "model", :multiple => true)
|
17
|
+
account.activerecord_dynamic_columns.build(:dynamic_type => "Customer", :key => "products", :data_type => "model", :class_name => "Product", :column_name => "name", :multiple => true)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -25,11 +25,11 @@ describe HasDynamicColumns::DynamicColumnModelDatum do
|
|
25
25
|
customer.save
|
26
26
|
json = customer.as_json(:root => nil)
|
27
27
|
|
28
|
-
expect(json["fields"]["address"]
|
28
|
+
expect(json["fields"]["address"]).to eq("1796 18th St, San Francisco, CA 94107, United States")
|
29
29
|
expect(json["fields"]["products"].length).to eq(5)
|
30
30
|
# Each of the products should be json
|
31
31
|
json["fields"]["products"].each_with_index { |i, index|
|
32
|
-
expect(i
|
32
|
+
expect(i).to eq("P#{index+1}")
|
33
33
|
}
|
34
34
|
end
|
35
35
|
|
@@ -112,7 +112,7 @@ describe HasDynamicColumns::DynamicColumnModelDatum do
|
|
112
112
|
)
|
113
113
|
.with_scope(account)
|
114
114
|
expect(result.length).to eq(2)
|
115
|
-
expect(result.first.as_json["fields"]["address"]
|
115
|
+
expect(result.first.as_json["fields"]["address"]).to eq("1600 Amphitheatre Pkwy, Mountain View, CA 94043, United States")
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_dynamic_columns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Butch Marshall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|