gexp 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  lib = File.expand_path('../lib', __FILE__)
3
+
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'gexp/version'
5
6
 
@@ -22,6 +23,7 @@ Gem::Specification.new do |gem|
22
23
  gem.add_development_dependency "rspec"
23
24
  gem.add_development_dependency "rr"
24
25
  gem.add_development_dependency "rake"
26
+ gem.add_development_dependency "pry"
25
27
  gem.add_development_dependency "state_machine"
26
28
  gem.add_development_dependency "activesupport"
27
29
  gem.add_development_dependency 'bson', '= 1.8.0'
@@ -29,4 +31,5 @@ Gem::Specification.new do |gem|
29
31
  gem.add_development_dependency 'mongo', '~> 1.8.0'
30
32
  gem.add_development_dependency "mongoid", "~> 3.0.0"
31
33
  gem.add_development_dependency 'money-mongoid', '= 0.1.2'
34
+ gem.add_development_dependency "mongoid-rspec", '= 1.4.5'
32
35
  end
@@ -0,0 +1,68 @@
1
+ class ItemExample
2
+ class << self
3
+ def inherited(sub)
4
+ sub.instance_eval do
5
+ include Gexp::Object
6
+ end
7
+ end
8
+
9
+ def register
10
+ @register ||= {}
11
+
12
+ if @register.empty?
13
+ register = Configuration.for 'register'
14
+ register.keys.each do |key|
15
+ @register[key] = Configuration.for(key).to_hash
16
+ end
17
+ end
18
+
19
+ @register
20
+ end
21
+
22
+ def reload_register!
23
+ @register = {}
24
+ end
25
+
26
+ end
27
+
28
+ attr_accessor :current_command
29
+
30
+ include Mongoid::Document
31
+
32
+ field :state, type: String, default: 'created'
33
+ field :uid, type: String
34
+ field :social_type_id, type: Integer
35
+
36
+ field :x, type: Integer, default: 0
37
+ field :y, type: Integer, default: 0
38
+
39
+ scope :with_class_and_uid, lambda { |klass, uid, social_type_id|
40
+ where(_type: klass, uid: uid, social_type_id: social_type_id)
41
+ }
42
+
43
+ # TODO: по возможности переделать на Mongoid::Observer или скрыть из конфига
44
+ def around_handlers(transition, &block)
45
+ self.check_handlers(transition)
46
+ self.before_event(transition)
47
+ #require 'pry'
48
+ #binding.pry
49
+ block.call
50
+ self.after_event(transition)
51
+ self.modify_handlers(transition)
52
+ rescue => e
53
+ raise
54
+ end
55
+
56
+ def before_event(transition)
57
+ end
58
+
59
+ def after_event(transition)
60
+ end
61
+
62
+ def check_handlers(transition)
63
+ end
64
+
65
+ def modify_handlers(transition)
66
+ end
67
+
68
+ end
@@ -0,0 +1,14 @@
1
+ class UserExample
2
+ include Mongoid::Document
3
+
4
+ field :energy, type: Integer
5
+ field :exp, type: Integer
6
+ field :exp_level, type: Integer
7
+
8
+ def max_energy
9
+ [ 10, 40, 50, 60, 80, 90, 100][self.exp_level || 0]
10
+ end
11
+
12
+ def after_change!(param)
13
+ end
14
+ end
@@ -14,3 +14,10 @@ module Gexp
14
14
  end
15
15
  end
16
16
  end
17
+
18
+ Dir["#{File.dirname(__FILE__)}/gexp/**/*.rb"].sort.each do |path|
19
+ require path
20
+ end
21
+
22
+ require "#{File.dirname(__FILE__)}/examples/user_example"
23
+ require "#{File.dirname(__FILE__)}/examples/item_example"
@@ -1,7 +1,11 @@
1
1
  # encoding: utf-8
2
+ require 'state_machine/core'
3
+
2
4
  module Gexp
3
5
  class Command
4
6
 
7
+ extend StateMachine::MacroMethods
8
+
5
9
  attr_accessor :errors
6
10
  attr_accessor :context
7
11
  attr_accessor :params
@@ -24,6 +24,8 @@ module Gexp
24
24
 
25
25
  def load_object
26
26
  if @params[:object]
27
+ #require 'pry'
28
+ #binding.pry
27
29
  label = @params[:object].keys.first
28
30
  id = @params[:object].values.first
29
31
  @object = Gexp.label_to_class(label).find(id)
@@ -1,4 +1,5 @@
1
1
  require 'singleton'
2
+ require 'mongoid'
2
3
 
3
4
  # Gexp::Mongoid::Transaction::Observer.started?
4
5
 
@@ -1,5 +1,5 @@
1
- require File.join(APP_ROOT, 'lib', 'gexp', 'state_definition')
2
- require File.join(APP_ROOT, 'lib', 'gexp', 'state_definition', 'state_machine')
1
+ require File.join('gexp', 'state_definition')
2
+ require File.join('gexp', 'state_definition', 'state_machine')
3
3
 
4
4
  module Gexp
5
5
  module Object
@@ -14,6 +14,10 @@ module Gexp
14
14
  state_aliases = [ :all, :any ]
15
15
 
16
16
  self.instance_eval do
17
+ unless self.methods.include?("state_machine")
18
+ extend ::StateMachine::MacroMethods
19
+ end
20
+
17
21
  state_machine initial: sm[:initial] do
18
22
 
19
23
  # Внешний хук от Handlers
@@ -1,3 +1,3 @@
1
1
  module Gexp
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -6,7 +6,7 @@ describe Gexp::Command::Object do
6
6
  context "Команда pick на объекте у себя в локации" do
7
7
 
8
8
  before do
9
- @user = Fabricate(:user)
9
+ @user = UserExample.new
10
10
  @request = HashWithIndifferentAccess.new({
11
11
  :params => {
12
12
  :sended_at => 123456789.012,
@@ -17,7 +17,7 @@ describe Gexp::Command::Object do
17
17
  :stage => { x: 100, y: 200 },
18
18
  :rewards => { energy: -1, exp: 5 },
19
19
  :timestamp => 123456789.012,
20
- :object => { 'item.stage.house' => '55a55' },
20
+ :object => { 'item_example' => '55a55' },
21
21
  :transition => { :builded => :builded },
22
22
  :seed => 532434234,
23
23
  }]
@@ -27,7 +27,7 @@ describe Gexp::Command::Object do
27
27
  @object = Object.new
28
28
  @context = Object.new
29
29
 
30
- stub(Item::Stage::House).find.with('55a55') { @object }
30
+ stub(ItemExample).find.with('55a55') { @object }
31
31
 
32
32
  lambda {
33
33
  @command = Gexp::Command::Object.new @request[:params][:commands].first
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper.rb')
2
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper.rb')
3
3
 
4
4
  describe Gexp::Command::Stack do
5
5
 
@@ -50,7 +50,7 @@ describe Gexp::Command::Stack do
50
50
  }
51
51
 
52
52
  before do
53
- @user = Fabricate(:user)
53
+ @user = UserExample.new
54
54
  @request = request
55
55
  end
56
56
 
@@ -1,12 +1,12 @@
1
1
  # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper.rb')
2
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
3
3
 
4
4
  describe Gexp::Command do
5
5
 
6
6
  context "Базовый функционал команды" do
7
7
 
8
8
  before do
9
- @user = Fabricate(:user)
9
+ @user = UserExample.new
10
10
  @request = HashWithIndifferentAccess.new({
11
11
  :params => {
12
12
  :event => :command_event,
@@ -1,10 +1,10 @@
1
1
  # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper.rb')
2
+ require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper.rb')
3
3
 
4
4
  describe Gexp::Handler::Check::Item do
5
5
 
6
6
  before do
7
- @user = User.new
7
+ @user = UserExample.new
8
8
  @object = Object.new
9
9
 
10
10
  subject.user = @user
@@ -1,10 +1,10 @@
1
1
  # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper.rb')
2
+ require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper.rb')
3
3
 
4
4
  describe Gexp::Handler::Check::Resources do
5
5
 
6
6
  before do
7
- @user = User.new
7
+ @user = UserExample.new
8
8
  @object = Object.new
9
9
 
10
10
  subject.user = @user
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper.rb')
2
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper.rb')
3
3
 
4
4
  describe Gexp::Handler::Check do
5
5
  end
@@ -1,11 +1,11 @@
1
1
  # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper.rb')
2
+ require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper.rb')
3
3
 
4
4
  describe Gexp::Handler::Modify::Resources do
5
5
 
6
6
  before do
7
- @user = User.new
8
- @object = Item.new
7
+ @user = UserExample.new
8
+ @object = ItemExample.new
9
9
 
10
10
  subject.user = @user
11
11
  subject.object = @object
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper.rb')
2
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper.rb')
3
3
 
4
4
  describe Gexp::Handler::Modify do
5
5
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper.rb')
2
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper.rb')
3
3
 
4
4
  describe Gexp::Handler::Producer do
5
5
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper.rb')
2
+ require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper.rb')
3
3
 
4
4
  describe Gexp::Handler::Transition::Builder do
5
5
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper.rb')
2
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper.rb')
3
3
 
4
4
  describe Gexp::Handler::Transition do
5
5
 
@@ -1,8 +1,10 @@
1
1
  # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper.rb')
2
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper.rb')
3
3
 
4
4
  describe Gexp::Mongoid::Transaction do
5
5
 
6
+ before { pending }
7
+
6
8
  context "Transactional Object" do
7
9
 
8
10
  before do
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper.rb')
2
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper.rb')
3
3
 
4
4
  describe Gexp::StateDefinition::StateMachine do
5
5
 
@@ -1,10 +1,13 @@
1
1
  require "bundler"
2
2
  require 'bundler/setup'
3
+ require 'state_machine/core'
3
4
  require 'gexp'
4
5
 
5
- RSpec.configure do |config|
6
- #config.treat_symbols_as_metadata_keys_with_true_values = true
7
- #config.run_all_when_everything_filtered = true
8
- #config.filter_run :focus
9
- config.mock_with :rr
6
+ ENV["MONGO_URL"] ||= ENV["MONGOHQ_URL"] || "mongodb://localhost/gexp_test"
7
+
8
+ RSpec.configure do |conf|
9
+ #conf.include Rack::Test::Methods
10
+ conf.include Mongoid::Matchers
11
+ conf.mock_with :rr
12
+ conf.color_enabled = true
10
13
  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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-03-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70131204742080 !ruby/object:Gem::Requirement
16
+ requirement: &2194326880 !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: *70131204742080
24
+ version_requirements: *2194326880
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rr
27
- requirement: &70131204741300 !ruby/object:Gem::Requirement
27
+ requirement: &2194325600 !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: *70131204741300
35
+ version_requirements: *2194325600
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70131204740800 !ruby/object:Gem::Requirement
38
+ requirement: &2194320360 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,21 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70131204740800
46
+ version_requirements: *2194320360
47
+ - !ruby/object:Gem::Dependency
48
+ name: pry
49
+ requirement: &2194317020 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2194317020
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: state_machine
49
- requirement: &70131204740380 !ruby/object:Gem::Requirement
60
+ requirement: &2194314860 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,10 +65,10 @@ dependencies:
54
65
  version: '0'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *70131204740380
68
+ version_requirements: *2194314860
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: activesupport
60
- requirement: &70131204739900 !ruby/object:Gem::Requirement
71
+ requirement: &2194312320 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ! '>='
@@ -65,10 +76,10 @@ dependencies:
65
76
  version: '0'
66
77
  type: :development
67
78
  prerelease: false
68
- version_requirements: *70131204739900
79
+ version_requirements: *2194312320
69
80
  - !ruby/object:Gem::Dependency
70
81
  name: bson
71
- requirement: &70131204732540 !ruby/object:Gem::Requirement
82
+ requirement: &2194309220 !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - =
@@ -76,10 +87,10 @@ dependencies:
76
87
  version: 1.8.0
77
88
  type: :development
78
89
  prerelease: false
79
- version_requirements: *70131204732540
90
+ version_requirements: *2194309220
80
91
  - !ruby/object:Gem::Dependency
81
92
  name: bson_ext
82
- requirement: &70131204731900 !ruby/object:Gem::Requirement
93
+ requirement: &2194307800 !ruby/object:Gem::Requirement
83
94
  none: false
84
95
  requirements:
85
96
  - - =
@@ -87,10 +98,10 @@ dependencies:
87
98
  version: 1.8.0
88
99
  type: :development
89
100
  prerelease: false
90
- version_requirements: *70131204731900
101
+ version_requirements: *2194307800
91
102
  - !ruby/object:Gem::Dependency
92
103
  name: mongo
93
- requirement: &70131204731260 !ruby/object:Gem::Requirement
104
+ requirement: &2194306020 !ruby/object:Gem::Requirement
94
105
  none: false
95
106
  requirements:
96
107
  - - ~>
@@ -98,10 +109,10 @@ dependencies:
98
109
  version: 1.8.0
99
110
  type: :development
100
111
  prerelease: false
101
- version_requirements: *70131204731260
112
+ version_requirements: *2194306020
102
113
  - !ruby/object:Gem::Dependency
103
114
  name: mongoid
104
- requirement: &70131204730280 !ruby/object:Gem::Requirement
115
+ requirement: &2194191400 !ruby/object:Gem::Requirement
105
116
  none: false
106
117
  requirements:
107
118
  - - ~>
@@ -109,10 +120,10 @@ dependencies:
109
120
  version: 3.0.0
110
121
  type: :development
111
122
  prerelease: false
112
- version_requirements: *70131204730280
123
+ version_requirements: *2194191400
113
124
  - !ruby/object:Gem::Dependency
114
125
  name: money-mongoid
115
- requirement: &70131204729740 !ruby/object:Gem::Requirement
126
+ requirement: &2194186120 !ruby/object:Gem::Requirement
116
127
  none: false
117
128
  requirements:
118
129
  - - =
@@ -120,7 +131,18 @@ dependencies:
120
131
  version: 0.1.2
121
132
  type: :development
122
133
  prerelease: false
123
- version_requirements: *70131204729740
134
+ version_requirements: *2194186120
135
+ - !ruby/object:Gem::Dependency
136
+ name: mongoid-rspec
137
+ requirement: &2194181460 !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - =
141
+ - !ruby/object:Gem::Version
142
+ version: 1.4.5
143
+ type: :development
144
+ prerelease: false
145
+ version_requirements: *2194181460
124
146
  description: Gexp - comand hadlers
125
147
  email:
126
148
  - kazantsev.nickolay@gmail.com
@@ -134,6 +156,8 @@ files:
134
156
  - README.md
135
157
  - Rakefile
136
158
  - gexp.gemspec
159
+ - lib/examples/item_example.rb
160
+ - lib/examples/user_example.rb
137
161
  - lib/gexp.rb
138
162
  - lib/gexp/command.rb
139
163
  - lib/gexp/command/object.rb