record_store 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/record_store.rb +21 -3
- data/record_store.gemspec +1 -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: 8f98dc3b3a7439e904f88b8d46856b689d40cd40
|
4
|
+
data.tar.gz: 584c3e8614f3fac484414838d5ae2c5c9c114053
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c94aca9cdbcb23e70d49e5c7ca643ddbc987ece4caf556ced296a0c3eea0ffbd736ce35248517a4c97a17ce8a9b8ae1dec6951ac5b8b3ff5e569635cab7869e8
|
7
|
+
data.tar.gz: 15509f73d2a7881364f98674cb0b73e736a966a02cc69ea446cd3614280429edeb9bd9a8417fa544d18a8d6972516f3422c74d3f478301d8076a16c96a11bd54
|
data/lib/record_store.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class RecordStore
|
2
|
-
VERSION = "0.
|
2
|
+
VERSION = "0.2.0"
|
3
3
|
|
4
4
|
class << self
|
5
5
|
def put(record)
|
@@ -11,6 +11,13 @@ class RecordStore
|
|
11
11
|
@dataset_name ||= name.sub(/Store$/,'').tableize.to_sym
|
12
12
|
end
|
13
13
|
|
14
|
+
def type_column_map(database)
|
15
|
+
@type_column_map ||= database.schema(dataset_name).each_with_object({}) do |(column,metadata),map|
|
16
|
+
map[metadata[:db_type]] ||= []
|
17
|
+
map[metadata[:db_type]] << column
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
14
21
|
def validations
|
15
22
|
@validations ||= []
|
16
23
|
end
|
@@ -39,6 +46,7 @@ class RecordStore
|
|
39
46
|
end
|
40
47
|
|
41
48
|
def put
|
49
|
+
typecast
|
42
50
|
transform
|
43
51
|
return { errors: 'no record provided' } if @record.blank?
|
44
52
|
validate
|
@@ -68,6 +76,16 @@ class RecordStore
|
|
68
76
|
@errors ||= []
|
69
77
|
end
|
70
78
|
|
79
|
+
def typecast
|
80
|
+
if database.database_type == :postgres
|
81
|
+
Array(self.class.type_column_map(database)['json']).each do |json_column|
|
82
|
+
if @record[json_column]
|
83
|
+
@record[json_column] = Sequel.pg_json(@record[json_column])
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
71
89
|
def transform
|
72
90
|
end
|
73
91
|
|
@@ -82,10 +100,10 @@ class RecordStore
|
|
82
100
|
end
|
83
101
|
|
84
102
|
def insert
|
85
|
-
dataset.insert(@record)
|
103
|
+
@record[:id] = dataset.insert(@record.except(:errors))
|
86
104
|
end
|
87
105
|
|
88
106
|
def update
|
89
|
-
dataset.where(id: @record[:id]).update(@record.except(:id))
|
107
|
+
dataset.where(id: @record[:id]).update(@record.except(:id, :errors))
|
90
108
|
end
|
91
109
|
end
|
data/record_store.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: record_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Barry
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|