wherever-positions 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/wherever/db_store/dataset.rb +6 -9
- data/lib/wherever/db_store/identifier.rb +8 -7
- data/lib/wherever/db_store/lookup.rb +1 -0
- data/lib/wherever/db_store.rb +33 -1
- data/lib/wherever/wherever/accessors.rb +5 -2
- data/lib/wherever/wherever/lookup.rb +18 -12
- data/lib/wherever/wherever/mark.rb +11 -4
- data/spec/wherever/adder_spec.rb +19 -19
- data/spec/wherever/custom_grouping_spec.rb +2 -2
- data/spec/wherever/key_store_spec.rb +14 -2
- data/spec/wherever/mark_spec.rb +5 -5
- data/spec/wherever/using_lookup_in_grouping_spec.rb +9 -9
- data/wherever-positions.gemspec +2 -4
- metadata +4 -6
- data/lib/wherever/db_store/marker.rb +0 -12
- data/lib/wherever/db_store/store.rb +0 -9
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
@@ -1,14 +1,11 @@
|
|
1
1
|
module DbStore
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def price
|
9
|
-
self.store.marker.price
|
2
|
+
module DatasetConfig
|
3
|
+
def self.included(base)
|
4
|
+
base.send :include, Mongoid::Document
|
5
|
+
base.send :include, DbStore::RecordMatcher
|
6
|
+
base.field :values, :type => Hash, :default => Hash.new(0)
|
10
7
|
end
|
11
|
-
|
8
|
+
|
12
9
|
def diff(record)
|
13
10
|
res = {}
|
14
11
|
record.keys.each do |key|
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module DbStore
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
module IdentifierConfig
|
3
|
+
def self.included(base)
|
4
|
+
base.send :include, Mongoid::Document
|
5
|
+
base.send :include, DbStore::RecordMatcher
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
base.field :_id, :type => Integer
|
8
|
+
base.field :version, :type => Integer
|
9
|
+
end
|
10
|
+
end
|
10
11
|
end
|
data/lib/wherever/db_store.rb
CHANGED
@@ -7,4 +7,36 @@ require 'wherever/db_store/store'
|
|
7
7
|
require 'wherever/db_store/dataset'
|
8
8
|
require 'wherever/db_store/identifier'
|
9
9
|
|
10
|
-
require 'wherever/db_store/lookup'
|
10
|
+
require 'wherever/db_store/lookup'
|
11
|
+
|
12
|
+
module DbStore
|
13
|
+
class << self
|
14
|
+
attr_reader :stores
|
15
|
+
def new_store(marker, keys)
|
16
|
+
@stores ||= {}
|
17
|
+
@stores[[marker, keys]] = Container.new(
|
18
|
+
get_store(marker, keys, :identifier),
|
19
|
+
get_store(marker, keys, :dataset)
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_store(marker, keys, db_type)
|
24
|
+
name = "#{marker.upcase}_#{keys.map(&:upcase).join('_')}_#{db_type.to_s.upcase}"
|
25
|
+
return "DbStore::#{name}".constantize if DbStore.constants.include?(name)
|
26
|
+
klass = Class.new do
|
27
|
+
include "DbStore::#{db_type.to_s.titlecase}Config".constantize
|
28
|
+
store_in :"#{marker}_#{keys.join('_')}_#{db_type}"
|
29
|
+
end
|
30
|
+
eval("DbStore::#{name}=klass")
|
31
|
+
klass
|
32
|
+
end
|
33
|
+
|
34
|
+
class Container
|
35
|
+
attr_reader :identifiers, :datasets
|
36
|
+
|
37
|
+
def initialize(identifier, dataset)
|
38
|
+
@identifiers, @datasets = identifier, dataset
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
class Wherever
|
2
2
|
module Accessors
|
3
3
|
def get_key_store(*keys)
|
4
|
-
|
5
|
-
|
4
|
+
DbStore.new_store(get_marker(keys), keys)
|
5
|
+
end
|
6
|
+
|
7
|
+
def get_marker(keys=[])
|
8
|
+
keys.last.is_a?(Hash) ? keys.pop["marker"] : marker
|
6
9
|
end
|
7
10
|
|
8
11
|
def collection(mark=marker)
|
@@ -10,13 +10,13 @@ class Wherever
|
|
10
10
|
lookup, record = create_lookup_record(name, version)
|
11
11
|
record.values = key_to_string(values)
|
12
12
|
record.save
|
13
|
-
recalculate if set_price_lookup(version)
|
13
|
+
recalculate if set_price_lookup(name, version)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
self.class.class_eval do
|
18
|
-
define_method "get_#{name}" do |
|
19
|
-
lookup, record = get_lookup_record(name,
|
18
|
+
define_method "get_#{name}" do |marker, data|
|
19
|
+
lookup, record = get_lookup_record(name, marker)
|
20
20
|
value_key = lookup.keys.map{|key| data[key]}.join('_')
|
21
21
|
record.values[value_key] || 0
|
22
22
|
end
|
@@ -30,9 +30,11 @@ class Wherever
|
|
30
30
|
string_values
|
31
31
|
end
|
32
32
|
|
33
|
-
def set_price_lookup(version)
|
34
|
-
|
35
|
-
|
33
|
+
def set_price_lookup(name, version=nil, keys=[])
|
34
|
+
lookup = get_lookup(name)
|
35
|
+
return false if lookup.lookups[get_marker] == version
|
36
|
+
lookup.lookups[get_marker(keys)] = (version || lookup.lookups['current'])
|
37
|
+
lookup.save
|
36
38
|
end
|
37
39
|
|
38
40
|
def recalculate
|
@@ -49,18 +51,22 @@ class Wherever
|
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
52
|
-
def get_lookup_record(name,
|
53
|
-
lookup =
|
54
|
-
|
55
|
-
return [lookup, lookup.versions.find_or_create_by(:name => version)]
|
54
|
+
def get_lookup_record(name, marker)
|
55
|
+
lookup = get_lookup(name)
|
56
|
+
return [lookup, lookup.versions.find_or_create_by(:name => lookup.lookups[marker])]
|
56
57
|
end
|
57
58
|
|
58
59
|
def create_lookup_record(name, version)
|
59
|
-
lookup =
|
60
|
-
raise InvalidLookup, "Attempt to access invalid lookup: #{name}" unless lookup
|
60
|
+
lookup = get_lookup(name)
|
61
61
|
records = lookup.versions.where(:name => version)
|
62
62
|
raise InvalidLookupSetter, "Lookup '#{version}' for '#{name}' already set" unless records.empty?
|
63
63
|
return [lookup, lookup.versions.find_or_create_by(:name => version)]
|
64
64
|
end
|
65
|
+
|
66
|
+
def get_lookup(name)
|
67
|
+
lookup = DbStore::Lookup.where(:name => name).first
|
68
|
+
raise InvalidLookup, "Attempt to access invalid lookup: #{name}" unless lookup
|
69
|
+
lookup
|
70
|
+
end
|
65
71
|
end
|
66
72
|
end
|
@@ -1,11 +1,18 @@
|
|
1
1
|
class Wherever
|
2
2
|
module Mark
|
3
3
|
def mark(name)
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
(['identifier'] + config.key_groups).each do |key|
|
5
|
+
keys = Array(key)
|
6
|
+
current_db = get_key_store(*keys)
|
7
|
+
new_db = get_key_store(*(keys + [{'marker' => name}]))
|
8
|
+
current_db.datasets.all.each do |record|
|
9
|
+
new_db.datasets.create!(record.attributes)
|
10
|
+
end
|
11
|
+
current_db.identifiers.all.each do |record|
|
12
|
+
new_db.identifiers.create!(record.attributes)
|
13
|
+
end
|
8
14
|
end
|
15
|
+
set_price_lookup('price', nil, [{'marker' => name}])
|
9
16
|
end
|
10
17
|
end
|
11
18
|
end
|
data/spec/wherever/adder_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe "Wherever" do
|
|
10
10
|
context 'the unique dataset' do
|
11
11
|
it 'inserts a record' do
|
12
12
|
wherever.add({"settled" => 100, "unsettled" => 0}, options)
|
13
|
-
wherever.get_key_store("unique").datasets.should ==
|
13
|
+
wherever.get_key_store("unique").datasets.all.should ==
|
14
14
|
[DbStore::Dataset.new("trade_id" => 12, "values" => {"unsettled" => 0, "settled" => 100}, "version" => 1, "fund_id" => 2)]
|
15
15
|
end
|
16
16
|
end
|
@@ -18,7 +18,7 @@ describe "Wherever" do
|
|
18
18
|
context 'the id dataset' do
|
19
19
|
it 'inserts a record' do
|
20
20
|
wherever.add({"settled" => 100, "unsettled" => 0}, options)
|
21
|
-
wherever.get_key_store("identifier").datasets.should ==
|
21
|
+
wherever.get_key_store("identifier").datasets.all.should ==
|
22
22
|
[DbStore::Dataset.new("trade_id" => 12, "values" => {"unsettled" => 0, "settled" => 100}, "version" => 1, "fund_id" => 2)]
|
23
23
|
end
|
24
24
|
end
|
@@ -27,9 +27,9 @@ describe "Wherever" do
|
|
27
27
|
context 'with a single key' do
|
28
28
|
it 'inserts a record' do
|
29
29
|
wherever.add({"settled" => 100, "unsettled" => 0}, options)
|
30
|
-
wherever.get_key_store("fund").datasets.should ==
|
30
|
+
wherever.get_key_store("fund").datasets.all.should ==
|
31
31
|
[DbStore::Dataset.new("values" => {"unsettled" => 0, "settled" => 100}, "fund_id" => 2)]
|
32
|
-
wherever.get_key_store("fund").identifiers.should ==
|
32
|
+
wherever.get_key_store("fund").identifiers.all.should ==
|
33
33
|
[DbStore::Identifier.new("trade_id" => 12, "version" => 1)]
|
34
34
|
end
|
35
35
|
end
|
@@ -41,14 +41,14 @@ describe "Wherever" do
|
|
41
41
|
it 'inserts a record for each key combination' do
|
42
42
|
wherever.add({"settled" => 100, "unsettled" => 0}, options)
|
43
43
|
|
44
|
-
wherever.get_key_store("fund").datasets.should ==
|
44
|
+
wherever.get_key_store("fund").datasets.all.should ==
|
45
45
|
[DbStore::Dataset.new("values" => {"unsettled" => 0, "settled" => 100}, "fund_id" => 2)]
|
46
|
-
wherever.get_key_store("fund").identifiers.should ==
|
46
|
+
wherever.get_key_store("fund").identifiers.all.should ==
|
47
47
|
[DbStore::Identifier.new("trade_id" => 12, "version" => 1)]
|
48
48
|
|
49
|
-
wherever.get_key_store("security").datasets.should ==
|
49
|
+
wherever.get_key_store("security").datasets.all.should ==
|
50
50
|
[DbStore::Dataset.new("values" => {"unsettled" => 0, "settled" => 100}, "security_id" => 4)]
|
51
|
-
wherever.get_key_store("security").identifiers.should ==
|
51
|
+
wherever.get_key_store("security").identifiers.all.should ==
|
52
52
|
[DbStore::Identifier.new("trade_id" => 12, "version" => 1)]
|
53
53
|
end
|
54
54
|
end
|
@@ -61,19 +61,19 @@ describe "Wherever" do
|
|
61
61
|
it 'inserts a record for each key combination' do
|
62
62
|
wherever.add({"settled" => 100, "unsettled" => 0}, options)
|
63
63
|
|
64
|
-
wherever.get_key_store("fund").datasets.should ==
|
64
|
+
wherever.get_key_store("fund").datasets.all.should ==
|
65
65
|
[DbStore::Dataset.new("values" => {"unsettled" => 0, "settled" => 100}, "fund_id" => 2)]
|
66
|
-
wherever.get_key_store("fund").identifiers.should ==
|
66
|
+
wherever.get_key_store("fund").identifiers.all.should ==
|
67
67
|
[DbStore::Identifier.new("trade_id" => 12, "version" => 1)]
|
68
68
|
|
69
|
-
wherever.get_key_store("security").datasets.should ==
|
69
|
+
wherever.get_key_store("security").datasets.all.should ==
|
70
70
|
[DbStore::Dataset.new("values" => {"unsettled" => 0, "settled" => 100}, "security_id" => 4)]
|
71
|
-
wherever.get_key_store("security").identifiers.should ==
|
71
|
+
wherever.get_key_store("security").identifiers.all.should ==
|
72
72
|
[DbStore::Identifier.new("trade_id" => 12, "version" => 1)]
|
73
73
|
|
74
|
-
wherever.get_key_store("fund", "security").datasets.should ==
|
74
|
+
wherever.get_key_store("fund", "security").datasets.all.should ==
|
75
75
|
[DbStore::Dataset.new("fund_id" => 2, "security_id" => 4, "values" => {"unsettled" => 0, "settled" => 100})]
|
76
|
-
wherever.get_key_store("fund", "security").identifiers.should ==
|
76
|
+
wherever.get_key_store("fund", "security").identifiers.all.should ==
|
77
77
|
[DbStore::Identifier.new("trade_id" => 12, "version" => 1)]
|
78
78
|
end
|
79
79
|
end
|
@@ -91,7 +91,7 @@ describe "Wherever" do
|
|
91
91
|
it 'add the change' do
|
92
92
|
wherever.add({"settled" => 110, "unsettled" => 0}, options_second)
|
93
93
|
|
94
|
-
wherever.get_key_store("unique").datasets.should ==
|
94
|
+
wherever.get_key_store("unique").datasets.all.should ==
|
95
95
|
[DbStore::Dataset.new("fund_id" => 2, "trade_id" => 12, "version" => 1, "values" => {"unsettled" => 0, "settled" => 100}),
|
96
96
|
DbStore::Dataset.new("fund_id" => 2, "trade_id" => 12, "version" => 2, "values" => {"unsettled" => 0, "settled" => 10})]
|
97
97
|
end
|
@@ -101,7 +101,7 @@ describe "Wherever" do
|
|
101
101
|
it 'updates the record' do
|
102
102
|
wherever.add({"settled" => 110, "unsettled" => 0}, options_second)
|
103
103
|
|
104
|
-
wherever.get_key_store("identifier").datasets.should ==
|
104
|
+
wherever.get_key_store("identifier").datasets.all.should ==
|
105
105
|
[DbStore::Dataset.new("fund_id" => 2, "trade_id" => 12, "version" => 2, "values" => {"unsettled" => 0, "settled" => 110})]
|
106
106
|
end
|
107
107
|
end
|
@@ -110,9 +110,9 @@ describe "Wherever" do
|
|
110
110
|
context 'with a single key' do
|
111
111
|
it 'inserts a record' do
|
112
112
|
wherever.add({"settled" => 110, "unsettled" => 0}, options_second)
|
113
|
-
wherever.get_key_store("fund").datasets.should ==
|
114
|
-
[DbStore::Dataset.new("values"
|
115
|
-
wherever.get_key_store("fund").identifiers.should ==
|
113
|
+
wherever.get_key_store("fund").datasets.all.should ==
|
114
|
+
[DbStore::Dataset.new("values" => {"unsettled" => 0, "settled" => 110}, "fund_id" => 2)]
|
115
|
+
wherever.get_key_store("fund").identifiers.all.should ==
|
116
116
|
[DbStore::Identifier.new("trade_id" => 12, "version" => 2)]
|
117
117
|
end
|
118
118
|
end
|
@@ -19,12 +19,12 @@ describe Wherever, 'with a custom grouping' do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'the identifier record' do
|
22
|
-
wherever.get_key_store("identifier").datasets.should ==
|
22
|
+
wherever.get_key_store("identifier").datasets.all.should ==
|
23
23
|
[DbStore::Dataset.new("values" => {"unsettled" => -250, "settled" => 100}, "fund_id" => 2, "version" => 1, "trade_id" => 12)]
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'the grouped record' do
|
27
|
-
wherever.get_key_store("fund").datasets.should ==
|
27
|
+
wherever.get_key_store("fund").datasets.all.should ==
|
28
28
|
[DbStore::Dataset.new("values" => {"unsettled" => -250, "settled" => 100}, "fund_id" => 2)]
|
29
29
|
end
|
30
30
|
end
|
@@ -9,14 +9,26 @@ describe "Wherever" do
|
|
9
9
|
context 'when a single element key' do
|
10
10
|
let(:store) { wherever.get_key_store("fund") }
|
11
11
|
it 'sets the class name' do
|
12
|
-
store.
|
12
|
+
store.identifiers.to_s.should == "DbStore::CURRENT_FUND_IDENTIFIER"
|
13
|
+
store.datasets.to_s.should == "DbStore::CURRENT_FUND_DATASET"
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'sets the table' do
|
17
|
+
store.identifiers.collection_name.should == "current_fund_identifier"
|
18
|
+
store.datasets.collection_name.should == "current_fund_dataset"
|
13
19
|
end
|
14
20
|
end
|
15
21
|
|
16
22
|
context 'when a multiple element keys' do
|
17
23
|
let(:store) { wherever.get_key_store("fund", "security") }
|
18
24
|
it 'sets the class name' do
|
19
|
-
store.
|
25
|
+
store.identifiers.to_s.should == "DbStore::CURRENT_FUND_SECURITY_IDENTIFIER"
|
26
|
+
store.datasets.to_s.should == "DbStore::CURRENT_FUND_SECURITY_DATASET"
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'sets the table' do
|
30
|
+
store.identifiers.collection_name.should == "current_fund_security_identifier"
|
31
|
+
store.datasets.collection_name.should == "current_fund_security_dataset"
|
20
32
|
end
|
21
33
|
end
|
22
34
|
end
|
data/spec/wherever/mark_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe Wherever, 'mark a time point' do
|
|
4
4
|
let(:create_options) { ["keys" => keys, "database" => 'wherever_test', "key_groups" => key_groups, "key" => "trade_id"] }
|
5
5
|
let(:wherever) {
|
6
6
|
Wherever.new(*create_options) do |values, data, record, keys|
|
7
|
-
price = wherever.get_price(
|
7
|
+
price = wherever.get_price('current', record)
|
8
8
|
if keys.include?("security_id")
|
9
9
|
values["position"] += data["position"] if data
|
10
10
|
values["price"] = price
|
@@ -26,17 +26,17 @@ describe Wherever, 'mark a time point' do
|
|
26
26
|
wherever.create_lookup('price', ["security_id"])
|
27
27
|
wherever.set_price('20111029_01', {4 => 12.5})
|
28
28
|
wherever.add({"position" => 100}, options_one)
|
29
|
-
wherever.mark('
|
29
|
+
wherever.mark('COB_20111009')
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'can retrieve data via marker name' do
|
33
|
-
wherever.get({"fund_id" => 2}, '
|
33
|
+
wherever.get({"fund_id" => 2}, 'COB_20111009').should == {"trade_value" => 1250}
|
34
34
|
end
|
35
35
|
|
36
36
|
context 'adding new record' do
|
37
37
|
it 'does not change marker record' do
|
38
38
|
wherever.add({"position" => 100}, options_two)
|
39
|
-
wherever.get({"fund_id" => 2}, '
|
39
|
+
wherever.get({"fund_id" => 2}, 'COB_20111009').should == {"trade_value" => 1250}
|
40
40
|
wherever.get({"fund_id" => 2}).should == {"trade_value" => 2500}
|
41
41
|
end
|
42
42
|
end
|
@@ -44,7 +44,7 @@ describe Wherever, 'mark a time point' do
|
|
44
44
|
context 'adding price data' do
|
45
45
|
it 'does not change marker record' do
|
46
46
|
wherever.set_price('20111029_02', {4 => 13.5})
|
47
|
-
wherever.get({"fund_id" => 2}, '
|
47
|
+
wherever.get({"fund_id" => 2}, 'COB_20111009').should == {"trade_value" => 1250}
|
48
48
|
wherever.get({"fund_id" => 2}).should == {"trade_value" => 1350}
|
49
49
|
end
|
50
50
|
end
|
@@ -4,7 +4,7 @@ describe Wherever, 'using lookup in grouping calculation' do
|
|
4
4
|
let(:create_options) { ["keys" => keys, "database" => 'wherever_test', "key_groups" => key_groups, "key" => "trade_id"] }
|
5
5
|
let(:wherever) {
|
6
6
|
Wherever.new(*create_options) do |values, data, record, keys|
|
7
|
-
price = wherever.get_price(
|
7
|
+
price = wherever.get_price('current', record)
|
8
8
|
if keys.include?("security_id")
|
9
9
|
values["position"] += data["position"] if data
|
10
10
|
values["price"] = price
|
@@ -32,25 +32,25 @@ describe Wherever, 'using lookup in grouping calculation' do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'on identifier record' do
|
35
|
-
wherever.get_key_store("identifier").datasets.should ==
|
35
|
+
wherever.get_key_store("identifier").datasets.all.should ==
|
36
36
|
[DbStore::Dataset.new("values" => {"position" => 100, "price" => 12.5, "trade_value" => 1250},
|
37
37
|
"trade_id" => 12, "version" => 1, "fund_id" => 2, "security_id" => 4)]
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'on fund record' do
|
41
|
-
wherever.get_key_store("fund").datasets.should ==
|
41
|
+
wherever.get_key_store("fund").datasets.all.should ==
|
42
42
|
[DbStore::Dataset.new("values" => {"trade_value" => 1250}, "fund_id" => 2)]
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'on fund record with trade edit' do
|
46
46
|
wherever.add({"position" => 110}, options_two)
|
47
|
-
wherever.get_key_store("fund").datasets.should ==
|
47
|
+
wherever.get_key_store("fund").datasets.all.should ==
|
48
48
|
[DbStore::Dataset.new("values" => {"trade_value" => 1375}, "fund_id" => 2)]
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'on fund record with two trades' do
|
52
52
|
wherever.add({"position" => 200}, options_three)
|
53
|
-
wherever.get_key_store("fund").datasets.should ==
|
53
|
+
wherever.get_key_store("fund").datasets.all.should ==
|
54
54
|
[DbStore::Dataset.new("values" => {"trade_value" => 3750}, "fund_id" => 2)]
|
55
55
|
end
|
56
56
|
end
|
@@ -70,7 +70,7 @@ describe Wherever, 'using lookup in grouping calculation' do
|
|
70
70
|
it 'on identifier record' do
|
71
71
|
wherever.create_lookup('price', ["security_id"])
|
72
72
|
wherever.set_price('current', {4 => 12.5})
|
73
|
-
wherever.get_key_store("identifier").datasets.should ==
|
73
|
+
wherever.get_key_store("identifier").datasets.all.should ==
|
74
74
|
[DbStore::Dataset.new("values" => {"position" => 100, "price" => 12.5, "trade_value" => 1250},
|
75
75
|
"trade_id" => 12, "version" => 1, "fund_id" => 2, "security_id" => 4)]
|
76
76
|
end
|
@@ -78,7 +78,7 @@ describe Wherever, 'using lookup in grouping calculation' do
|
|
78
78
|
it 'on fund record' do
|
79
79
|
wherever.create_lookup('price', ["security_id"])
|
80
80
|
wherever.set_price('current', {4 => 12.5})
|
81
|
-
wherever.get_key_store("fund").datasets.should ==
|
81
|
+
wherever.get_key_store("fund").datasets.all.should ==
|
82
82
|
[DbStore::Dataset.new("values" => {"trade_value" => 1250}, "fund_id" => 2)]
|
83
83
|
end
|
84
84
|
|
@@ -86,14 +86,14 @@ describe Wherever, 'using lookup in grouping calculation' do
|
|
86
86
|
wherever.add({"position" => 110}, options_two)
|
87
87
|
wherever.create_lookup('price', ["security_id"])
|
88
88
|
wherever.set_price('current', {4 => 12.5})
|
89
|
-
wherever.get_key_store("fund").datasets.should ==
|
89
|
+
wherever.get_key_store("fund").datasets.all.should ==
|
90
90
|
[DbStore::Dataset.new("values" => {"trade_value" => 1375}, "fund_id" => 2)]
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'on fund record with two trades' do
|
94
94
|
wherever.add({"position" => 200}, options_three)
|
95
95
|
wherever.set_price('current', {4 => 12.5})
|
96
|
-
wherever.get_key_store("fund").datasets.should ==
|
96
|
+
wherever.get_key_store("fund").datasets.all.should ==
|
97
97
|
[DbStore::Dataset.new("values" => {"trade_value" => 3750}, "fund_id" => 2)]
|
98
98
|
end
|
99
99
|
end
|
data/wherever-positions.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{wherever-positions}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
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"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-11-02}
|
13
13
|
s.description = %q{Allow Store of positions by multiple keys with teh option to mark specific points in time for use later}
|
14
14
|
s.email = %q{dw_henry@yahoo.com.au}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -36,9 +36,7 @@ Gem::Specification.new do |s|
|
|
36
36
|
"lib/wherever/db_store/dataset.rb",
|
37
37
|
"lib/wherever/db_store/identifier.rb",
|
38
38
|
"lib/wherever/db_store/lookup.rb",
|
39
|
-
"lib/wherever/db_store/marker.rb",
|
40
39
|
"lib/wherever/db_store/record_matcher.rb",
|
41
|
-
"lib/wherever/db_store/store.rb",
|
42
40
|
"lib/wherever/wherever.rb",
|
43
41
|
"lib/wherever/wherever/accessors.rb",
|
44
42
|
"lib/wherever/wherever/adder.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: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 2
|
9
8
|
- 3
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- David Henry
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-11-02 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -179,9 +179,7 @@ files:
|
|
179
179
|
- lib/wherever/db_store/dataset.rb
|
180
180
|
- lib/wherever/db_store/identifier.rb
|
181
181
|
- lib/wherever/db_store/lookup.rb
|
182
|
-
- lib/wherever/db_store/marker.rb
|
183
182
|
- lib/wherever/db_store/record_matcher.rb
|
184
|
-
- lib/wherever/db_store/store.rb
|
185
183
|
- lib/wherever/wherever.rb
|
186
184
|
- lib/wherever/wherever/accessors.rb
|
187
185
|
- lib/wherever/wherever/adder.rb
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module DbStore
|
2
|
-
class Marker
|
3
|
-
include Mongoid::Document
|
4
|
-
embeds_many :stores, :class_name => 'DbStore::Store'
|
5
|
-
field :name, :type => String
|
6
|
-
field :price, :type => String
|
7
|
-
|
8
|
-
def self.find_by_name(name)
|
9
|
-
find_or_create_by({:name => name})
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
module DbStore
|
2
|
-
class Store
|
3
|
-
include Mongoid::Document
|
4
|
-
embedded_in :marker, :inverse_of => :stores, :class_name => 'DbStore::Marker'
|
5
|
-
embeds_many :datasets, :class_name => 'DbStore::Dataset'
|
6
|
-
embeds_many :identifiers, :class_name => 'DbStore::Identifier'
|
7
|
-
field :key, :type => Array
|
8
|
-
end
|
9
|
-
end
|