bidding 0.0.3 → 0.0.4

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 951744d77950f40951369dfe33cacd9c944c3ec1
4
+ data.tar.gz: 3f2b0c3f1eb64225f1d4a48cbc78b86b44ac4b6e
5
+ SHA512:
6
+ metadata.gz: d0d14a5c3d6b680d6a265b2c0df466dafc89c959c5a9b9f4ee31966ae5a6baf00584e2d3eb818429fb2e41c5844b615867ad27a659bf3b54a829e4abcd854e23
7
+ data.tar.gz: bb1636cf1e75d1f3bffaf9ca200ed0e215fe2da61583a4816f0c3fe7b5d6c56e6af2ac42376c7d92282f936d01596aad7f6aabe7ce70e7eccea28bcb44187644
@@ -10,36 +10,36 @@ require 'bidding/tools/importer'
10
10
 
11
11
  module Bidding
12
12
 
13
- @@executor = CommandsExecutor.new
14
- @@log = TransactionLog.new
15
- @@queue = CommandQueue.new
13
+ @@executor = CommandsExecutor.new
14
+ @@log = TransactionLog.new
15
+ @@queue = CommandQueue.new
16
16
 
17
- def self.executor=(executor)
18
- @@executor = executor
19
- end
17
+ def self.executor=(executor)
18
+ @@executor = executor
19
+ end
20
20
 
21
21
 
22
- def self.execute_commands commands
23
- @@executor.execute commands
24
- end
22
+ def self.execute_commands commands
23
+ @@executor.execute commands
24
+ end
25
25
 
26
- def self.transaction_log=(log)
27
- @@log = log
28
- end
26
+ def self.transaction_log=(log)
27
+ @@log = log
28
+ end
29
29
 
30
- def self.command_queue=(queue)
31
- @@queue = queue
32
- end
30
+ def self.command_queue=(queue)
31
+ @@queue = queue
32
+ end
33
33
 
34
- def self.command_queue
35
- @@queue
36
- end
34
+ def self.command_queue
35
+ @@queue
36
+ end
37
+
38
+ def self.log_commands commands
39
+ @@log.push commands
40
+ end
37
41
 
38
- def self.log_commands commands
39
- @@log.push commands
40
- end
41
42
 
42
-
43
43
 
44
44
 
45
45
  end
@@ -1,5 +1,5 @@
1
1
  class Command
2
- attr_accessor :name, :arguments, :user, :commandline
2
+ attr_accessor :name, :arguments, :user, :commandline, :execution_date
3
3
 
4
4
  def self.parameters(*args)
5
5
  args.each do |arg|
@@ -7,13 +7,14 @@ class Command
7
7
  end
8
8
  end
9
9
 
10
- def self.parse(commandline, user)
10
+ def self.parse(commandline, user, time)
11
11
  parts = commandline.split(" ")
12
12
  name = camel_case parts.shift
13
13
  command = Kernel.const_get(name).new
14
14
  command.name = name
15
15
  command.user = user
16
16
  command.arguments = parts
17
+ command.execution_date = time
17
18
  command.commandline = commandline
18
19
  command
19
20
  end
@@ -24,7 +25,7 @@ class Command
24
25
 
25
26
  def self.camel_case(s)
26
27
  return s if s !~ /_/ && s =~ /[A-Z]+.*/
27
- s.split('_').map{|e| e.capitalize}.join
28
+ s.split('_').map{|e| e.capitalize}.join
28
29
  end
29
30
 
30
31
 
@@ -2,35 +2,35 @@ require 'observer'
2
2
 
3
3
  class CommandQueue
4
4
 
5
- def initialize
6
- @list = []
7
- end
8
-
9
- def list
10
- @list
11
- end
12
-
13
- def pushCommands(commands)
14
- @list.push commands
15
- if(Bidding.execute_commands commands)
16
- @list.delete commands
17
- end
18
- end
19
-
20
- def length
21
- @list.length
22
- end
23
-
24
- def return(transaction)
25
- @list.insert(0, transaction)
26
- end
27
-
28
- def next
29
- @list.shift
30
- end
31
-
32
- def exists? (id)
33
- @list.index { |item| item[:id] == id} != nil
34
- end
5
+ def initialize
6
+ @list = []
7
+ end
8
+
9
+ def list
10
+ @list
11
+ end
12
+
13
+ def pushCommands(commands)
14
+ @list.push commands
15
+ if(Bidding.execute_commands commands)
16
+ @list.delete commands
17
+ end
18
+ end
19
+
20
+ def length
21
+ @list.length
22
+ end
23
+
24
+ def return(transaction)
25
+ @list.insert(0, transaction)
26
+ end
27
+
28
+ def next
29
+ @list.shift
30
+ end
31
+
32
+ def exists? (id)
33
+ @list.index { |item| item[:id] == id} != nil
34
+ end
35
35
 
36
36
  end
@@ -1,7 +1,7 @@
1
1
 
2
2
  class Nop < Command
3
3
 
4
- def execute
5
- end
4
+ def execute
5
+ end
6
6
 
7
- end
7
+ end
@@ -1,18 +1,19 @@
1
+ require 'date'
1
2
 
2
3
  class CommandsExecutor
3
- def execute(commands)
4
- commands["commands"].each {|c|
5
- co = Command.parse(c, commands["user"])
6
- co.execute()
7
- }
8
- Bidding.log_commands commands
9
- return true
10
- rescue Exception
11
- p 'EXCEPTION'
12
- p $!.to_s
13
- p $!.backtrace
14
- return false
15
- end
4
+ def execute(commands)
5
+ commands["commands"].each {|c|
6
+ co = Command.parse(c, commands["user"], DateTime.now)
7
+ co.execute()
8
+ }
9
+ Bidding.log_commands commands
10
+ return true
11
+ rescue Exception
12
+ p 'EXCEPTION'
13
+ p $!.to_s
14
+ p $!.backtrace
15
+ return false
16
+ end
16
17
 
17
18
 
18
- end
19
+ end
@@ -1,30 +1,30 @@
1
1
  class InMemoryTransactionLog
2
2
 
3
- def initialize
4
- @list = []
5
- end
3
+ def initialize
4
+ @list = []
5
+ end
6
6
 
7
- def push(transaction)
8
- @list.push(transaction)
9
- end
7
+ def push(transaction)
8
+ @list.push(transaction)
9
+ end
10
10
 
11
- def from(date)
12
- @list.select { |entry| entry["date"] < date}
13
- end
11
+ def from(date)
12
+ @list.select { |entry| entry["date"] < date}
13
+ end
14
14
 
15
15
 
16
- def containsId? (id)
17
- @list.index { |trans| trans["id"] == id } != nil
18
- end
16
+ def containsId? (id)
17
+ @list.index { |trans| trans["id"] == id } != nil
18
+ end
19
19
 
20
- def delete(entry)
21
- @list.delete_if { |entry| entry["id"] == entry}
22
- end
20
+ def delete(entry)
21
+ @list.delete_if { |entry| entry["id"] == entry}
22
+ end
23
23
 
24
- # for testing purposes only
25
- def log
26
- @list
27
- end
24
+ # for testing purposes only
25
+ def log
26
+ @list
27
+ end
28
28
 
29
29
 
30
- end
30
+ end
@@ -3,35 +3,35 @@ require 'date'
3
3
 
4
4
  class Exporter
5
5
 
6
- def initialize(log)
7
- @log = log
8
- end
9
-
10
- def export_from(date)
11
- entries = (@log.from date.to_f).to_a
12
- write entries, to(file_by date)
13
-
14
- delete entries
15
- end
16
-
17
- def write(entries, path)
18
- File.open(path, "w") { |file|
19
- file.write JSON entries
20
- }
21
- end
22
-
23
- def delete(entries)
24
- entries.each do |entry|
25
- @log.delete entry
26
- end
27
- end
28
-
29
- def to(file)
30
- file
31
- end
32
-
33
- def file_by(date)
34
- return "./tmp/log-" + Time.now.utc.to_date.to_s + ".json"
35
- end
36
-
37
- end
6
+ def initialize(log)
7
+ @log = log
8
+ end
9
+
10
+ def export_from(date)
11
+ entries = (@log.from date.to_f).to_a
12
+ write entries, to(file_by date)
13
+
14
+ delete entries
15
+ end
16
+
17
+ def write(entries, path)
18
+ File.open(path, "w") { |file|
19
+ file.write JSON entries
20
+ }
21
+ end
22
+
23
+ def delete(entries)
24
+ entries.each do |entry|
25
+ @log.delete entry
26
+ end
27
+ end
28
+
29
+ def to(file)
30
+ file
31
+ end
32
+
33
+ def file_by(date)
34
+ return "./tmp/log-" + Time.now.utc.to_date.to_s + ".json"
35
+ end
36
+
37
+ end
@@ -1,22 +1,23 @@
1
-
1
+ require 'time'
2
+ require 'bidding/command'
2
3
  Dir["./lib/commands/**/*.rb"].sort.each {|f| require f}
3
4
  Dir["./lib/models/**/*.rb"].sort.each {|f| require f}
4
5
  class Importer
5
6
 
6
- def import file
7
- p 'importing file ' + file
8
- transaction = JSON File.read file
7
+ def import file
8
+ p 'importing file ' + file
9
+ transaction = JSON File.read file
9
10
 
10
- transaction.each { |trans|
11
- commands = trans["commands"]
12
- commands.each { |command_string|
13
- command = Command.parse command_string, trans["user"]
14
- command.replay
15
- }
16
- }
11
+ transaction.each { |trans|
12
+ commands = trans["commands"]
13
+ commands.each { |command_string|
14
+ command = Command.parse command_string, trans["user"], Time.at(trans["date"])
15
+ command.replay
16
+ }
17
+ }
17
18
 
18
- File.delete file
19
+ File.delete file
19
20
 
20
- end
21
+ end
21
22
 
22
- end
23
+ end
@@ -3,16 +3,16 @@ require 'date'
3
3
  class TransactionLog
4
4
 
5
5
 
6
- def adapter=(adapter)
7
- @adapter = adapter
8
- end
6
+ def adapter=(adapter)
7
+ @adapter = adapter
8
+ end
9
9
 
10
- def adapter
11
- @adapter ||= InMemoryTransactionLog.new
12
- end
10
+ def adapter
11
+ @adapter ||= InMemoryTransactionLog.new
12
+ end
13
13
 
14
- def push(transaction)
15
- transaction["date"] = Time.now.utc.to_f
16
- adapter.push(transaction)
17
- end
18
- end
14
+ def push(transaction)
15
+ transaction["date"] = Time.now.utc.to_r
16
+ adapter.push(transaction)
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module Bidding
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bidding
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 0.0.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Morten Nielsen
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-01-10 00:00:00.000000000 Z
11
+ date: 2015-03-07 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,17 +41,15 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  description: Lets you create commands that will parse from oneline strings, and execute
@@ -66,40 +59,39 @@ executables: []
66
59
  extensions: []
67
60
  extra_rdoc_files: []
68
61
  files:
62
+ - README.md
69
63
  - lib/bidding.rb
64
+ - lib/bidding/command.rb
70
65
  - lib/bidding/command_queue.rb
66
+ - lib/bidding/commands/nop.rb
71
67
  - lib/bidding/commands_executor.rb
72
- - lib/bidding/transaction_log.rb
73
- - lib/bidding/version.rb
74
68
  - lib/bidding/in_memory_transaction_log.rb
75
- - lib/bidding/commands/nop.rb
76
69
  - lib/bidding/tools/exporter.rb
77
70
  - lib/bidding/tools/importer.rb
78
- - lib/bidding/command.rb
79
- - README.md
71
+ - lib/bidding/transaction_log.rb
72
+ - lib/bidding/version.rb
80
73
  homepage: https://github.com/morkeleb/bidding
81
74
  licenses:
82
75
  - MIT
76
+ metadata: {}
83
77
  post_install_message:
84
78
  rdoc_options: []
85
79
  require_paths:
86
80
  - lib
87
81
  required_ruby_version: !ruby/object:Gem::Requirement
88
- none: false
89
82
  requirements:
90
- - - ! '>='
83
+ - - '>='
91
84
  - !ruby/object:Gem::Version
92
85
  version: '0'
93
86
  required_rubygems_version: !ruby/object:Gem::Requirement
94
- none: false
95
87
  requirements:
96
- - - ! '>='
88
+ - - '>='
97
89
  - !ruby/object:Gem::Version
98
90
  version: '0'
99
91
  requirements: []
100
92
  rubyforge_project:
101
- rubygems_version: 1.8.25
93
+ rubygems_version: 2.2.2
102
94
  signing_key:
103
- specification_version: 3
95
+ specification_version: 4
104
96
  summary: A small library for handling commands
105
97
  test_files: []