simple_command 0.0.7 → 0.0.8

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: 34d0c5727245163347f97d47f2b6d1ee2427b3fc
4
- data.tar.gz: 55e57dbdac2641a907b8186b822a32c1ce5584e0
3
+ metadata.gz: e1e044db947afd477d7b8042fbd679fdffbd8a63
4
+ data.tar.gz: 021cfb1817dd007895a76184af0db53095c0c9a1
5
5
  SHA512:
6
- metadata.gz: 42f9820c03e53e70355decbf26c15d17559198404a171d3e5f37f54284b77f046a1094a69921abad73c34a793916066b301916ede8a8a0c88b74837ef72af3ce
7
- data.tar.gz: a86431bceab44ee6e2a25dc328b5c8e57a71d7eeed8aabde579e6287272d8b9d890ef99737f96e43e666405c2a0056d7582aebfede4c631e8a4d9e3662ecd9dc
6
+ metadata.gz: 0a88837defef4d2cc6f3c7167e0f891f73dd09ff6378a5719df8772e8a4f1bdd7cd22043ca29b3596d9e53d619c9a714d03c2107a27d3746150c8f3d167d2730
7
+ data.tar.gz: ea8a66ec330153ba06932837a9795d7931c3741faed743c3ebdaa40e211ffde726a173121a84c6a91c89cca5561308373d04aca9d0a776764ce195d8f75694f2
data/README.md CHANGED
@@ -38,9 +38,9 @@ class AuthenticateUser
38
38
  @password = password
39
39
  end
40
40
 
41
- # mandatory: define a #perform method. its return value will be available
41
+ # mandatory: define a #call method. its return value will be available
42
42
  # through #result
43
- def perform
43
+ def call
44
44
  if user = User.authenticate(@email, @password)
45
45
  return user
46
46
  else
@@ -57,8 +57,8 @@ Then, in your controller:
57
57
  class SessionsController < ApplicationController
58
58
  def create
59
59
  # initialize and execute the command
60
- # NOTE: `.perform` is a shortcut for `.new(args).perform)`
61
- command = AuthenticateUser.perform(session_params[:user], session_params[:password])
60
+ # NOTE: `.call` is a shortcut for `.new(args).call)`
61
+ command = AuthenticateUser.call(session_params[:user], session_params[:password])
62
62
 
63
63
  # check command outcome
64
64
  if command.success?
@@ -5,8 +5,8 @@ module SimpleCommand
5
5
  attr_reader :result
6
6
 
7
7
  module ClassMethods
8
- def perform(*args)
9
- new(*args).perform
8
+ def call(*args)
9
+ new(*args).call
10
10
  end
11
11
  end
12
12
 
@@ -14,21 +14,21 @@ module SimpleCommand
14
14
  base.extend ClassMethods
15
15
  end
16
16
 
17
- def perform
17
+ def call
18
18
  fail NotImplementedError unless defined?(super)
19
19
 
20
- @performed = true
20
+ @called = true
21
21
  @result = super
22
22
 
23
23
  self
24
24
  end
25
25
 
26
26
  def success?
27
- performed? && !failure?
27
+ called? && !failure?
28
28
  end
29
29
 
30
30
  def failure?
31
- performed? && errors.any?
31
+ called? && errors.any?
32
32
  end
33
33
 
34
34
  def errors
@@ -37,7 +37,7 @@ module SimpleCommand
37
37
 
38
38
  private
39
39
 
40
- def performed?
41
- @performed ||= false
40
+ def called?
41
+ @called ||= false
42
42
  end
43
43
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleCommand
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -1,4 +1,4 @@
1
- class MissedPerformCommand
1
+ class MissedCallCommand
2
2
  prepend SimpleCommand
3
3
 
4
4
  def initialize(input)
@@ -5,7 +5,7 @@ class SuccessCommand
5
5
  @input = input
6
6
  end
7
7
 
8
- def perform
8
+ def call
9
9
  @input * 2
10
10
  end
11
11
  end
@@ -3,48 +3,48 @@ require 'spec_helper'
3
3
  describe SimpleCommand do
4
4
  let(:command) { SuccessCommand.new(2) }
5
5
 
6
- describe '.perform' do
6
+ describe '.call' do
7
7
  before do
8
8
  allow(SuccessCommand).to receive(:new).and_return(command)
9
- allow(command).to receive(:perform)
9
+ allow(command).to receive(:call)
10
10
 
11
- SuccessCommand.perform 2
11
+ SuccessCommand.call 2
12
12
  end
13
13
 
14
14
  it 'initializes the command' do
15
15
  expect(SuccessCommand).to have_received(:new)
16
16
  end
17
17
 
18
- it 'calls #perform method' do
19
- expect(command).to have_received(:perform)
18
+ it 'calls #call method' do
19
+ expect(command).to have_received(:call)
20
20
  end
21
21
  end
22
22
 
23
- describe '#perform' do
24
- let(:missed_perform_command) { MissedPerformCommand.new(2) }
23
+ describe '#call' do
24
+ let(:missed_call_command) { MissedCallCommand.new(2) }
25
25
 
26
26
  it 'returns the command object' do
27
- expect(command.perform).to be_a(SuccessCommand)
27
+ expect(command.call).to be_a(SuccessCommand)
28
28
  end
29
29
 
30
30
  it 'raises an exception if the method is not defined in the command' do
31
31
  expect do
32
- missed_perform_command.perform
32
+ missed_call_command.call
33
33
  end.to raise_error(SimpleCommand::NotImplementedError)
34
34
  end
35
35
  end
36
36
 
37
37
  describe '#success?' do
38
38
  it 'is true by default' do
39
- expect(command.perform.success?).to be_truthy
39
+ expect(command.call.success?).to be_truthy
40
40
  end
41
41
 
42
42
  it 'is false if something went wrong' do
43
43
  command.errors.add_error(:some_error, 'some message')
44
- expect(command.perform.success?).to be_falsy
44
+ expect(command.call.success?).to be_falsy
45
45
  end
46
46
 
47
- context 'when perform is not called yet' do
47
+ context 'when call is not called yet' do
48
48
  it 'is false by default' do
49
49
  expect(command.success?).to be_falsy
50
50
  end
@@ -53,10 +53,10 @@ describe SimpleCommand do
53
53
 
54
54
  describe '#result' do
55
55
  it 'returns the result of command execution' do
56
- expect(command.perform.result).to eq(4)
56
+ expect(command.call.result).to eq(4)
57
57
  end
58
58
 
59
- context 'when perform is not called yet' do
59
+ context 'when call is not called yet' do
60
60
  it 'returns nil' do
61
61
  expect(command.result).to be_nil
62
62
  end
@@ -65,15 +65,15 @@ describe SimpleCommand do
65
65
 
66
66
  describe '#failure?' do
67
67
  it 'is false by default' do
68
- expect(command.perform.failure?).to be_falsy
68
+ expect(command.call.failure?).to be_falsy
69
69
  end
70
70
 
71
71
  it 'is true if something went wrong' do
72
72
  command.errors.add_error(:some_error, 'some message')
73
- expect(command.perform.failure?).to be_truthy
73
+ expect(command.call.failure?).to be_truthy
74
74
  end
75
75
 
76
- context 'when perform is not called yet' do
76
+ context 'when call is not called yet' do
77
77
  it 'is false by default' do
78
78
  expect(command.failure?).to be_falsy
79
79
  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.7
4
+ version: 0.0.8
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-16 00:00:00.000000000 Z
11
+ date: 2015-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,7 +71,7 @@ files:
71
71
  - lib/simple_command/errors.rb
72
72
  - lib/simple_command/version.rb
73
73
  - simple_command.gemspec
74
- - spec/factories/missed_perform_command.rb
74
+ - spec/factories/missed_call_command.rb
75
75
  - spec/factories/success_command.rb
76
76
  - spec/simple_command/errors_spec.rb
77
77
  - spec/simple_command_spec.rb
@@ -101,7 +101,7 @@ signing_key:
101
101
  specification_version: 4
102
102
  summary: Easy way to build and manage commands (service objects)
103
103
  test_files:
104
- - spec/factories/missed_perform_command.rb
104
+ - spec/factories/missed_call_command.rb
105
105
  - spec/factories/success_command.rb
106
106
  - spec/simple_command/errors_spec.rb
107
107
  - spec/simple_command_spec.rb