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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ca96bb424702503964607990ceaf8bd1f1d295d
4
- data.tar.gz: a58a689b2bd09f47717d03f46eb159642c9ed585
3
+ metadata.gz: b0b1ecc13bba58282485955da6aeb21a51273498
4
+ data.tar.gz: ebfb6b3d4ce705e8e7cc3252c5ec08481511e1a5
5
5
  SHA512:
6
- metadata.gz: d28daa53d39118043b48317fa1528a858f4879700314f1409c3c85be2e5d75da596d68c6ff82c0c215b7ef98754861f8c35707a6398addefa35a458f856007d4
7
- data.tar.gz: 809f23544abba7769655652fe364e58a1d697133ffebf721a813b8301526b4edb624121f25e9d4f91f634413f42f0d34a7b84d8f2e00981a1cb873b55d45a13b
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(opts = :chain)
83
+ def order_with_dynamic_columns(*args)
84
84
  # Chain - by_dynamic_columns
85
- if opts == :chain
85
+ if args.empty?
86
86
  ::ActiveRecord::QueryMethods::OrderChain.new(clone)
87
87
  else
88
- order_without_dynamic_columns(opts)
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(opts = :chain)
57
+ def order_with_dynamic_columns(*args)
58
58
  # Chain - by_dynamic_columns
59
- if opts == :chain
59
+ if args.empty?
60
60
  ::ActiveRecord::QueryMethods::OrderChain.new(spawn)
61
61
  else
62
- order_without_dynamic_columns(opts)
62
+ order_without_dynamic_columns(*args)
63
63
  end
64
64
  end
65
65
  end
@@ -1,5 +1,5 @@
1
1
  module HasDynamicColumns
2
2
  class DynamicColumnBooleanDatum < ::ActiveRecord::Base
3
- belongs_to :dynamic_column_datum, :class_name => "HasDynamicColumns::DynamicColumnDatum"
3
+ has_one :dynamic_column_datum, :as => :datum
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module HasDynamicColumns
2
2
  class DynamicColumnDateDatum < ::ActiveRecord::Base
3
- belongs_to :dynamic_column_datum, :class_name => "HasDynamicColumns::DynamicColumnDatum"
3
+ has_one :dynamic_column_datum, :as => :datum
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module HasDynamicColumns
2
2
  class DynamicColumnDatetimeDatum < ::ActiveRecord::Base
3
- belongs_to :dynamic_column_datum, :class_name => "HasDynamicColumns::DynamicColumnDatum"
3
+ has_one :dynamic_column_datum, :as => :datum
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module HasDynamicColumns
2
2
  class DynamicColumnEnumDatum < ::ActiveRecord::Base
3
- belongs_to :dynamic_column_datum, :class_name => "HasDynamicColumns::DynamicColumnDatum"
3
+ has_one :dynamic_column_datum, :as => :datum
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module HasDynamicColumns
2
2
  class DynamicColumnFloatDatum < ::ActiveRecord::Base
3
- belongs_to :dynamic_column_datum, :class_name => "HasDynamicColumns::DynamicColumnDatum"
3
+ has_one :dynamic_column_datum, :as => :datum
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module HasDynamicColumns
2
2
  class DynamicColumnIntegerDatum < ::ActiveRecord::Base
3
- belongs_to :dynamic_column_datum, :class_name => "HasDynamicColumns::DynamicColumnDatum"
3
+ has_one :dynamic_column_datum, :as => :datum
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
1
  module HasDynamicColumns
2
2
  class DynamicColumnModelDatum < ::ActiveRecord::Base
3
- belongs_to :dynamic_column_datum, :class_name => "HasDynamicColumns::DynamicColumnDatum"
3
+ has_one :dynamic_column_datum, :as => :datum
4
4
  belongs_to :value, :polymorphic => true
5
5
  end
6
6
  end
@@ -1,5 +1,5 @@
1
1
  module HasDynamicColumns
2
2
  class DynamicColumnStringDatum < ::ActiveRecord::Base
3
- belongs_to :dynamic_column_datum, :class_name => "HasDynamicColumns::DynamicColumnDatum"
3
+ has_one :dynamic_column_datum, :as => :datum
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module HasDynamicColumns
2
2
  class DynamicColumnTextDatum < ::ActiveRecord::Base
3
- belongs_to :dynamic_column_datum, :class_name => "HasDynamicColumns::DynamicColumnDatum"
3
+ has_one :dynamic_column_datum, :as => :datum
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module HasDynamicColumns
2
2
  class DynamicColumnTimeDatum < ::ActiveRecord::Base
3
- belongs_to :dynamic_column_datum, :class_name => "HasDynamicColumns::DynamicColumnDatum"
3
+ has_one :dynamic_column_datum, :as => :datum
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module HasDynamicColumns
2
2
  class DynamicColumnTimestampDatum < ::ActiveRecord::Base
3
- belongs_to :dynamic_column_datum, :class_name => "HasDynamicColumns::DynamicColumnDatum"
3
+ has_one :dynamic_column_datum, :as => :datum
4
4
  end
5
5
  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
@@ -1,3 +1,3 @@
1
1
  module HasDynamicColumns
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.8"
3
3
  end
@@ -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"]["name"]).to eq("1796 18th St, San Francisco, CA 94107, United States")
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["name"]).to eq("P#{index+1}")
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"]["name"]).to eq("1600 Amphitheatre Pkwy, Mountain View, CA 94043, United States")
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.6
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-13 00:00:00.000000000 Z
11
+ date: 2015-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord