simple_command 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c874dea14c49cfea5cf2d5f8dafcbc8352199a55
4
- data.tar.gz: caedd0f176a3f0091728dabd200212100c4462b0
3
+ metadata.gz: e0354a2aa2db1b280b8f692540d1cc43bc8d5101
4
+ data.tar.gz: 338efb5cc5dba3c0dc871f0b8c95303199bee39e
5
5
  SHA512:
6
- metadata.gz: cbf388daa3f6482e3916afd9f2d982d22b50927e4af7e60e6b4b88d88f94020e872c1ad206bbe039e732936e3d43a065608f32d0624e6153dd172852f4f2eb68
7
- data.tar.gz: 07ccf08861301769d364e60dce60a388bea5319988e90ab83b108409ca9a629a9e1eaf280b01a7408a4f2a8cc0a7709bff6dfb0f01940c25692f4af2fec8df43
6
+ metadata.gz: 93599a158af6881b4a0bff6d580ecc7f3324669bdef4a9a8781aa7772d7372e392fc4bfadb44e3688605c2c5ea0a792fe86e4ff0f1e0e2c4809895c17d9fe35e
7
+ data.tar.gz: a0e8fa514b19948d4725f35f152aaa612ba359f30abe7108e5ab7afc0a1edbc556e4d513650213e2d875ead4215f27f764bd80faaf9662bf8b2426e40d8a5797
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ # This is the configuration used to check the rubocop source code.
2
+
3
+ # inherit_from: .rubocop_todo.yml
4
+
5
+ # AllCops:
6
+ # Exclude:
7
+ # - 'simple_command.gemspec'
8
+ # - 'spec/factories/**/*'
9
+
10
+ # Style/Encoding:
11
+ # Enabled: when_needed
12
+
13
+ Style/Documentation:
14
+ Enabled: false
data/Gemfile CHANGED
@@ -5,4 +5,5 @@ gemspec
5
5
 
6
6
  group :development do
7
7
  gem 'simplecov'
8
+ gem 'rubocop'
8
9
  end
data/README.md CHANGED
@@ -8,12 +8,10 @@ A simple, standardized way to build and use _Service Objects_ (aka _Commands_) i
8
8
 
9
9
  ## Installation
10
10
 
11
- *NOTE:* this gem is not yet published on rubygems, use the github repository.
12
-
13
11
  Add this line to your application's Gemfile:
14
12
 
15
13
  ```ruby
16
- gem 'simple_command', github: 'nebulab/simple_command'
14
+ gem 'simple_command'
17
15
  ```
18
16
 
19
17
  And then execute:
@@ -59,7 +57,8 @@ Then, in your controller:
59
57
  class SessionsController < ApplicationController
60
58
  def create
61
59
  # initialize and execute the command
62
- command = AuthenticateUser.new(session_params[:user], session_params[:password]).perform
60
+ # NOTE: `.perform` is a shortcut for `.new(args).perform)`
61
+ command = AuthenticateUser.perform(session_params[:user], session_params[:password])
63
62
 
64
63
  # check command outcome
65
64
  if command.success?
data/Rakefile CHANGED
@@ -1,7 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
7
-
6
+ task default: :spec
@@ -1,12 +1,21 @@
1
- require "simple_command/version"
2
- require "simple_command/errors"
1
+ require 'simple_command/version'
2
+ require 'simple_command/errors'
3
3
 
4
4
  module SimpleCommand
5
+ attr_reader :result
5
6
 
6
- def perform
7
- if !defined?(super)
8
- raise NotImplementedError
7
+ module ClassMethods
8
+ def perform(*args)
9
+ new(*args).perform
9
10
  end
11
+ end
12
+
13
+ def self.prepended(base)
14
+ base.extend ClassMethods
15
+ end
16
+
17
+ def perform
18
+ fail NotImplementedError unless defined?(super)
10
19
 
11
20
  @performed = true
12
21
  @result = super
@@ -22,10 +31,6 @@ module SimpleCommand
22
31
  performed? && errors.any?
23
32
  end
24
33
 
25
- def result
26
- @result
27
- end
28
-
29
34
  def errors
30
35
  @errors ||= {}
31
36
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleCommand
2
- class NotImplementedError < ::StandardError ; end
2
+ class NotImplementedError < ::StandardError; end
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleCommand
2
- VERSION = "0.0.3"
2
+ VERSION = '0.0.4'
3
3
  end
@@ -3,23 +3,23 @@ lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'simple_command/version'
5
5
 
6
- Gem::Specification.new do |spec|
7
- spec.required_ruby_version = '~> 2.0'
8
- spec.name = "simple_command"
9
- spec.version = SimpleCommand::VERSION
10
- spec.authors = ["Andrea Pavoni"]
11
- spec.email = ["andrea.pavoni@gmail.com"]
12
- spec.summary = %q{Easy way to build and manage commands (aka: service objects)}
13
- spec.description = %q{Easy way to build and manage commands (aka: service objects)}
14
- spec.homepage = "http://github.com/nebulab/simple_command"
15
- spec.license = "MIT"
6
+ Gem::Specification.new do |s|
7
+ s.required_ruby_version = '>= 2.0'
8
+ s.name = 'simple_command'
9
+ s.version = SimpleCommand::VERSION
10
+ s.authors = ['Andrea Pavoni']
11
+ s.email = ['andrea.pavoni@gmail.com']
12
+ s.summary = 'Easy way to build and manage commands (service objects)'
13
+ s.description = 'Easy way to build and manage commands (service objects)'
14
+ s.homepage = 'http://github.com/nebulab/simple_command'
15
+ s.license = 'MIT'
16
16
 
17
- spec.files = `git ls-files -z`.split("\x0")
18
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
- spec.require_paths = ["lib"]
17
+ s.files = `git ls-files -z`.split("\x0")
18
+ s.executables = s.files.grep(/^bin\//) { |f| File.basename(f) }
19
+ s.test_files = s.files.grep(/^(test|spec|features)\//)
20
+ s.require_paths = ['lib']
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.7"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "rspec"
22
+ s.add_development_dependency 'bundler', '~> 1.7'
23
+ s.add_development_dependency 'rake', '~> 10.0'
24
+ s.add_development_dependency 'rspec', '~> 3.1'
25
25
  end
@@ -6,6 +6,6 @@ class FailCommand
6
6
  end
7
7
 
8
8
  def perform
9
- add_error(:wrong_math, 'Math is not an opinion') if true
9
+ add_error(:wrong_math, 'Math is not an opinion')
10
10
  end
11
11
  end
@@ -4,6 +4,23 @@ describe SimpleCommand do
4
4
  let(:command) { SuccessCommand.new(2) }
5
5
  let(:fail_command) { FailCommand.new(2) }
6
6
 
7
+ describe '.perform' do
8
+ before do
9
+ allow(SuccessCommand).to receive(:new).and_return(command)
10
+ allow(command).to receive(:perform)
11
+
12
+ SuccessCommand.perform 2
13
+ end
14
+
15
+ it 'initializes the command' do
16
+ expect(SuccessCommand).to have_received(:new)
17
+ end
18
+
19
+ it 'calls #perform method' do
20
+ expect(command).to have_received(:perform)
21
+ end
22
+ end
23
+
7
24
  describe '#perform' do
8
25
  let(:missed_perform_command) { MissedPerformCommand.new(2) }
9
26
 
@@ -12,7 +29,9 @@ describe SimpleCommand do
12
29
  end
13
30
 
14
31
  it 'raises an exception if the method is not defined in the command' do
15
- expect { missed_perform_command.perform }.to raise_error(SimpleCommand::NotImplementedError)
32
+ expect do
33
+ missed_perform_command.perform
34
+ end.to raise_error(SimpleCommand::NotImplementedError)
16
35
  end
17
36
  end
18
37
 
@@ -81,5 +100,4 @@ describe SimpleCommand do
81
100
  end
82
101
  end
83
102
  end
84
-
85
103
  end
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  require 'simplecov'
2
2
 
3
3
  SimpleCov.start do
4
- add_filter "/spec/"
4
+ add_filter '/spec/'
5
5
  end
6
6
 
7
7
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
8
8
 
9
9
  require 'simple_command'
10
10
 
11
- Dir[File.join(File.dirname(__FILE__), 'factories', '**/*.rb')].each { |f| require f }
11
+ Dir[File.join(File.dirname(__FILE__), 'factories', '**/*.rb')].each do |factory|
12
+ require factory
13
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_command
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrea Pavoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-02 00:00:00.000000000 Z
11
+ date: 2015-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,17 +42,17 @@ dependencies:
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '3.1'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
55
- description: 'Easy way to build and manage commands (aka: service objects)'
54
+ version: '3.1'
55
+ description: Easy way to build and manage commands (service objects)
56
56
  email:
57
57
  - andrea.pavoni@gmail.com
58
58
  executables: []
@@ -61,6 +61,7 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
63
  - ".rspec"
64
+ - ".rubocop.yml"
64
65
  - ".travis.yml"
65
66
  - Gemfile
66
67
  - LICENSE.txt
@@ -85,7 +86,7 @@ require_paths:
85
86
  - lib
86
87
  required_ruby_version: !ruby/object:Gem::Requirement
87
88
  requirements:
88
- - - "~>"
89
+ - - ">="
89
90
  - !ruby/object:Gem::Version
90
91
  version: '2.0'
91
92
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -98,7 +99,7 @@ rubyforge_project:
98
99
  rubygems_version: 2.2.2
99
100
  signing_key:
100
101
  specification_version: 4
101
- summary: 'Easy way to build and manage commands (aka: service objects)'
102
+ summary: Easy way to build and manage commands (service objects)
102
103
  test_files:
103
104
  - spec/factories/fail_command.rb
104
105
  - spec/factories/missed_perform_command.rb