gexp 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,11 +23,9 @@ module Gexp
23
23
  protected
24
24
 
25
25
  def load_object
26
- if @params[:object]
27
- #require 'pry'
28
- #binding.pry
29
- label = @params[:object].keys.first
30
- id = @params[:object].values.first
26
+ if @params[:objects]
27
+ label = @params[:objects].keys.first
28
+ id = @params[:objects].values.first
31
29
  @object = Gexp.label_to_class(label).find(id)
32
30
  else
33
31
  raise "Can't find object params"
@@ -14,7 +14,7 @@ module Gexp
14
14
  end
15
15
 
16
16
  def build_command(command_param = {})
17
- Gexp::Command.new(command_param)
17
+ Gexp::Command::Object.new(command_param)
18
18
  end
19
19
 
20
20
  def fill(request = nil)
@@ -22,11 +22,8 @@ module Gexp
22
22
  end
23
23
 
24
24
  def receive
25
- @stack.map do |command|
26
- Gexp::Mongoid::Transaction.with do |context|
27
- command.perform
28
- end
29
- end
25
+ raise NotImplementedError.new \
26
+ "Abstract receiver class"
30
27
  end
31
28
 
32
29
  end
@@ -0,0 +1,15 @@
1
+ module Gexp
2
+ class Receiver
3
+ class Example < self
4
+
5
+ def receive
6
+ @stack.map do |hash, command|
7
+ # Start transaction
8
+ command.perform
9
+ # finish transaction
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Gexp
2
+ class Receiver
3
+ class Mongoid < self
4
+
5
+ def receive
6
+ @stack.map do |command|
7
+ Gexp::Mongoid::Transaction.with do |context|
8
+ command.perform
9
+ end
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Gexp
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -13,13 +13,13 @@ describe Gexp::Command::Object do
13
13
  :create_at => 123456789.012,
14
14
  :commands => [{
15
15
  # У себя на карте
16
- :event => :pick,
17
- :stage => { x: 100, y: 200 },
18
- :rewards => { energy: -1, exp: 5 },
19
- :timestamp => 123456789.012,
20
- :object => { 'item_example' => '55a55' },
16
+ :event => :pick,
17
+ :stage => { x: 100, y: 200 },
18
+ :rewards => { energy: -1, exp: 5 },
19
+ :timestamp => 123456789.012,
20
+ :objects => { 'item_example' => '55a55' },
21
21
  :transition => { :builded => :builded },
22
- :seed => 532434234,
22
+ :seed => 532434234,
23
23
  }]
24
24
  }
25
25
  })
@@ -46,7 +46,7 @@ describe Gexp::Command::Object do
46
46
 
47
47
  it "Нельзя (так просто взять и) создать команду без параметра-объекта" do
48
48
  params = @request[:params][:commands].first
49
- params.delete(:object)
49
+ params.delete(:objects)
50
50
  lambda {
51
51
  @command = Gexp::Command::Object.new params
52
52
  }.should raise_error Regexp.new("Can't find object")
@@ -16,7 +16,7 @@ describe Gexp::Command::Stack do
16
16
  :stage => { x: 100, y: 200 },
17
17
  :rewards => { energy: -1, exp: 5 },
18
18
  :timestamp => 123456789.012,
19
- :objects => [{ 'item.stage.house' => '50c12939584aa5488a000001' }],
19
+ :objects => { 'item_example' => '50c12939584aa5488a000001' },
20
20
  :transition => { :builded => :builded },
21
21
  :timestamp => 123456789.010,
22
22
  :seed => 532434234,
@@ -26,21 +26,21 @@ describe Gexp::Command::Stack do
26
26
  :uid => '<friend_uid>',
27
27
  :rewards => { energy: -1, exp: 5 },
28
28
  :timestamp => 123456789.012,
29
- :objects => [{ 'item.stage.house' => '50c12939584aa5488a000001' }],
29
+ :objects => { 'item_example' => '50c12939584aa5488a000002' },
30
30
  :transition => { :builded => :builded },
31
31
  :timestamp => 123456789.011,
32
32
  :seed => 532434234,
33
33
  }, { # создание здания
34
34
  :event => :create,
35
35
  :stage => { x: 100, y: 200 },
36
- :objects => [{ 'item.stage.house' => '50c12939584aa5488a000001' }],
36
+ :objects => { 'item_example' => '50c12939584aa5488a000003' },
37
37
  :reward => { gold: -100 },
38
38
  :timestamp => 123456789.012,
39
39
  :seed => 532434234,
40
40
  }, { # создание контракта
41
41
  :event => :pick,
42
42
  :stage => { x: 100, y: 200 },
43
- :objects => [{ 'item.stage.house' => '50c12939584aa5488a000001' }],
43
+ :objects => { 'item_example' => '50c12939584aa5488a000004' },
44
44
  :timestamp => 123456789.013,
45
45
  :seed => 532412334,
46
46
  },
@@ -49,7 +49,18 @@ describe Gexp::Command::Stack do
49
49
  })
50
50
  }
51
51
 
52
+ let(:item1) { ItemExample.new }
53
+ let(:item2) { ItemExample.new }
54
+ let(:item3) { ItemExample.new }
55
+ let(:item4) { ItemExample.new }
56
+
52
57
  before do
58
+
59
+ stub(ItemExample).find('50c12939584aa5488a000001') { item1 }
60
+ stub(ItemExample).find('50c12939584aa5488a000002') { item2 }
61
+ stub(ItemExample).find('50c12939584aa5488a000003') { item3 }
62
+ stub(ItemExample).find('50c12939584aa5488a000004') { item4 }
63
+
53
64
  @user = UserExample.new
54
65
  @request = request
55
66
  end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
3
+
4
+ describe Gexp::Receiver do
5
+
6
+ let(:receiver_class) { Gexp::Receiver::Example }
7
+ let(:user) { UserExample.new }
8
+ let(:item_id) { 1 }
9
+ let(:item) { ItemExample.new }
10
+ let(:request) do
11
+ HashWithIndifferentAccess.new({
12
+ :params => {
13
+ :sended_at => 123456789.012,
14
+ :create_at => 123456789.012,
15
+ :commands => [{
16
+ # У себя на карте
17
+ :event => :pick,
18
+ :stage => { x: 100, y: 200 },
19
+ :rewards => { energy: -1, exp: 5 },
20
+ :timestamp => 123456789.012,
21
+ :objects => { 'item_example' => item_id },
22
+ :transition => { :builded => :builded },
23
+ :seed => 532434234,
24
+ }]
25
+ }
26
+ })
27
+ end
28
+
29
+ let(:subject) do
30
+ receiver_class.new(user, request)
31
+ end
32
+
33
+ before do
34
+ stub(ItemExample).find(item_id) { item }
35
+ end
36
+
37
+ context "Успешная обработка комманды" do
38
+
39
+ it "должна пройти без ошибок" do
40
+ #lambda {
41
+ subject.receive
42
+ #}.should_not raise_error
43
+ end
44
+
45
+ end
46
+
47
+
48
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gexp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-17 00:00:00.000000000 Z
12
+ date: 2013-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2194326880 !ruby/object:Gem::Requirement
16
+ requirement: &70143297987720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2194326880
24
+ version_requirements: *70143297987720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rr
27
- requirement: &2194325600 !ruby/object:Gem::Requirement
27
+ requirement: &70143297986680 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2194325600
35
+ version_requirements: *70143297986680
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &2194320360 !ruby/object:Gem::Requirement
38
+ requirement: &70143297985980 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2194320360
46
+ version_requirements: *70143297985980
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: pry
49
- requirement: &2194317020 !ruby/object:Gem::Requirement
49
+ requirement: &70143297984780 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2194317020
57
+ version_requirements: *70143297984780
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: state_machine
60
- requirement: &2194314860 !ruby/object:Gem::Requirement
60
+ requirement: &70143297983800 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2194314860
68
+ version_requirements: *70143297983800
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activesupport
71
- requirement: &2194312320 !ruby/object:Gem::Requirement
71
+ requirement: &70143297982600 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2194312320
79
+ version_requirements: *70143297982600
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: bson
82
- requirement: &2194309220 !ruby/object:Gem::Requirement
82
+ requirement: &70143297980680 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - =
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 1.8.0
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2194309220
90
+ version_requirements: *70143297980680
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: bson_ext
93
- requirement: &2194307800 !ruby/object:Gem::Requirement
93
+ requirement: &70143297979760 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - =
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 1.8.0
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2194307800
101
+ version_requirements: *70143297979760
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: mongo
104
- requirement: &2194306020 !ruby/object:Gem::Requirement
104
+ requirement: &70143297978700 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 1.8.0
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *2194306020
112
+ version_requirements: *70143297978700
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: mongoid
115
- requirement: &2194191400 !ruby/object:Gem::Requirement
115
+ requirement: &70143297977520 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ~>
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: 3.0.0
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *2194191400
123
+ version_requirements: *70143297977520
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: money-mongoid
126
- requirement: &2194186120 !ruby/object:Gem::Requirement
126
+ requirement: &70143297976520 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - =
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: 0.1.2
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *2194186120
134
+ version_requirements: *70143297976520
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: mongoid-rspec
137
- requirement: &2194181460 !ruby/object:Gem::Requirement
137
+ requirement: &70143297975140 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - =
@@ -142,7 +142,7 @@ dependencies:
142
142
  version: 1.4.5
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *2194181460
145
+ version_requirements: *70143297975140
146
146
  description: Gexp - comand hadlers
147
147
  email:
148
148
  - kazantsev.nickolay@gmail.com
@@ -176,6 +176,8 @@ files:
176
176
  - lib/gexp/mongoid/transaction.rb
177
177
  - lib/gexp/object.rb
178
178
  - lib/gexp/receiver.rb
179
+ - lib/gexp/receiver/example.rb
180
+ - lib/gexp/receiver/mongoid.rb
179
181
  - lib/gexp/state_definition.rb
180
182
  - lib/gexp/state_definition/state_machine.rb
181
183
  - lib/gexp/version.rb
@@ -191,6 +193,7 @@ files:
191
193
  - spec/gexp/handler/transition/builder_spec.rb
192
194
  - spec/gexp/handler/transition_spec.rb
193
195
  - spec/gexp/mongoid/transaction_spec.rb
196
+ - spec/gexp/receiver_spec.rb
194
197
  - spec/gexp/state_definition/state_machine_spec.rb
195
198
  - spec/spec_helper.rb
196
199
  homepage: http://github.com/realb0t/gexp
@@ -205,12 +208,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
205
208
  - - ! '>='
206
209
  - !ruby/object:Gem::Version
207
210
  version: '0'
211
+ segments:
212
+ - 0
213
+ hash: -3174103148992928154
208
214
  required_rubygems_version: !ruby/object:Gem::Requirement
209
215
  none: false
210
216
  requirements:
211
217
  - - ! '>='
212
218
  - !ruby/object:Gem::Version
213
219
  version: '0'
220
+ segments:
221
+ - 0
222
+ hash: -3174103148992928154
214
223
  requirements: []
215
224
  rubyforge_project: gexp
216
225
  rubygems_version: 1.8.5
@@ -230,5 +239,6 @@ test_files:
230
239
  - spec/gexp/handler/transition/builder_spec.rb
231
240
  - spec/gexp/handler/transition_spec.rb
232
241
  - spec/gexp/mongoid/transaction_spec.rb
242
+ - spec/gexp/receiver_spec.rb
233
243
  - spec/gexp/state_definition/state_machine_spec.rb
234
244
  - spec/spec_helper.rb