simple_command 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +14 -0
- data/Gemfile +1 -0
- data/README.md +3 -4
- data/Rakefile +3 -4
- data/lib/simple_command.rb +14 -9
- data/lib/simple_command/errors.rb +1 -1
- data/lib/simple_command/version.rb +1 -1
- data/simple_command.gemspec +17 -17
- data/spec/factories/fail_command.rb +1 -1
- data/spec/simple_command_spec.rb +20 -2
- data/spec/spec_helper.rb +4 -2
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0354a2aa2db1b280b8f692540d1cc43bc8d5101
|
4
|
+
data.tar.gz: 338efb5cc5dba3c0dc871f0b8c95303199bee39e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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'
|
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
|
-
|
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
data/lib/simple_command.rb
CHANGED
@@ -1,12 +1,21 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'simple_command/version'
|
2
|
+
require 'simple_command/errors'
|
3
3
|
|
4
4
|
module SimpleCommand
|
5
|
+
attr_reader :result
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
data/simple_command.gemspec
CHANGED
@@ -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 |
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
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
|
data/spec/simple_command_spec.rb
CHANGED
@@ -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
|
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
|
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
|
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.
|
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-
|
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: '
|
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: '
|
55
|
-
description:
|
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:
|
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
|