hstore_accessor 0.5.6 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hstore_accessor/macro.rb +4 -2
- data/lib/hstore_accessor/version.rb +1 -1
- data/spec/hstore_accessor_spec.rb +36 -1
- 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: 2b47e3c21fb0e55a817beb1ee28a8054673d493f
|
4
|
+
data.tar.gz: cb8ed732ecb17fcfbf59019a979ec31bf66a2b5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bba53b175d4e96b1ddf78df7b1fb72cf2dc41e7c2f723a0e222e1927e0564cdf0678b14ff7ef9a68f6a7d4abe71f50be205b477f31fb85a694e6fac06756024f
|
7
|
+
data.tar.gz: 2cf9f0099ade2feb58e73d3bca95ac8731d22f8253127ca3fa5412c8019c9bcea6e67e908514d20e7d72f494f8f5efd279b65675673772a1d51201c01b377b16
|
@@ -4,6 +4,7 @@ module HstoreAccessor
|
|
4
4
|
module ClassMethods
|
5
5
|
|
6
6
|
def hstore_accessor(hstore_attribute, fields)
|
7
|
+
field_methods = Module.new
|
7
8
|
fields.each do |key, type|
|
8
9
|
|
9
10
|
data_type = type
|
@@ -22,12 +23,12 @@ module HstoreAccessor
|
|
22
23
|
fields
|
23
24
|
end
|
24
25
|
|
25
|
-
define_method
|
26
|
+
field_methods.send(:define_method, "#{key}=") do |value|
|
26
27
|
send("#{hstore_attribute}=", (send(hstore_attribute) || {}).merge(store_key.to_s => serialize(data_type, TypeHelpers.cast(type, value))))
|
27
28
|
send("#{hstore_attribute}_will_change!")
|
28
29
|
end
|
29
30
|
|
30
|
-
define_method
|
31
|
+
field_methods.send(:define_method, key) do
|
31
32
|
value = send(hstore_attribute) && send(hstore_attribute).with_indifferent_access[store_key.to_s]
|
32
33
|
deserialize(data_type, value)
|
33
34
|
end
|
@@ -66,6 +67,7 @@ module HstoreAccessor
|
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
70
|
+
include field_methods
|
69
71
|
end
|
70
72
|
|
71
73
|
end
|
@@ -429,10 +429,45 @@ describe HstoreAccessor do
|
|
429
429
|
expect(product.popular).to be_false
|
430
430
|
end
|
431
431
|
end
|
432
|
+
end
|
432
433
|
|
434
|
+
context "extended getters and setters" do
|
435
|
+
before do
|
436
|
+
class Product
|
437
|
+
alias_method :set_color, :color=
|
438
|
+
alias_method :get_color, :color
|
433
439
|
|
434
|
-
|
440
|
+
def color=(value)
|
441
|
+
super(value.upcase)
|
442
|
+
end
|
443
|
+
|
444
|
+
def color
|
445
|
+
super.downcase
|
446
|
+
end
|
447
|
+
end
|
448
|
+
end
|
449
|
+
|
450
|
+
after do
|
451
|
+
class Product
|
452
|
+
alias_method :color=, :set_color
|
453
|
+
alias_method :color, :get_color
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
context "setters" do
|
458
|
+
it "can be wrapped" do
|
459
|
+
product.color = "red"
|
460
|
+
expect(product.options["color"]).to eq("RED")
|
461
|
+
end
|
462
|
+
end
|
435
463
|
|
464
|
+
context "getters" do
|
465
|
+
it "can be wrapped" do
|
466
|
+
product.color = "GREEN"
|
467
|
+
expect(product.color).to eq("green")
|
468
|
+
end
|
469
|
+
end
|
470
|
+
end
|
436
471
|
end
|
437
472
|
|
438
473
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hstore_accessor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Hirn
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-04-
|
13
|
+
date: 2014-04-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|