bidding 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -105,13 +105,79 @@ Command.parse("nop the_type 12345 awesome%20stuff!").execute()
105
105
  Each parameter is separated with a space. If you would like to add parameter values that contain spaces I recommend URI encoding them first.
106
106
  This allows you to handle strings that might contain spaces.
107
107
 
108
- ### Executor
108
+ ### Components
109
109
 
110
- The commands executor simply takes a hash of commands from a queue and executes them in order. Successfull commands are pushed to a log.
111
- If the commands are not successfull the commands are left on the queue.
110
+ Appart from the Command structure bidding has 3 major components. All quite simple in their implementations.
111
+
112
+ The Executor, the command queue and the transaction log.
113
+ The executor executes commands and if they are successfull the commands are pushed to the transaction log. The command queue keeps a queue of commands to be executed in order.
112
114
 
113
115
  The gem contains an inmemory queue and log for testing purposes.
114
116
 
117
+ The TransactionLog and the queue should be implemented as need be.
118
+
119
+ #### The queue
120
+
121
+ Pushing a command to the queue is done simply by calling
122
+
123
+ ```ruby
124
+
125
+ Bidding.command_queue.pushCommands {"commands"=>["nop"]}
126
+
127
+ ```
128
+
129
+ You can change which implementation for the queue to use by setting which queue to use in bidding.
130
+
131
+
132
+ ```ruby
133
+
134
+ Bidding.command_queue = MyOwnImplementationOfTheQueue.new
135
+
136
+ ```
137
+
138
+ #### Executor
139
+
140
+ The commands executor takes a hash of commands from a queue and executes them in order. Successfull commands are pushed to a log.
141
+ If the commands are not successfull the commands are left on the queue.
142
+
143
+ Commands can be executed immidiatly by calling execute commands
144
+
145
+
146
+ ```ruby
147
+
148
+ Bidding.execute_commands {"commands"=>["nop"]}
149
+
150
+ ```
151
+
152
+ The example above will send the commands directly to the executor without passing the queue.
153
+
154
+ The executor implementation can also be changed.
155
+
156
+ ```ruby
157
+
158
+ Bidding.executor = MyOwnImplementationOfTheExecutor.new
159
+
160
+ ```
161
+
162
+ #### The transaction log
163
+
164
+ The log keeps track of which commands that have been successfully been executed and in which order.
165
+
166
+ > The concept of the transaction log is inspired by Event Sourcing. If you want to use events as a termonology I would recommend looking into changing the implementation of the executor. The reason I didn't go all in is a wish to start simple. Bidding might support event sourcing in the future.
167
+
168
+ Bidding contains some helper tools that should help you create rake files to import and or export transaction logs to JSON files.
169
+
170
+ These JSON files help you to keep a backup of the command logs on disc. They also allow you to completley replay all commands in the system, effectivlly allowing you to change details of the history.
171
+
172
+ Which log implementation to use can be changed similar to the other components.
173
+
174
+
175
+ ```ruby
176
+
177
+ Bidding.transaction_log = MyOwnImplementationOfTheTransactionLog.new
178
+
179
+ ```
180
+
115
181
  ## Contributing
116
182
 
117
183
  1. Fork it ( http://github.com/morkeleb/bidding/fork )
data/lib/bidding.rb CHANGED
@@ -9,6 +9,37 @@ require 'bidding/tools/exporter'
9
9
  require 'bidding/tools/importer'
10
10
 
11
11
  module Bidding
12
- # Your code goes here...
12
+
13
+ @@executor = CommandsExecutor.new
14
+ @@log = TransactionLog.new
15
+ @@queue = CommandQueue.new
16
+
17
+ def self.executor=(executor)
18
+ @@executor = executor
19
+ end
20
+
21
+
22
+ def self.execute_commands commands
23
+ @@executor.execute commands
24
+ end
25
+
26
+ def self.transaction_log=(log)
27
+ @@log = log
28
+ end
29
+
30
+ def self.command_queue=(queue)
31
+ @@queue = queue
32
+ end
33
+
34
+ def self.command_queue
35
+ @@queue
36
+ end
37
+
38
+ def self.log_commands commands
39
+ @@log.push commands
40
+ end
41
+
42
+
43
+
13
44
 
14
45
  end
@@ -1,7 +1,6 @@
1
1
  require 'observer'
2
2
 
3
3
  class CommandQueue
4
- include Observable
5
4
 
6
5
  def initialize
7
6
  @list = []
@@ -13,9 +12,9 @@ class CommandQueue
13
12
 
14
13
  def pushCommands(commands)
15
14
  @list.push commands
16
- changed
17
- notify_observers commands
18
-
15
+ if(Bidding.execute_commands commands)
16
+ @list.delete commands
17
+ end
19
18
  end
20
19
 
21
20
  def length
@@ -1,22 +1,17 @@
1
- class CommandsExecutor
2
- def initialize(queue, transactionLog)
3
- @queue = queue
4
- @transactionLog = transactionLog
5
- @queue.add_observer(self)
6
- end
7
1
 
8
- def update(commands)
9
- transaction = @queue.next
10
- transaction["commands"].each {|c|
11
- co = Command.parse(c, transaction["user"])
2
+ class CommandsExecutor
3
+ def execute(commands)
4
+ commands["commands"].each {|c|
5
+ co = Command.parse(c, commands["user"])
12
6
  co.execute()
13
7
  }
14
- @transactionLog.push transaction
8
+ Bidding.log_commands commands
9
+ return true
15
10
  rescue Exception
16
11
  p 'EXCEPTION'
17
12
  p $!.to_s
18
13
  p $!.backtrace
19
- @queue.return transaction
14
+ return false
20
15
  end
21
16
 
22
17
 
@@ -1,3 +1,3 @@
1
1
  module Bidding
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bidding
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Morten Nielsen
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-12-18 00:00:00.000000000 Z
12
+ date: 2014-12-26 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ~>
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ~>
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rspec
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ~>
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ~>
39
44
  - !ruby/object:Gem::Version
@@ -41,15 +46,17 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: rake
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - '>='
51
+ - - ! '>='
46
52
  - !ruby/object:Gem::Version
47
53
  version: '0'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - '>='
59
+ - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
62
  description: Lets you create commands that will parse from oneline strings, and execute
@@ -59,39 +66,40 @@ executables: []
59
66
  extensions: []
60
67
  extra_rdoc_files: []
61
68
  files:
62
- - README.md
63
69
  - lib/bidding.rb
64
- - lib/bidding/command.rb
65
70
  - lib/bidding/command_queue.rb
66
- - lib/bidding/commands/nop.rb
67
71
  - lib/bidding/commands_executor.rb
72
+ - lib/bidding/transaction_log.rb
73
+ - lib/bidding/version.rb
68
74
  - lib/bidding/in_memory_transaction_log.rb
75
+ - lib/bidding/commands/nop.rb
69
76
  - lib/bidding/tools/exporter.rb
70
77
  - lib/bidding/tools/importer.rb
71
- - lib/bidding/transaction_log.rb
72
- - lib/bidding/version.rb
78
+ - lib/bidding/command.rb
79
+ - README.md
73
80
  homepage: https://github.com/morkeleb/bidding
74
81
  licenses:
75
82
  - MIT
76
- metadata: {}
77
83
  post_install_message:
78
84
  rdoc_options: []
79
85
  require_paths:
80
86
  - lib
81
87
  required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
82
89
  requirements:
83
- - - '>='
90
+ - - ! '>='
84
91
  - !ruby/object:Gem::Version
85
92
  version: '0'
86
93
  required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
87
95
  requirements:
88
- - - '>='
96
+ - - ! '>='
89
97
  - !ruby/object:Gem::Version
90
98
  version: '0'
91
99
  requirements: []
92
100
  rubyforge_project:
93
- rubygems_version: 2.2.2
101
+ rubygems_version: 1.8.25
94
102
  signing_key:
95
- specification_version: 4
103
+ specification_version: 3
96
104
  summary: A small library for handling commands
97
105
  test_files: []
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 5d5697d795874fbac30fd7513e22eccaed0ff1dc
4
- data.tar.gz: 6549800b7a60c5d993c263d84570ecafecfbb0e9
5
- SHA512:
6
- metadata.gz: ed39d7e778f30cd4015923f8e8c20b39d2b4e6c13acca76a24fec18c42ae3d15557fa0055da96e668c70c209471c6827d81108be5a3dec1ae60cb92b06c8588a
7
- data.tar.gz: e78b7fa2c025e9c80cc5d7fc1a6fc22bcc934ca6f91234d6262150a568bed697454035e0c647ec757d4ea8e6ab20fc7b070767a47d3f15c7bb45c78c18c39783