dm-hstore 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/dm-hstore.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'dm-core'
2
+ require 'dm-types'
3
+ require 'dm-postgres-adapter'
4
+
5
+ module DataMapper
6
+ class Property
7
+ autoload :HStore, 'dm-hstore/property'
8
+ end
9
+
10
+ module Resource
11
+ require 'dm-hstore/resource'
12
+ end
13
+
14
+ module HStoreType
15
+ def self.included(base)
16
+ base.extend ClassMethods
17
+ end
18
+
19
+ module ClassMethods
20
+ def type_map
21
+ super.merge(Property::HStore => { primitive: 'hstore' }).freeze
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ DataMapper::Adapters::PostgresAdapter.send :include, DataMapper::HStoreType
@@ -0,0 +1,32 @@
1
+ require 'dm-core'
2
+ require 'dm-types'
3
+
4
+ module DataMapper
5
+ class Property
6
+ class HStore < Object
7
+ def load(str)
8
+ return {} if str.nil?
9
+ hash = Hash[*str.to_s.split(',').map do |item|
10
+ if item.strip =~ /\A\"(.*)\"[ ]*=>[ ]*(.*)\z/
11
+ key = $1.to_sym
12
+ value = $2 =~ /\"(.*)\"/ ? $1 : nil
13
+ [key, value]
14
+ else
15
+ raise ArgumentError, 'invalid format'
16
+ end
17
+ end.flatten]
18
+ hash = hash.with_indifferent_access if hash.respond_to? :with_indifferent_access
19
+ hash
20
+ end
21
+
22
+ def dump(hash)
23
+ return "" if hash.nil?
24
+ raise ArgumentError, 'invalid format' unless hash.is_a? Hash
25
+ hash.map do |key, value|
26
+ value = value.nil? ? "NULL" : "\"#{value}\""
27
+ "\"#{key}\"=>#{value}"
28
+ end.join(',')
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,4 @@
1
+ module DataMapper
2
+ module Resource
3
+ end
4
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dm-hstore
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tobias Casper
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: dm-core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.2.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.2.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: dm-types
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.2.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.2.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: dm-postgres-adapter
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.2.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.0
62
+ description: Provides a new HStore property type.
63
+ email: tobias.casper@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - lib/dm-hstore.rb
69
+ - lib/dm-hstore/property.rb
70
+ - lib/dm-hstore/resource.rb
71
+ homepage: https://github.com/tlux/dm-hstore
72
+ licenses: []
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 1.8.24
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: PostgreSQL HStore support for DataMapper.
95
+ test_files: []