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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed2b5bff4fe20d7492d9d7962db5ac19d01db361
4
- data.tar.gz: e31babad47cd7164102dea6969af1d5246cb72d7
3
+ metadata.gz: 8f98dc3b3a7439e904f88b8d46856b689d40cd40
4
+ data.tar.gz: 584c3e8614f3fac484414838d5ae2c5c9c114053
5
5
  SHA512:
6
- metadata.gz: 9a580a20dd9a4bb281fdb963e54f4ca02f6b9c6185b98b4e3e31bf4659ee9a63c8e92cbc78325b010cd87ab6a5ab1ff78c24af0b60b08d67b6ddfdad4a47130f
7
- data.tar.gz: de785c0265a5bdfd1f45ba70ca169a9b65ee3fa43192854abe9662cd7139f353a4e224f23847bbdc979381a01a1c1ac5db7715b5ea74e7916c5c0748cbb72600
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.1.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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "record_store"
5
- spec.version = "0.1.0"
5
+ spec.version = "0.2.0"
6
6
  spec.authors = ["Paul Barry"]
7
7
  spec.email = ["mail@paulbarry.com"]
8
8
 
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.1.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-05-20 00:00:00.000000000 Z
11
+ date: 2015-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler