condition 0.0.9 → 0.0.10

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: 9b30028c08d8586bbc2846e45107fd738ef3ab07
4
- data.tar.gz: 3fc8ef2b4e14594112d6ef7ea54c7a04b86b9565
3
+ metadata.gz: b9ac4108f5c2b04fafdc90724e8f8b52c7b90c2d
4
+ data.tar.gz: f40b96478445f6dabd7e5b7816f566428de235a2
5
5
  SHA512:
6
- metadata.gz: bad7d74c148c5567379a55ecd980f13a273c1de5cefcffb999da621e7caab942ee4a68d33eb1fda87f7ab421dac1cc0cabecf589626b207d8bd1a0c8be8f54e9
7
- data.tar.gz: 2e1210d1cbc76d637b327d1191c05ab1ff690116ab6bae3bd19caef5c70a74d738a107b8116f63806fabf1cbbe95abed4925a24ae20c8971b88b9c0d96706317
6
+ metadata.gz: 10869fa4ba4ccb3b0cf550120e2d8c1d61e27c417dc268cfb892e29e241da1aea54d464986899d8daba6718a3dda9274c32a8a06ee337456ddedfd9548703426
7
+ data.tar.gz: 618c9f8738a6e655fb29be2087adc7d47a0228c7d8e93302301f02503a890852e72a65ed821bc3cd01197a6c424df69939904320f5711cf872e4bb33974f83dd
data/README.md CHANGED
@@ -30,6 +30,9 @@ TODO: Write usage instructions here
30
30
 
31
31
  ## Changes
32
32
 
33
+ 2013-04-23 0.0.10
34
+ separate storage, param_item
35
+
33
36
  2013-04-18 0.0.9
34
37
  deep value_match?
35
38
 
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec"
24
24
  spec.add_development_dependency "pg"
25
+ spec.add_development_dependency "sequel"
25
26
  spec.add_dependency "roo"
26
- spec.add_dependency "sequel"
27
27
  spec.add_dependency "json"
28
28
  end
@@ -65,17 +65,17 @@ module Condition
65
65
  end
66
66
  end
67
67
 
68
- def pre(db, default=nil)
68
+ def pre(storage, default=nil)
69
69
  @item_map.each_value do |item|
70
- item.delete(db)
71
- item.insert(db, default)
72
- item.exec_after(db)
70
+ storage.delete(item)
71
+ storage.insert(item, default)
72
+ storage.exec_after(item)
73
73
  end
74
74
  end
75
75
 
76
- def post(db)
76
+ def post(storage)
77
77
  @item_map.each_value do |item|
78
- list = item.all(db)
78
+ list = storage.all(item)
79
79
  list.each do |line|
80
80
  item.check_line(line)
81
81
  end
@@ -67,29 +67,8 @@ module Condition
67
67
  @params
68
68
  end
69
69
 
70
- def all(db)
71
- db["SELECT * FROM #{@name}"].all
72
- end
73
-
74
- def delete(db)
75
- db["DELETE FROM #{@name}"].delete
76
- end
77
-
78
- def insert(db, default)
79
- item = default.item(@name) if default
80
- ds = db[@name.to_sym].prepare(
81
- :insert,
82
- :insert_with_name,
83
- item ? item.params.merge(@params) : @params)
84
- @values.each do |it|
85
- ds.call(item ? item.value.merge(it) : it)
86
- end
87
- end
88
-
89
- def exec_after(db)
90
- @options.each do |key|
91
- db.run key
92
- end
70
+ def options
71
+ @options
93
72
  end
94
73
 
95
74
  def value_match?(expected, real)
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+
3
+ module Condition
4
+ module Storage
5
+ class Db
6
+ def initialize(db)
7
+ @db = db
8
+ end
9
+
10
+ def all(param_item)
11
+ @db["SELECT * FROM #{param_item.name}"].all
12
+ end
13
+
14
+ def delete(param_item)
15
+ @db["DELETE FROM #{param_item.name}"].delete
16
+ end
17
+
18
+ def insert(param_item, default)
19
+ default_item = default.item(param_item.name) if default
20
+ ds = @db[param_item.name.to_sym].prepare(
21
+ :insert,
22
+ :insert_with_name,
23
+ default_item ? default_item.params.merge(param_item.params) : param_item.params)
24
+ param_item.values.each do |it|
25
+ ds.call(default_item ? default_item.value.merge(it) : it)
26
+ end
27
+ end
28
+
29
+ def exec_after(param_item)
30
+ param_item.options.each do |key|
31
+ @db.run key
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Condition
4
- VERSION = "0.0.9"
4
+ VERSION = "0.0.10"
5
5
  end
@@ -8,17 +8,19 @@ describe Condition do
8
8
  end
9
9
 
10
10
  it 'pre and post' do
11
+ storage = Condition::Storage::Db.new(DB)
11
12
  param = Condition::Param.new(FILES + '/t_user.ods')
12
13
  default = Condition::Param.new(FILES + '/t_user.ods', 3)
13
- param.pre(DB, default)
14
+ param.pre(storage, default)
14
15
  param = Condition::Param.new(FILES + '/t_user.ods', 1)
15
- param.post(DB)
16
+ param.post(storage)
16
17
  end
17
18
 
18
19
  it 'pre and params' do
20
+ storage = Condition::Storage::Db.new(DB)
19
21
  param = Condition::Param.new(FILES + '/t_user.ods')
20
22
  default = Condition::Param.new(FILES + '/t_user.ods', 3)
21
- param.pre(DB, default)
23
+ param.pre(storage, default)
22
24
 
23
25
  param = Condition::Param.new(FILES + '/t_user.ods', 2)
24
26
  item = default.item('t_user')
@@ -3,6 +3,8 @@
3
3
  require 'bundler/setup'
4
4
  require 'condition'
5
5
  require 'sequel'
6
+ require 'pg'
7
+ require 'condition/storage/db'
6
8
 
7
9
  FILES = File.dirname(__FILE__) + "/files"
8
10
  DB = Sequel.connect('postgres://localhost:5432/test?user=aoyagikouhei')
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.9
4
+ version: 0.0.10
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-18 00:00:00.000000000 Z
11
+ date: 2013-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,13 +67,13 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: roo
70
+ name: sequel
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
- type: :runtime
76
+ type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: sequel
84
+ name: roo
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - '>='
@@ -124,6 +124,7 @@ files:
124
124
  - lib/condition.rb
125
125
  - lib/condition/param.rb
126
126
  - lib/condition/param_item.rb
127
+ - lib/condition/storage/db.rb
127
128
  - lib/condition/version.rb
128
129
  - spec/condition_spec.rb
129
130
  - spec/files/t_user.ods