activecommand 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6539a80be081d5bb2ca07a4c214fd505456bf9b9
4
- data.tar.gz: 13c3d3d4554c819a8373961ba7b3a881532503af
3
+ metadata.gz: a0bff99477fe2be1ec3d4ac7c189110141d37c1a
4
+ data.tar.gz: f5fee12ef76e5b5af11ee14356b48a5786c1eecb
5
5
  SHA512:
6
- metadata.gz: f81fae5b5fe169483413092a52549b4b0340ef0d9ed9680c5e3acf6d00fcb04daafc80bdda1996f5e109cb2d1d0e14d3a4524d3c1132705d9c4a1f4bb50eac82
7
- data.tar.gz: 01e987eccf9471dc91d2463b4572027128c41c63e33d55381230ed713cd3439e3566c03e644b2a41b5b2ba4cd37c65a39a8219f7b8ce71d3bc048a8e7030d163
6
+ metadata.gz: efb9b97ed8b2f8d6837cdc12ddca0808266de59db91979113430fb20d56ceefcf46cffde5ef8ae21ef8aad7cccc6aff4fffdb4c436a5fb744ae763e8e53b899f
7
+ data.tar.gz: 0323cee104f88f74b1c177abcf35e222e7f26cff2c80c953c2f97b9fd708e81a0fcccce788f48bf4747c4bab34dcd54e11fefb69eac72e52400d4b77f1e1f3fd
@@ -0,0 +1 @@
1
+ 2.3.0
@@ -1,11 +1,22 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.3.0
3
4
  - 2.2.3
4
- - jruby
5
+ - jruby-9.1.2.0
5
6
  before_install: gem install bundler -v 1.10.6
6
7
 
8
+ env:
9
+ - JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF8"
10
+
7
11
  script: 'bundle exec rake'
8
12
 
13
+ branches:
14
+ only:
15
+ - master
16
+ - develop
17
+ - /^feature\/.*$/
18
+ - /^release\/.*$/
19
+
9
20
  notifications:
10
21
  email:
11
22
  recipients:
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # ActiveCommand
2
2
 
3
+ [![Build Status](https://travis-ci.org/jcarley/activecommand.svg?branch=master)](https://travis-ci.org/jcarley/activecommand)
4
+
3
5
  ActiveCommand adds the ability to use the command pattern commonly seen in CQRS.
4
6
 
5
7
  ## Installation
@@ -28,11 +30,23 @@ First create your command. Perhaps adding it to a commands folder under app, if
28
30
  - commands
29
31
  - SubmitOrderCommand.rb
30
32
 
31
- Then inherit from the base command class and implement an execute method.
33
+ Then inherit from the base command class and implement an execute method. The following example
34
+ is assuming the Order is an ActiveRecord model and has a submit? method.
32
35
 
33
36
  ```ruby
34
37
  class SubmitOrderCommand < ActiveCommand::Command
38
+
39
+ attribute :order_id, String
40
+
41
+ validates :order_id, presence: true
42
+
35
43
  def execute
44
+ order = Order.find(order_id)
45
+ if order.submit?
46
+ Emailer.send_order_submitted_notification_for(order)
47
+ else
48
+ raise OrderSubmitError, "Something went wrong submitting the order '#{order_id}'"
49
+ end
36
50
  end
37
51
  end
38
52
  ```
@@ -42,12 +56,12 @@ execute the command, instantiate it and execute it using the CommandBus. The re
42
56
  is a CommandResult object. The CommandResult will tell you if the command was successful or not.
43
57
 
44
58
  ```ruby
45
- submit_order_command = SubmitOrderCommand.new
59
+ submit_order_command = SubmitOrderCommand.new(:order_id => "ABC123")
46
60
  cr = ActiveCommand::CommandBus.execute(submit_order_command)
47
61
  if cr.success?
48
62
  redirect "/"
49
63
  else
50
- render "submit_path"
64
+ render :submit
51
65
  end
52
66
  ```
53
67
 
@@ -59,7 +73,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
59
73
 
60
74
  ## Contributing
61
75
 
62
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/activecommand. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
76
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jcarley/activecommand. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
63
77
 
64
78
 
65
79
  ## License
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.add_dependency 'middleware'
18
18
  spec.add_dependency 'activesupport'
19
19
  spec.add_dependency 'activemodel'
20
+ spec.add_dependency 'sidekiq'
20
21
 
21
22
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
22
23
  # delete this section to allow pushing this gem to any host.
@@ -3,11 +3,14 @@ require 'middleware'
3
3
  require 'active_support'
4
4
  require 'active_support/hash_with_indifferent_access'
5
5
  require 'active_model'
6
+ require 'sidekiq'
6
7
 
7
8
  module ActiveCommand
8
9
  extend ActiveSupport::Autoload
9
10
 
11
+ autoload :Core
10
12
  autoload :Command
13
+ autoload :BackgroundCommand
11
14
  autoload :CommandBus
12
15
  autoload :CommandResult
13
16
  autoload :CommandNotValidError
@@ -1,9 +1,13 @@
1
1
  module ActiveCommand
2
2
  class Command
3
+ include Core
4
+ include Sidekiq::Worker
3
5
  include Virtus.model
4
6
  include ActiveModel::Validations
5
7
  include ActiveModel::Serializers::JSON
6
8
 
9
+ attribute :job_id, String
10
+
7
11
  def self.from_json(json)
8
12
  klass = self.new
9
13
  klass.from_json(json)
@@ -16,6 +20,15 @@ module ActiveCommand
16
20
  alias_method :to_hash, :to_params
17
21
 
18
22
  def run
23
+ self.class.perform_async self.to_params.to_json
24
+ end
25
+
26
+ def perform(job_data)
27
+ self.from_json(job_data)
28
+ self.perform_now
29
+ end
30
+
31
+ def perform_now
19
32
  if self.valid?
20
33
  self.execute
21
34
  else
@@ -8,7 +8,18 @@ module ActiveCommand
8
8
  end
9
9
 
10
10
  def execute(command)
11
- env = {:command => command}
11
+ env = {:command => command, :at => :later}
12
+ default_middleware.call(env)
13
+ env[:command_result]
14
+ end
15
+
16
+ def self.execute_now(command)
17
+ bus = self.instance
18
+ bus.execute_now(command)
19
+ end
20
+
21
+ def execute_now(command)
22
+ env = {:command => command, :at => :now}
12
23
  default_middleware.call(env)
13
24
  env[:command_result]
14
25
  end
@@ -0,0 +1,9 @@
1
+ module ActiveCommand
2
+ module Core
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ end
7
+
8
+ end
9
+ end
@@ -8,12 +8,15 @@ module ActiveCommand
8
8
  end
9
9
 
10
10
  def call(env)
11
+
12
+ at = env.fetch(:at, :later)
11
13
  cmd = env.fetch(:command, nil)
12
14
 
13
15
  result = CommandResult.new(cmd).tap do |cr|
14
16
  begin
15
17
  raise MissingCommandError if cr.command.nil?
16
- cr.command.run
18
+ cr.command.run if at == :later
19
+ cr.command.perform_now if at == :now
17
20
  rescue StandardError => e
18
21
  cr.error = e
19
22
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveCommand
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/todo.md ADDED
@@ -0,0 +1,12 @@
1
+
2
+ TODO
3
+ ------
4
+ * Add generators
5
+ * Add background command using ActiveJob
6
+ * Add more middleware
7
+ - logging
8
+ - benchmarking
9
+ - job recording
10
+ * Example project
11
+ * Description/Example code using command validations
12
+ * Add callbacks
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activecommand
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jefferson Carley
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-14 00:00:00.000000000 Z
11
+ date: 2016-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sidekiq
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -118,6 +132,7 @@ files:
118
132
  - ".gitignore"
119
133
  - ".rbenv-gemsets"
120
134
  - ".rspec"
135
+ - ".ruby-version"
121
136
  - ".travis.yml"
122
137
  - CODE_OF_CONDUCT.md
123
138
  - Gemfile
@@ -132,9 +147,11 @@ files:
132
147
  - lib/active_command/command_bus.rb
133
148
  - lib/active_command/command_not_valid_error.rb
134
149
  - lib/active_command/command_result.rb
150
+ - lib/active_command/core.rb
135
151
  - lib/active_command/middleware/command_runner.rb
136
152
  - lib/active_command/version.rb
137
153
  - lib/activecommand.rb
154
+ - todo.md
138
155
  homepage: https://github.com/jcarley/activecommand
139
156
  licenses:
140
157
  - MIT
@@ -156,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
173
  version: '0'
157
174
  requirements: []
158
175
  rubyforge_project:
159
- rubygems_version: 2.4.5.1
176
+ rubygems_version: 2.5.1
160
177
  signing_key:
161
178
  specification_version: 4
162
179
  summary: ActiveCommand adds the ability to use the command pattern commonly seen in