condition 0.0.16 → 0.0.17

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: 662e70bdaa099817376d9934c1146469274e7646
4
- data.tar.gz: 34fc6074209e62d7fb346b507f04ed32ff39312b
3
+ metadata.gz: c660ebf970ed4d07d0cb2c17f663c26d957f5e3c
4
+ data.tar.gz: 80508516454670dc5eb73a1e5c9db3f945519226
5
5
  SHA512:
6
- metadata.gz: db3dac4a43ae5960261295cd69ddcaa4925cf5f55a7c52dfd4bd6facf33ad1514411e460c78a85052e300d2bf0d35d7bb8ecdd470d901b02463653dd077bb628
7
- data.tar.gz: 64fc5bf5eb48e000fdb0052258ffe193a11811ca04c793deb594c4f96af8b805b4e1ba3e98ef1a4a1c6bd37a394f79851fc8a7bccd6675f2b508afad84cf256b
6
+ metadata.gz: 038592f544ab29b35d7edba60c2e22fce16d18e78cf2474f13a5b637707b5f5467b612a84b2492b3847c02b48f84a0bab8c98efd2eeae537c1b0c6c260f6ecd8
7
+ data.tar.gz: 8f3cbbb7c9b4e66203b81a5fbdddf232ebe2a072cc91ba3381cec166f1071804ec26344554d6a18badce332107dd620d35a1e37828937f815092d78123b00c33
data/README.md CHANGED
@@ -30,6 +30,9 @@ TODO: Write usage instructions here
30
30
 
31
31
  ## Changes
32
32
 
33
+ 2013-12-11 0.0.17
34
+ add redis reader
35
+
33
36
  2013-12-06 0.0.16
34
37
  modify mongo key to symbol
35
38
  modify check no used line in expectations
data/condition.gemspec CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "sequel"
26
26
  spec.add_development_dependency "mongo"
27
27
  spec.add_development_dependency "bson_ext"
28
+ spec.add_development_dependency "redis"
28
29
  spec.add_dependency "roo"
29
30
  spec.add_dependency "json"
30
31
  end
@@ -14,8 +14,17 @@ module Condition
14
14
  @@reader
15
15
  end
16
16
 
17
- def initialize(path, sheet_index=0)
18
- blocks = Condition::Param.get_reader().read_sheet(path, sheet_index)
17
+ def initialize(path, sheet_index=0, blks: nil, reader: nil)
18
+ if blks.nil?
19
+ rd = reader.nil? ? Condition::Param.get_reader() : reader
20
+ blocks = rd.read_sheet(path, sheet_index)
21
+ set_blocks(blocks)
22
+ else
23
+ set_blocks(blks)
24
+ end
25
+ end
26
+
27
+ def set_blocks(blocks)
19
28
  @item_map = {}
20
29
  item_list = []
21
30
  blocks.each do |rows|
@@ -0,0 +1,17 @@
1
+ # coding: utf-8
2
+ require 'json'
3
+
4
+ module Condition
5
+ module Reader
6
+ class ConvertSheet
7
+ def initialize(redis)
8
+ @redis = redis
9
+ @reader = Condition::Reader::RooReader.new
10
+ end
11
+
12
+ def convert(path, sheet_index, name)
13
+ @redis.set(name, JSON.generate(@reader.read_sheet(path, sheet_index)))
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ # coding: utf-8
2
+ require 'json'
3
+
4
+ module Condition
5
+ module Reader
6
+ class RedisReader
7
+ def initialize(redis)
8
+ @redis = redis
9
+ end
10
+
11
+ def read_sheet(path, sheet_index)
12
+ JSON.parse(@redis.get(path), {:symbolize_names => true})
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Condition
4
- VERSION = "0.0.16"
4
+ VERSION = "0.0.17"
5
5
  end
@@ -5,6 +5,14 @@ describe Condition do
5
5
  DB << "DROP TABLE IF EXISTS t_test"
6
6
  DB << "CREATE TABLE t_user(user_id BIGINT, user_name TEXT, login_ts TIMESTAMPTZ NOT NULL)"
7
7
  DB << "CREATE TABLE t_test(id BIGINT, name TEXT, flag BOOLEAN, ts TIMESTAMPTZ, iary BIGINT[], tary TEXT[], test_name TEXT NOT NULL)"
8
+
9
+ converter = Condition::Reader::ConvertSheet.new(REDIS)
10
+ converter.convert(FILES + '/t_user.ods', 0, 'pre_condition')
11
+ converter.convert(FILES + '/t_user.ods', 1, 'post_condition1')
12
+ converter.convert(FILES + '/t_user.ods', 2, 'params')
13
+ converter.convert(FILES + '/t_user.ods', 3, 'default')
14
+ converter.convert(FILES + '/t_user.ods', 4, 'post_condition2')
15
+ converter.convert(FILES + '/t_user.ods', 5, 'post_condition3')
8
16
  end
9
17
 
10
18
  it 'pre and post' do
@@ -67,4 +75,38 @@ describe Condition do
67
75
  param = Condition::Param.new(FILES + '/mongo.ods', 1)
68
76
  param.post(storage)
69
77
  end
78
+
79
+ it 'redis with set_reader' do
80
+ reader = Condition::Reader::RedisReader.new(REDIS)
81
+ Condition::Param.set_reader(reader)
82
+ storage = Condition::Storage::Db.new(DB)
83
+ param = Condition::Param.new('pre_condition')
84
+ default = Condition::Param.new('default')
85
+ param.pre(storage, default)
86
+ param = Condition::Param.new('post_condition1')
87
+ param.post(storage)
88
+ param = Condition::Param.new('post_condition2')
89
+ expect { param.post(storage) }.to raise_error
90
+ param = Condition::Param.new('post_condition3')
91
+ expect { param.post(storage) }.to raise_error
92
+ end
93
+
94
+ it 'redis with reader parameter' do
95
+ reader = Condition::Reader::RedisReader.new(REDIS)
96
+ Condition::Param.set_reader(nil)
97
+
98
+ storage = Condition::Storage::Db.new(DB)
99
+ param = Condition::Param.new('pre_condition', reader: reader)
100
+ default = Condition::Param.new('default', reader: reader)
101
+ param.pre(storage, default)
102
+ param = Condition::Param.new('post_condition1', reader: reader)
103
+ param.post(storage)
104
+ param = Condition::Param.new('post_condition2', reader: reader)
105
+ expect { param.post(storage) }.to raise_error
106
+ param = Condition::Param.new('post_condition3', reader: reader)
107
+ expect { param.post(storage) }.to raise_error
108
+
109
+ param = Condition::Param.new(FILES + '/t_user.ods', 5)
110
+ expect { param.post(storage) }.to raise_error
111
+ end
70
112
  end
data/spec/spec_helper.rb CHANGED
@@ -7,10 +7,14 @@ require 'pg'
7
7
  require 'mongo'
8
8
  require 'condition/storage/db'
9
9
  require 'condition/storage/mongo'
10
+ require 'redis'
11
+ require 'condition/reader/redis_reader'
12
+ require 'condition/reader/convert_sheet'
10
13
 
11
14
  FILES = File.dirname(__FILE__) + "/files"
12
15
  DB = Sequel.connect('postgres://localhost:5432/test?user=aoyagikouhei')
13
16
  MONGO = Mongo::MongoClient.new('localhost', 27017)['test']
17
+ REDIS = Redis.new
14
18
 
15
19
  RSpec.configure do |config|
16
20
  # some (optional) config here
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.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - aoyagikouhei
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-05 00:00:00.000000000 Z
11
+ date: 2013-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: redis
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: roo
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -152,6 +166,8 @@ files:
152
166
  - lib/condition.rb
153
167
  - lib/condition/param.rb
154
168
  - lib/condition/param_item.rb
169
+ - lib/condition/reader/convert_sheet.rb
170
+ - lib/condition/reader/redis_reader.rb
155
171
  - lib/condition/reader/roo_reader.rb
156
172
  - lib/condition/storage/db.rb
157
173
  - lib/condition/storage/mongo.rb