hstore_attributes 1.0.3 → 1.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c988492ec880d5015b35286f22bcc8f44e3aa93
4
- data.tar.gz: 1aa4e76b7aa66df79312ebd98bd7114a5b88f498
3
+ metadata.gz: 96d23483429660646d51455c55999ffb42bc10ff
4
+ data.tar.gz: 2dd231a0ce61ffd5252dc5063b0d13509884a712
5
5
  SHA512:
6
- metadata.gz: 9b87a4d3c5d8b317621f86c00ba9aa222535fef543234dbce30705c95e9f4d7fab6d8dc8712bb9fd1e7d51d6cdcb1707cfdc6bd750d56c6a0db17f3e39eb25f7
7
- data.tar.gz: 3f2273b97a4dd116192a60d9865667bd36dbd17b0b296e341fc2952a6477bc999f65d5322151ce601dfd7e82ce099abe7c6ca61dfcdba2f5ff7643b768dcc13d
6
+ metadata.gz: 48cb4ca45649a695454e1cf77d4502d1ad5c5c2a32b344c694e01ea716da7051428e313f47ea1596411a483c29e82c680a232ff1dde83032cdc89c6972156cc3
7
+ data.tar.gz: 0bead8530fd7f87055ed0e7a2b9f9c7241a3d089bac8e9ddf7c35aadd4748ff778b29a11a3be346c6f8b57582709fbe54f5495a54d13fc47eb17dffaa54cff4b
@@ -11,10 +11,17 @@ module HstoreAttributes
11
11
  end
12
12
  end
13
13
 
14
+ def self.attribute_name(name, options)
15
+ prefix = options[:prefix]
16
+ suffix = options[:suffix]
17
+ [prefix, name, suffix].compact.join("_")
18
+ end
19
+
14
20
  def hstore_reader(hstore, *attributes)
15
21
  options = attributes.extract_options!
16
22
  attributes.map(&:to_s).each do |attribute|
17
- define_method(attribute) do
23
+ attribute_name = HstoreAttributes.attribute_name(attribute, options)
24
+ define_method(attribute_name) do
18
25
  value = (send(hstore) || {})[attribute]
19
26
  HstoreAttributes.convert(value, options)
20
27
  end
@@ -24,7 +31,8 @@ module HstoreAttributes
24
31
  def hstore_writer(hstore, *attributes)
25
32
  options = attributes.extract_options!
26
33
  attributes.map(&:to_s).each do |attribute|
27
- define_method("#{attribute}=") do |value|
34
+ attribute_name = HstoreAttributes.attribute_name(attribute, options)
35
+ define_method("#{attribute_name}=") do |value|
28
36
  value = HstoreAttributes.convert(value, options)
29
37
  send("#{hstore}=", (send(hstore) || {}).merge(attribute => value))
30
38
  end
@@ -1,3 +1,3 @@
1
1
  module HstoreAttributes
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -5,6 +5,9 @@ class Product
5
5
  extend HstoreAttributes
6
6
 
7
7
  hstore_accessor :data, :name, :description, type_cast: ->(value) { value.to_s.upcase }
8
+ hstore_accessor :data, :name, prefix: :prefixed
9
+ hstore_accessor :data, :name, suffix: :suffixed
10
+ hstore_accessor :data, :name, prefix: :pre, suffix: :suf
8
11
  end
9
12
 
10
13
  describe "hstore_writer" do
@@ -21,4 +24,19 @@ describe "hstore_writer" do
21
24
  @product.description = "trolololo"
22
25
  assert_equal "TROLOLOLO", @product.description
23
26
  end
27
+
28
+ it "allows to prefix accessor methods" do
29
+ @product.prefixed_name = "zomg"
30
+ assert_equal "zomg", @product.prefixed_name
31
+ end
32
+
33
+ it "allows to suffix accessor methods" do
34
+ @product.name_suffixed = "zomg"
35
+ assert_equal "zomg", @product.name_suffixed
36
+ end
37
+
38
+ it "allows to prefix and suffix accessor methods at once" do
39
+ @product.pre_name_suf = "zomg"
40
+ assert_equal "zomg", @product.pre_name_suf
41
+ end
24
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hstore_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kuba Kuźma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-28 00:00:00.000000000 Z
11
+ date: 2013-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  version: '0'
93
93
  requirements: []
94
94
  rubyforge_project:
95
- rubygems_version: 2.0.2
95
+ rubygems_version: 2.0.3
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: Easy accessors for Hstore data.