wherever-positions 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.5
1
+ 0.4.6
@@ -0,0 +1,51 @@
1
+ module MethodLogging
2
+ class << self
3
+ def add(klass)
4
+ klass::LogMethods.each do |method|;
5
+ unless klass.instance_methods.include?("#{method}_without_logging")
6
+ add_method(klass, method)
7
+ end
8
+ end
9
+ end
10
+
11
+ def add_method(klass, method)
12
+ klass.send :alias_method, :"#{method}_without_logging", method
13
+ klass.class_eval <<-END
14
+ def #{method}_with_logging(*args)
15
+ MethodLogging.log("Called: #{method}(\#{MethodLogging.strify(*args)})")
16
+ #{method}_without_logging(*args)
17
+ end
18
+ END
19
+ klass.send :alias_method, method, :"#{method}_with_logging"
20
+ end
21
+
22
+ def log(string)
23
+ File.open("log/method.log", 'a') do |f|
24
+ f.puts string
25
+ end
26
+ end
27
+
28
+ def strify(*args)
29
+ args.map do |arg|
30
+ case arg.class.to_s
31
+ when "String"
32
+ %Q{"#{arg}"}
33
+ when "Fixnum", "Integer", "Float"
34
+ arg.to_s
35
+ when "Hash"
36
+ string = arg.map do |k, v|
37
+ "#{strify(k)} => #{strify(v)}"
38
+ end.join(', ')
39
+ "{#{string}}"
40
+ when "Array"
41
+ string = arg.map do |v|
42
+ string(v)
43
+ end.join(', ')
44
+ "[#{string}]"
45
+ else
46
+ "(#{arg.class} - #{arg})"
47
+ end
48
+ end.join(', ')
49
+ end
50
+ end
51
+ end
@@ -1,5 +1,6 @@
1
1
  class Wherever
2
2
  module Accessors
3
+ protected
3
4
  def get_key_store(*keys)
4
5
  DbStore.new_store(get_marker(keys), keys)
5
6
  end
@@ -9,6 +9,7 @@ class Wherever
9
9
  end
10
10
  end
11
11
 
12
+ protected
12
13
  def find
13
14
  identifier_set.datasets.where(identifier_key).first
14
15
  end
@@ -20,6 +20,8 @@ class Wherever
20
20
  lookup_data.values[value_key] || 0
21
21
  end
22
22
  end
23
+ MethodLogging.add_method(self.class, "set_#{name}")
24
+ MethodLogging.add_method(self.class, "get_#{name}")
23
25
  end
24
26
 
25
27
  protected
@@ -11,6 +11,7 @@ class Wherever
11
11
  set_price_lookup('price', nil, [{'marker' => name}])
12
12
  end
13
13
 
14
+ protected
14
15
  def copy_collections(from_collection, to_collection)
15
16
  copy_function = "db.#{from_collection}.find().forEach( function(x){db.#{to_collection}.insert(x)} )"
16
17
  if Mongoid::Config.respond_to?(:instance)
@@ -10,6 +10,8 @@ class Wherever
10
10
  include Mark
11
11
  attr_reader :config, :marker
12
12
 
13
+ LogMethods = [:add, :get, :get_key_store, :mark]
14
+
13
15
  def initialize(options={}, &grouping)
14
16
  @config = Configure.new(options)
15
17
  @marker = options[:marker] || 'current'
@@ -22,5 +24,9 @@ class Wherever
22
24
  end
23
25
  end
24
26
  end
27
+
28
+ if options['method_logging']
29
+ MethodLogging.add(self.class)
30
+ end
25
31
  end
26
32
  end
data/lib/wherever.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'mongo'
2
2
  require 'mongoid'
3
3
  require 'string_helper'
4
+ require 'method_logging'
4
5
  require 'wherever/wherever/accessors'
5
6
  require 'wherever/wherever/adder'
6
7
  require 'wherever/wherever/getter'
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Wherever", 'method logging' do
4
+ let(:wherever) { Wherever.new("method_logging" => true, "keys" => keys, "database" => 'wherever_test', "key_groups" => key_groups, "key" => "trade_id") }
5
+ let(:keys) { ["fund"] }
6
+ let(:key_groups) { nil }
7
+ let(:options) { {"unique" => {"trade_id" => 12, "version" => 1}, "keys" => {"fund_id" => 2}} }
8
+ let(:file) { mock(:file_io) }
9
+ before do
10
+ MethodLogging.stub(:log => true)
11
+ end
12
+ context 'the add method' do
13
+
14
+ it 'is logged to file' do
15
+ call_string = %Q{Called: add({"unsettled" => 0, "settled" => 100}, {"keys" => {"fund_id" => 2}, "unique" => {"trade_id" => 12, "version" => 1}})}
16
+ MethodLogging.should_receive(:log).with(call_string)
17
+ wherever.add({"settled" => 100, "unsettled" => 0}, options)
18
+ end
19
+ end
20
+
21
+ context 'the get key method' do
22
+ it 'is logged to file' do
23
+ call_string = %Q{Called: get_key_store("identifier")}
24
+ MethodLogging.should_receive(:log).with(call_string)
25
+ wherever.get_key_store("identifier").datasets.all
26
+ end
27
+ end
28
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{wherever-positions}
8
- s.version = "0.4.5"
8
+ s.version = "0.4.6"
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-11-05}
12
+ s.date = %q{2011-11-07}
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 = [
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  "features/step_definitions/wherever_steps.rb",
30
30
  "features/support/env.rb",
31
31
  "features/wherever.feature",
32
+ "lib/method_logging.rb",
32
33
  "lib/monkeypatch_for_mongoid_1.9.rb",
33
34
  "lib/string_helper.rb",
34
35
  "lib/wherever.rb",
@@ -44,6 +45,7 @@ Gem::Specification.new do |s|
44
45
  "lib/wherever/wherever/getter.rb",
45
46
  "lib/wherever/wherever/lookup.rb",
46
47
  "lib/wherever/wherever/mark.rb",
48
+ "spec/method_logging_spec.rb",
47
49
  "spec/spec_helper.rb",
48
50
  "spec/wherever/adder_spec.rb",
49
51
  "spec/wherever/custom_grouping_spec.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: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 5
10
- version: 0.4.5
9
+ - 6
10
+ version: 0.4.6
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-11-05 00:00:00 +00:00
18
+ date: 2011-11-07 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -172,6 +172,7 @@ files:
172
172
  - features/step_definitions/wherever_steps.rb
173
173
  - features/support/env.rb
174
174
  - features/wherever.feature
175
+ - lib/method_logging.rb
175
176
  - lib/monkeypatch_for_mongoid_1.9.rb
176
177
  - lib/string_helper.rb
177
178
  - lib/wherever.rb
@@ -187,6 +188,7 @@ files:
187
188
  - lib/wherever/wherever/getter.rb
188
189
  - lib/wherever/wherever/lookup.rb
189
190
  - lib/wherever/wherever/mark.rb
191
+ - spec/method_logging_spec.rb
190
192
  - spec/spec_helper.rb
191
193
  - spec/wherever/adder_spec.rb
192
194
  - spec/wherever/custom_grouping_spec.rb