dm-postgres-types 0.0.2 → 0.0.3

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: e639a4b51d8e2801528d28f361678a77cc22fddd
4
- data.tar.gz: 21859491842b616d4376b838f651e725e4c6eabd
3
+ metadata.gz: b34c0fed29d2734988332c1ebc2feb36b701c8a8
4
+ data.tar.gz: 2d43675b7212f143f7fdcc2ad8b5bef523b2eba2
5
5
  SHA512:
6
- metadata.gz: a8c61bb9da397af557b989cf16c8302949e2086fbf032b6efdacf6aaef3e331f75b52a583446a1d51ac267e2cceefceed293a9071a7b76898aa342fc0ec70668
7
- data.tar.gz: fbe056c6f2e989f8fe5d54b639063056fd0b19c7d9e403067ea0ca79115e78795110eab572eccbf5171b8758b971678f7b1f46a7e79c06b73742f5c9ae88dd48
6
+ metadata.gz: bb572e25a2ab66f534816d62717fdfa3d2e544e5274022fca8549170a0fbc98c0df8969106dafefc0b806af694116b1c596ff3215b753451c04e2c193001afbf
7
+ data.tar.gz: 0f7fe62848199365af2b9ce45f5028705715844573ea21365c587f56731f738b527ceafb41b4f7ef01a8faaf03148c0efcfeb45139a744568c1f186f32b3f14d
data/README.md CHANGED
@@ -39,7 +39,7 @@ m.elements
39
39
  # => ["abc", "def"]
40
40
  ````
41
41
 
42
- Use this property when you want to store an array of strings. This property dosn't have any options.
42
+ Use this property when you want to store an array of strings. This property doesn't have any options.
43
43
 
44
44
  ---
45
45
 
@@ -84,7 +84,7 @@ m.things
84
84
  # => { "a" => "bcd", "e" => "fgh" }
85
85
  ````
86
86
 
87
- Use this property when you want to store simple hash values. This property dosn't have any options.
87
+ Use this property when you want to store simple hash values. This property doesn't have any options.
88
88
 
89
89
  Please note: All hash keys will be returned as strings when your hash is loaded from the database, even if you supplied a hash with symbol keys when you saved it. If this is undesired, check out the `Hash#symbolize_keys` method provided by `ActiveSupport` ([link](http://rubygems.org/gems/activesupport)).
90
90
 
@@ -118,3 +118,10 @@ Please note: JSON de/serializtion is being handled by the `Oj` gem, which is the
118
118
  3. Commit your changes (`git commit -am 'Add some feature'`)
119
119
  4. Push to the branch (`git push origin my-new-feature`)
120
120
  5. Create new Pull Request
121
+
122
+ ## Shout Outs
123
+
124
+ This library is heavily inspired by and borrows ideas and sometimes code from:
125
+ - `dm-pg-types` ([More Info](https://github.com/svs/dm-pg-types))
126
+ - `dm-types` ([More Info](https://github.com/svs/dm-types))
127
+ - `dm-pg-json` ([More Info](https://github.com/styleseek/dm-pg-json))
@@ -7,17 +7,17 @@ module DataMapper
7
7
  class PgHStore < Object
8
8
  def load(value)
9
9
  return nil unless value
10
- values = value.split(",")
11
- values.map! { |val| unescape_pg_hash(val) }
12
- values.map! { |key, val| [key, unescape_nil(val)] }
10
+ values = value.split(", ")
11
+ values.map! do |val|
12
+ k, v = val.split("=>")
13
+ [unescape_double_quote(k),unescape_double_quote(unescape_nil(v))]
14
+ end
13
15
  Hash[*(values.flatten)]
14
16
  end
15
17
 
16
18
  def dump(value)
17
19
  return "" unless value
18
- value.map! do |idx, val|
19
- [escape_double_quote(idx), escape_value(val)].join(",")
20
- end
20
+ value.map { |key, val| %Q{"#{key.to_s}"=>"#{escape_nil(val)}"} }.join(", ")
21
21
  end
22
22
 
23
23
  private
@@ -30,30 +30,11 @@ module DataMapper
30
30
  (value == 'NULL') ? nil : value
31
31
  end
32
32
 
33
- def escape_double_quote(value)
34
- value.gsub!(/"/, '\"')
35
- value
36
- end
37
-
38
33
  def unescape_double_quote(value)
39
34
  value.gsub!('"','')
40
35
  value.strip!
41
36
  value
42
37
  end
43
-
44
- def escape_pg_hash(value)
45
- (value =~ /[,\s=>]/ || value.empty?) ? %Q{"#{value}"} : value
46
- end
47
-
48
- def unescape_pg_hash(value)
49
- values = value.split("=>")
50
- values.map! { |val| unescape_double_quote(val) }
51
- values
52
- end
53
-
54
- def escape_value(value)
55
- escape_double_quote(escape_nil(escape_pg_hash(value)))
56
- end
57
38
  end
58
39
  end
59
40
  end
@@ -1,5 +1,5 @@
1
1
  module DataMapper
2
2
  module PostgresTypes
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-postgres-types
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Marden
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-08 00:00:00.000000000 Z
11
+ date: 2014-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dm-core