wherever-positions 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/string_helper.rb +16 -0
- data/lib/wherever.rb +1 -0
- data/lib/wherever/configure.rb +2 -2
- data/lib/wherever/db_store.rb +3 -2
- data/lib/wherever/db_store/lookup.rb +4 -0
- data/lib/wherever/wherever/adder.rb +1 -2
- data/lib/wherever/wherever/getter.rb +2 -2
- data/lib/wherever/wherever/lookup.rb +3 -6
- data/lib/wherever/wherever/mark.rb +1 -1
- data/spec/wherever/adder_spec.rb +3 -3
- data/spec/wherever/custom_grouping_spec.rb +3 -3
- data/spec/wherever/getter_spec.rb +2 -2
- data/spec/wherever/key_store_spec.rb +1 -1
- data/spec/wherever/mark_spec.rb +3 -3
- data/spec/wherever/setter_spec.rb +2 -2
- data/spec/wherever/using_lookup_in_grouping_spec.rb +5 -5
- data/wherever-positions.gemspec +2 -1
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.4
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module StringHelper
|
2
|
+
class << self
|
3
|
+
def add_method_to_id(strings)
|
4
|
+
return nil unless strings
|
5
|
+
strings.each do |string|
|
6
|
+
if string.is_a?(Array)
|
7
|
+
add_method_to_id(string)
|
8
|
+
else
|
9
|
+
def string.to_id
|
10
|
+
"#{self}_id"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/wherever.rb
CHANGED
data/lib/wherever/configure.rb
CHANGED
@@ -13,8 +13,8 @@ class Configure
|
|
13
13
|
config.master = mongo_connection
|
14
14
|
end
|
15
15
|
|
16
|
-
@keys = options["keys"]
|
17
|
-
groups = options["key_groups"] || @keys
|
16
|
+
@keys = StringHelper.add_method_to_id(options["keys"])
|
17
|
+
groups = StringHelper.add_method_to_id(options["key_groups"]) || @keys
|
18
18
|
@key_groups = groups.map{|g| Array(g)}
|
19
19
|
end
|
20
20
|
end
|
data/lib/wherever/db_store.rb
CHANGED
@@ -31,9 +31,10 @@ module DbStore
|
|
31
31
|
|
32
32
|
def get_lookup(name, keys)
|
33
33
|
DbStore::Lookup.find_or_create_by(:name => name, :keys => keys) if keys
|
34
|
-
|
34
|
+
class_name = "Lookup#{name.titlecase}"
|
35
|
+
return "DbStore::#{class_name}".constantize if DbStore.constants.include?(class_name)
|
35
36
|
raise "Missing lookup key from definition" unless keys
|
36
|
-
build_class(
|
37
|
+
build_class(class_name, DbStore::VersionConfig, :"lookup_#{name}")
|
37
38
|
end
|
38
39
|
|
39
40
|
def build_class(name, module_object, store_in)
|
@@ -52,8 +52,7 @@ class Wherever
|
|
52
52
|
def for_group(group_keys, values, id_record)
|
53
53
|
key = {}
|
54
54
|
group_keys.each do |key_values|
|
55
|
-
|
56
|
-
key.merge!(k_id => @options["keys"][k_id])
|
55
|
+
key.merge!(key_values.to_id => @options["keys"][key_values.to_id])
|
57
56
|
end
|
58
57
|
store = get_key_store(*group_keys)
|
59
58
|
record = store.datasets.find_or_create_by(key)
|
@@ -5,7 +5,7 @@ class Wherever
|
|
5
5
|
result = Hash.new(0)
|
6
6
|
if keys.first == "identifier"
|
7
7
|
get_key_store(*keys).datasets.where(selector).all.each do |record|
|
8
|
-
@grouping.call(result, record.values, result,
|
8
|
+
@grouping.call(result, record.values, result, keys)
|
9
9
|
end
|
10
10
|
result
|
11
11
|
else
|
@@ -24,7 +24,7 @@ class Wherever
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def check_keys(keys)
|
27
|
-
invalid_keys = (keys - config.keys)
|
27
|
+
invalid_keys = (keys - config.keys.map(&:to_id))
|
28
28
|
raise InvalidSelector,"Unknown Selector: #{invalid_keys.join(' ')}" unless invalid_keys.empty?
|
29
29
|
end
|
30
30
|
end
|
@@ -16,7 +16,7 @@ class Wherever
|
|
16
16
|
lookup = get_lookup(name)
|
17
17
|
lookup_data = lookup_class.where(:name => lookup.lookups[marker]).first
|
18
18
|
return 0 unless lookup_data
|
19
|
-
value_key = lookup.keys.map{|key| data[key]}.join('_')
|
19
|
+
value_key = lookup.keys.map{|key| data[key.to_id]}.join('_')
|
20
20
|
lookup_data.values[value_key] || 0
|
21
21
|
end
|
22
22
|
end
|
@@ -56,16 +56,13 @@ class Wherever
|
|
56
56
|
config.key_groups.each do |group|
|
57
57
|
if keys & group == keys
|
58
58
|
get_key_store(*group).datasets.all.each do |record|
|
59
|
-
@grouping.call(record.values, nil, record,
|
59
|
+
@grouping.call(record.values, nil, record, group)
|
60
|
+
record.save!
|
60
61
|
end
|
61
|
-
record.save!
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
def temp(group_keys, values, id_record)
|
67
|
-
end
|
68
|
-
|
69
66
|
def get_lookup_record(name, marker)
|
70
67
|
lookup = get_lookup(name)
|
71
68
|
return [lookup, lookup.versions.find_or_create_by(:name => lookup.lookups[marker])]
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class Wherever
|
2
2
|
module Mark
|
3
3
|
def mark(name)
|
4
|
-
copy_collections("
|
4
|
+
copy_collections("current_identifier_dataset", "#{name}_identifier_dataset")
|
5
5
|
config.key_groups.each do |keys|
|
6
6
|
[:identifier, :dataset].each do |db_type|
|
7
7
|
db_id = "#{keys.join('_')}_#{db_type}"
|
data/spec/wherever/adder_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
2
|
|
3
3
|
describe "Wherever" do
|
4
4
|
let(:wherever) { Wherever.new("keys" => keys, "database" => 'wherever_test', "key_groups" => key_groups, "key" => "trade_id") }
|
5
|
-
let(:keys) { ["
|
5
|
+
let(:keys) { ["fund"] }
|
6
6
|
let(:key_groups) { nil }
|
7
7
|
|
8
8
|
context 'adding the first record' do
|
@@ -35,7 +35,7 @@ describe "Wherever" do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
context 'with a multiple keys' do
|
38
|
-
let(:keys) { ["
|
38
|
+
let(:keys) { ["fund", "security"] }
|
39
39
|
let(:options) { {"unique" => {"trade_id" => 12, "version" => 1}, "keys" => {"fund_id" => 2, "security_id" => 4}} }
|
40
40
|
|
41
41
|
it 'inserts a record for each key combination' do
|
@@ -54,7 +54,7 @@ describe "Wherever" do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
context 'with a multiple keys and grouping configured' do
|
57
|
-
let(:keys) { ["
|
57
|
+
let(:keys) { ["fund", "security"] }
|
58
58
|
let(:key_groups) { ["fund", "security", ["fund", "security"]] }
|
59
59
|
let(:options) { {"unique" => {"trade_id" => 12, "version" => 1}, "keys" => {"fund_id" => 2, "security_id" => 4}} }
|
60
60
|
|
@@ -10,7 +10,7 @@ describe Wherever, 'with a custom grouping' do
|
|
10
10
|
}
|
11
11
|
|
12
12
|
context 'add a record' do
|
13
|
-
let(:keys) { ["
|
13
|
+
let(:keys) { ["fund"] }
|
14
14
|
let(:key_groups) { nil }
|
15
15
|
let(:options) { {"unique" => {"trade_id" => 12, "version" => 1}, "keys" => {"fund_id" => 2}} }
|
16
16
|
|
@@ -30,8 +30,8 @@ describe Wherever, 'with a custom grouping' do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
context 'get a record' do
|
33
|
-
let(:keys) { ["
|
34
|
-
let(:key_groups) { ["
|
33
|
+
let(:keys) { ["fund", "security"] }
|
34
|
+
let(:key_groups) { ["fund"] }
|
35
35
|
let(:options_one) { {"unique" => {"trade_id" => 12, "version" => 1}, "keys" => {"fund_id" => 2, "security_id" => 14}} }
|
36
36
|
let(:options_two) { {"unique" => {"trade_id" => 15, "version" => 1}, "keys" => {"fund_id" => 2, "security_id" => 14}} }
|
37
37
|
|
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
2
|
|
3
3
|
describe "Wherever" do
|
4
4
|
let(:wherever) { Wherever.new("keys" => keys, "database" => 'wherever_test', "key_groups" => key_groups, "key" => "trade_id") }
|
5
|
-
let(:keys) { ["
|
5
|
+
let(:keys) { ["fund"] }
|
6
6
|
let(:key_groups) { nil }
|
7
7
|
|
8
8
|
context 'getting the record data' do
|
@@ -20,7 +20,7 @@ describe "Wherever" do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
context 'a more complex example' do
|
23
|
-
let(:keys) { ["
|
23
|
+
let(:keys) { ["fund", "security"] }
|
24
24
|
let(:key_groups) { ["fund", ["fund", "security"]] }
|
25
25
|
let(:options) { {"unique" => {"trade_id" => 12, "version" => 2}, "keys" => {"fund_id" => 3, "security_id" => 12}} }
|
26
26
|
|
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
2
|
|
3
3
|
describe "Wherever" do
|
4
4
|
let(:wherever) { Wherever.new("keys" => keys, "database" => 'wherever_test', "key_groups" => key_groups, "key" => "trade_id") }
|
5
|
-
let(:keys) { ["
|
5
|
+
let(:keys) { ["fund"] }
|
6
6
|
let(:key_groups) { nil }
|
7
7
|
|
8
8
|
context 'get the key store' do
|
data/spec/wherever/mark_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Wherever, 'mark a time point' do
|
|
5
5
|
let(:wherever) {
|
6
6
|
Wherever.new(*create_options) do |values, data, record, keys|
|
7
7
|
price = wherever.get_price('current', record)
|
8
|
-
if keys.include?("
|
8
|
+
if keys.include?("security")
|
9
9
|
values["position"] += data["position"] if data
|
10
10
|
values["price"] = price
|
11
11
|
end
|
@@ -16,14 +16,14 @@ describe Wherever, 'mark a time point' do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
}
|
19
|
-
let(:keys) { ["
|
19
|
+
let(:keys) { ["fund", "security"] }
|
20
20
|
let(:key_groups) { ["fund", "security", ["fund", "security"]] }
|
21
21
|
|
22
22
|
let(:options_one) { {"unique" => {"trade_id" => 12, "version" => 1}, "keys" => {"fund_id" => 2, "security_id" => 4}} }
|
23
23
|
let(:options_two) { {"unique" => {"trade_id" => 14, "version" => 1}, "keys" => {"fund_id" => 2, "security_id" => 4}} }
|
24
24
|
|
25
25
|
before do
|
26
|
-
wherever.create_lookup('price', ["
|
26
|
+
wherever.create_lookup('price', ["security"])
|
27
27
|
wherever.set_price('20111029_01', {4 => 12.5})
|
28
28
|
wherever.add({"position" => 100}, options_one)
|
29
29
|
wherever.mark('COB_20111009')
|
@@ -2,12 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Wherever, 'setting values' do
|
4
4
|
let(:wherever) { Wherever.new("keys" => keys, "database" => 'wherever_test', "key_groups" => key_groups, "key" => "trade_id") }
|
5
|
-
let(:keys) { ["
|
5
|
+
let(:keys) { ["fund"] }
|
6
6
|
let(:key_groups) { nil }
|
7
7
|
|
8
8
|
context 'data storage' do
|
9
9
|
before do
|
10
|
-
wherever.create_lookup('price', ["
|
10
|
+
wherever.create_lookup('price', ["security"])
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'can save and retrieve version data' do
|
@@ -5,7 +5,7 @@ describe Wherever, 'using lookup in grouping calculation' do
|
|
5
5
|
let(:wherever) {
|
6
6
|
Wherever.new(*create_options) do |values, data, record, keys|
|
7
7
|
price = wherever.get_price('current', record)
|
8
|
-
if keys.include?("
|
8
|
+
if keys.include?("security")
|
9
9
|
values["position"] += data["position"] if data
|
10
10
|
values["price"] = price
|
11
11
|
end
|
@@ -16,7 +16,7 @@ describe Wherever, 'using lookup in grouping calculation' do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
}
|
19
|
-
let(:keys) { ["
|
19
|
+
let(:keys) { ["fund", "security"] }
|
20
20
|
let(:key_groups) { ["fund", "security", ["fund", "security"]] }
|
21
21
|
|
22
22
|
context 'add record after price' do
|
@@ -26,7 +26,7 @@ describe Wherever, 'using lookup in grouping calculation' do
|
|
26
26
|
let(:options_three) { {"unique" => {"trade_id" => 14, "version" => 1}, "keys" => {"fund_id" => 2, "security_id" => 4}} }
|
27
27
|
|
28
28
|
before do
|
29
|
-
wherever.create_lookup('price', ["
|
29
|
+
wherever.create_lookup('price', ["security"])
|
30
30
|
wherever.set_price('current', {4 => 12.5})
|
31
31
|
wherever.add({"position" => 100}, options_one)
|
32
32
|
end
|
@@ -63,12 +63,12 @@ describe Wherever, 'using lookup in grouping calculation' do
|
|
63
63
|
let(:options_three) { {"unique" => {"trade_id" => 14, "version" => 1}, "keys" => {"fund_id" => 2, "security_id" => 4}} }
|
64
64
|
|
65
65
|
before do
|
66
|
-
wherever.create_lookup('price', ["
|
66
|
+
wherever.create_lookup('price', ["security"])
|
67
67
|
wherever.add({"position" => 100}, options_one)
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'on identifier record' do
|
71
|
-
wherever.create_lookup('price', ["
|
71
|
+
wherever.create_lookup('price', ["security"])
|
72
72
|
wherever.set_price('current', {4 => 12.5})
|
73
73
|
wherever.get_key_store("identifier").datasets.all.should ==
|
74
74
|
[DbStore::Dataset.new("values" => {"position" => 100, "price" => 12.5, "trade_value" => 1250},
|
data/wherever-positions.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{wherever-positions}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["David Henry"]
|
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
"features/support/env.rb",
|
31
31
|
"features/wherever.feature",
|
32
32
|
"lib/monkeypatch_for_mongoid_1.9.rb",
|
33
|
+
"lib/string_helper.rb",
|
33
34
|
"lib/wherever.rb",
|
34
35
|
"lib/wherever/configure.rb",
|
35
36
|
"lib/wherever/db_store.rb",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wherever-positions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 4
|
10
|
+
version: 0.4.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- David Henry
|
@@ -173,6 +173,7 @@ files:
|
|
173
173
|
- features/support/env.rb
|
174
174
|
- features/wherever.feature
|
175
175
|
- lib/monkeypatch_for_mongoid_1.9.rb
|
176
|
+
- lib/string_helper.rb
|
176
177
|
- lib/wherever.rb
|
177
178
|
- lib/wherever/configure.rb
|
178
179
|
- lib/wherever/db_store.rb
|