condition 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/condition.gemspec +2 -0
- data/lib/condition/param_item.rb +8 -0
- data/lib/condition/storage/mongo.rb +32 -0
- data/lib/condition/version.rb +1 -1
- data/spec/condition_spec.rb +9 -0
- data/spec/files/mongo.ods +0 -0
- data/spec/spec_helper.rb +3 -0
- metadata +32 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd8a22e436ad2e33acfe92f3afb8328ccebaeaa7
|
4
|
+
data.tar.gz: f89110f5e7a98059d08e28268233172818c0d237
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e17ac7ebfef9a3ac6cc5bb21b8cf47e4825727ca2b3ba4c426d1a287ec6d7da48113f76d0f03b4a002fb87cd46b12e579b4cff27e4e95fc4e137bf77337fad17
|
7
|
+
data.tar.gz: 8e005b131cf535efdbfefec067afc1ee679360dab6f3537c3723b24c8660e5cd85fa132d0a45d0f38ee1333852517dc8617bc389c8bec433ea47153d06d058ba
|
data/README.md
CHANGED
data/condition.gemspec
CHANGED
@@ -23,6 +23,8 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "rspec"
|
24
24
|
spec.add_development_dependency "pg"
|
25
25
|
spec.add_development_dependency "sequel"
|
26
|
+
spec.add_development_dependency "mongo"
|
27
|
+
spec.add_development_dependency "bson_ext"
|
26
28
|
spec.add_dependency "roo"
|
27
29
|
spec.add_dependency "json"
|
28
30
|
end
|
data/lib/condition/param_item.rb
CHANGED
@@ -31,6 +31,10 @@ module Condition
|
|
31
31
|
def calc_item(item, index, key)
|
32
32
|
if '#NULL' == item
|
33
33
|
nil
|
34
|
+
elsif '#TRUE' == item
|
35
|
+
true
|
36
|
+
elsif '#FALSE' == item
|
37
|
+
false
|
34
38
|
elsif '#EMPTY' == item
|
35
39
|
[]
|
36
40
|
elsif /^#REF\((.+)\)$/ =~ item
|
@@ -40,6 +44,10 @@ module Condition
|
|
40
44
|
item
|
41
45
|
elsif /^#JSON\((.+)\)$/ =~ item
|
42
46
|
JSON.parse($1, {:symbolize_names => true})
|
47
|
+
elsif /^#TIME\((.+)\)$/ =~ item
|
48
|
+
Time.parse($1)
|
49
|
+
elsif /^#INT\((.+)\)$/ =~ item
|
50
|
+
$1.to_i
|
43
51
|
else
|
44
52
|
item
|
45
53
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Condition
|
4
|
+
module Storage
|
5
|
+
class Mongo
|
6
|
+
def initialize(db)
|
7
|
+
@db = db
|
8
|
+
end
|
9
|
+
|
10
|
+
def all(param_item)
|
11
|
+
@db[param_item.name].find()
|
12
|
+
end
|
13
|
+
|
14
|
+
def delete(param_item)
|
15
|
+
@db[param_item.name].remove()
|
16
|
+
end
|
17
|
+
|
18
|
+
def insert(param_item, default)
|
19
|
+
default_item = default.item(param_item.name) if default
|
20
|
+
param_item.values.each do |it|
|
21
|
+
@db[param_item.name].insert(default_item ? default_item.value.merge(it) : it)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def exec_after(param_item)
|
26
|
+
param_item.options.each do |key|
|
27
|
+
# nothing
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/condition/version.rb
CHANGED
data/spec/condition_spec.rb
CHANGED
@@ -41,4 +41,13 @@ describe Condition do
|
|
41
41
|
param = Condition::Param.new(FILES + '/t_user.ods', 2)
|
42
42
|
lambda{param.check('unmatch', [{id: 1, name: "bbb", val: 456}])}.should raise_error
|
43
43
|
end
|
44
|
+
|
45
|
+
it 'mongo' do
|
46
|
+
storage = Condition::Storage::Mongo.new(MONGO)
|
47
|
+
param = Condition::Param.new(FILES + '/mongo.ods')
|
48
|
+
default = Condition::Param.new(FILES + '/mongo.ods', 2)
|
49
|
+
param.pre(storage, default)
|
50
|
+
param = Condition::Param.new(FILES + '/t_user.ods', 1)
|
51
|
+
param.post(storage)
|
52
|
+
end
|
44
53
|
end
|
Binary file
|
data/spec/spec_helper.rb
CHANGED
@@ -4,10 +4,13 @@ require 'bundler/setup'
|
|
4
4
|
require 'condition'
|
5
5
|
require 'sequel'
|
6
6
|
require 'pg'
|
7
|
+
require 'mongo'
|
7
8
|
require 'condition/storage/db'
|
9
|
+
require 'condition/storage/mongo'
|
8
10
|
|
9
11
|
FILES = File.dirname(__FILE__) + "/files"
|
10
12
|
DB = Sequel.connect('postgres://localhost:5432/test?user=aoyagikouhei')
|
13
|
+
MONGO = Mongo::MongoClient.new('localhost', 27017)['test']
|
11
14
|
|
12
15
|
RSpec.configure do |config|
|
13
16
|
# some (optional) config here
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: condition
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aoyagikouhei
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mongo
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bson_ext
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: roo
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,8 +153,10 @@ files:
|
|
125
153
|
- lib/condition/param.rb
|
126
154
|
- lib/condition/param_item.rb
|
127
155
|
- lib/condition/storage/db.rb
|
156
|
+
- lib/condition/storage/mongo.rb
|
128
157
|
- lib/condition/version.rb
|
129
158
|
- spec/condition_spec.rb
|
159
|
+
- spec/files/mongo.ods
|
130
160
|
- spec/files/t_user.ods
|
131
161
|
- spec/spec_helper.rb
|
132
162
|
homepage: https://github.com/aoyagikouhei/condition
|
@@ -155,5 +185,6 @@ specification_version: 4
|
|
155
185
|
summary: Condition Test
|
156
186
|
test_files:
|
157
187
|
- spec/condition_spec.rb
|
188
|
+
- spec/files/mongo.ods
|
158
189
|
- spec/files/t_user.ods
|
159
190
|
- spec/spec_helper.rb
|