condition 0.0.2 → 0.0.3

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: 2cc74fd455a5c5272d28fdf6ed278b6b3f2790dd
4
- data.tar.gz: 8a7cffd879fd0c3cab7c0f77490896e0f1645edf
3
+ metadata.gz: 56f8176e26996112edd1da8178bdbdc10ea723e5
4
+ data.tar.gz: 87d8a3b31df12240ecbb2d6155d311e7629e175e
5
5
  SHA512:
6
- metadata.gz: b01d271d559b2d76f8f5ef336e8a63f86c396ab3b5e945079f82ea96e8133ce01e3cbdb0cbc149bf3200d562b5c26d39ed5fd1dd0af75d57cf6e7140e37baa61
7
- data.tar.gz: eadf6a040442e6ad2be58c69a6064a6c0a5d0830b90f292938e94cf24ed219dc7adfe615937a54f2da208a812bd56a24d10935396483c7da9ebb16d895973e36
6
+ metadata.gz: 4c58d2270aa657f59be34cab672c0edf05a8d7399116b969c87d0f2abcff24f8e5ff2c349c6b3686e5272cb9fc183df72233180ac2d105158f7da0d1ca3180b7
7
+ data.tar.gz: f5e00fe61661aeace89ab6dc7ac4ef9ec655b782dc86c812afa2be8f13f53708e8e048f860cb721bf99612de1a3f4d8c9e19caa1e5507b595952c52726ae11d7
data/README.md CHANGED
@@ -30,6 +30,9 @@ TODO: Write usage instructions here
30
30
 
31
31
  ## Changes
32
32
 
33
+ 2013-04-15 0.0.3
34
+ add default to precondition
35
+
33
36
  2013-04-11 0.0.2
34
37
  add param, param_item
35
38
  delete pre, post, reader, table
@@ -42,12 +42,20 @@ module Condition
42
42
  end
43
43
  end
44
44
 
45
+ def item(name)
46
+ @item_map[name]
47
+ end
48
+
45
49
  def get(name)
46
- @item_map[name].values
50
+ item = @item_map[name]
51
+ return nil if !item
52
+ item.values
47
53
  end
48
54
 
49
55
  def get_one(name)
50
- @item_map[name].value
56
+ item = @item_map[name]
57
+ return nil if !item
58
+ item.value
51
59
  end
52
60
 
53
61
  def check(name, data)
@@ -57,10 +65,10 @@ module Condition
57
65
  end
58
66
  end
59
67
 
60
- def pre(db)
68
+ def pre(db, default=nil)
61
69
  @item_map.each_value do |item|
62
70
  item.delete(db)
63
- item.insert(db)
71
+ item.insert(db, default)
64
72
  end
65
73
  end
66
74
 
@@ -36,6 +36,10 @@ module Condition
36
36
  @values
37
37
  end
38
38
 
39
+ def params
40
+ @params
41
+ end
42
+
39
43
  def all(db)
40
44
  db["SELECT * FROM #{@name}"].all
41
45
  end
@@ -44,10 +48,14 @@ module Condition
44
48
  db["DELETE FROM #{@name}"].delete
45
49
  end
46
50
 
47
- def insert(db)
48
- ds = db[@name.to_sym].prepare(:insert, :insert_with_name, @params)
51
+ def insert(db, default)
52
+ item = default.item(@name) if default
53
+ ds = db[@name.to_sym].prepare(
54
+ :insert,
55
+ :insert_with_name,
56
+ item ? item.params.merge(@params) : @params)
49
57
  @values.each do |it|
50
- ds.call(it)
58
+ ds.call(item ? item.value.merge(it) : it)
51
59
  end
52
60
  end
53
61
 
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Condition
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
@@ -1,24 +1,29 @@
1
1
  require 'spec_helper'
2
2
  describe Condition do
3
3
  before(:all) do
4
- DB << "CREATE TABLE IF NOT EXISTS t_user(user_id BIGINT, user_name TEXT)"
5
- DB << "CREATE TABLE IF NOT EXISTS t_test(id BIGINT, name TEXT, flag BOOLEAN, ts TIMESTAMPTZ, iary BIGINT[], tary TEXT[])"
4
+ DB << "DROP TABLE IF EXISTS t_user"
5
+ DB << "DROP TABLE IF EXISTS t_test"
6
+ DB << "CREATE TABLE t_user(user_id BIGINT, user_name TEXT, login_ts TIMESTAMPTZ NOT NULL)"
7
+ DB << "CREATE TABLE t_test(id BIGINT, name TEXT, flag BOOLEAN, ts TIMESTAMPTZ, iary BIGINT[], tary TEXT[], test_name TEXT NOT NULL)"
6
8
  end
7
9
 
8
10
  it 'pre and post' do
9
11
  param = Condition::Param.new(FILES + '/t_user.ods')
10
- param.pre(DB)
12
+ default = Condition::Param.new(FILES + '/t_user.ods', 3)
13
+ param.pre(DB, default)
11
14
  param = Condition::Param.new(FILES + '/t_user.ods', 1)
12
15
  param.post(DB)
13
16
  end
14
17
 
15
18
  it 'pre and params' do
16
19
  param = Condition::Param.new(FILES + '/t_user.ods')
17
- param.pre(DB)
20
+ default = Condition::Param.new(FILES + '/t_user.ods', 3)
21
+ param.pre(DB, default)
18
22
 
19
23
  param = Condition::Param.new(FILES + '/t_user.ods', 2)
20
- ds = DB[:t_user].prepare(:insert, :insert_with_name, {user_id: :$user_id, user_name: :$user_name})
21
- ds.call(param.get_one('ins'))
24
+ item = default.item('t_user')
25
+ ds = DB[:t_user].prepare(:insert, :insert_with_name, item.params.merge({user_id: :$user_id, user_name: :$user_name}))
26
+ ds.call(item.value.merge(param.get_one('ins')))
22
27
 
23
28
  list = DB["SELECT * FROM t_user"].all
24
29
  param.check('list', list)
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: condition
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
  - aoyagikouhei
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-10 00:00:00.000000000 Z
11
+ date: 2013-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler