aye_commander 1.0.1 → 1.0.2
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 +4 -4
- data/lib/aye_commander/callable.rb +1 -2
- data/lib/aye_commander/errors.rb +8 -0
- data/lib/aye_commander/hookable.rb +1 -1
- data/lib/aye_commander/limitable.rb +16 -5
- data/lib/aye_commander/shareable.rb +2 -2
- data/lib/aye_commander/version.rb +1 -1
- data/spec/aye_commander/commander_spec.rb +3 -3
- data/spec/aye_commander/errors_spec.rb +22 -0
- data/spec/aye_commander/hookable_spec.rb +5 -5
- data/spec/aye_commander/inspectable_spec.rb +1 -1
- data/spec/aye_commander/limitable_spec.rb +4 -4
- data/spec/aye_commander/status_spec.rb +6 -6
- data/spec/spec_helper.rb +4 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5cd9e163ad88759356856bb67d1631806f3a6061
|
4
|
+
data.tar.gz: 92352f5d37a173072f885c6b44c6ae8c4b3bf64e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6737d92b45dfc9becbfb301aa75498affbbca75ddf823179f9cd5c715c55902f9f52a6d30756c8e3bc7ba5f341b77a041aa38bd7f3d8adc928497747a5858b3e
|
7
|
+
data.tar.gz: bfafe03df2dac3af038492aed9e4648f8cfc0cc0610b90edeacbb8cf09bb91e38e3e0bf49d4eda62b414574e81788463a6b5df8b8cbfd479c4b15d1e199fe229
|
@@ -35,7 +35,6 @@ module AyeCommander
|
|
35
35
|
# #call is what a user redefines in their own command, and what he
|
36
36
|
# customizes to give a command the behavior he desires.
|
37
37
|
# An empty call is defined in a command so they can be run even without one.
|
38
|
-
|
39
|
-
end
|
38
|
+
define_method(:call) {}
|
40
39
|
end
|
41
40
|
end
|
data/lib/aye_commander/errors.rb
CHANGED
@@ -6,7 +6,7 @@ module AyeCommander
|
|
6
6
|
# All hook functionality is defined at a class level, but runs at instance
|
7
7
|
# level
|
8
8
|
module ClassMethods
|
9
|
-
TYPES = %i
|
9
|
+
TYPES = %i[before around after aborted].freeze
|
10
10
|
|
11
11
|
TYPES.each do |kind|
|
12
12
|
# Defines .before .around .after and .aborted
|
@@ -5,7 +5,7 @@ module AyeCommander
|
|
5
5
|
# Limitable is a module which functionality is completely defined at class
|
6
6
|
# level.
|
7
7
|
module ClassMethods
|
8
|
-
LIMITERS = %i
|
8
|
+
LIMITERS = %i[receives requires returns].freeze
|
9
9
|
|
10
10
|
# Contains all the limiters
|
11
11
|
def limiters
|
@@ -54,13 +54,24 @@ module AyeCommander
|
|
54
54
|
|
55
55
|
# Validates the limiter arguments
|
56
56
|
def validate_arguments(args, skip_validations: false)
|
57
|
-
|
57
|
+
if validate_required_arguments?(skip_validations)
|
58
58
|
validate_required_arguments(args)
|
59
59
|
end
|
60
60
|
|
61
|
-
unless
|
62
|
-
|
63
|
-
|
61
|
+
return unless validate_received_arguments?(skip_validations)
|
62
|
+
validate_received_arguments(args)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Dont validate if asked to skip or requires is empty
|
66
|
+
def validate_required_arguments?(skip_validations)
|
67
|
+
return if [true, :requires].include?(skip_validations)
|
68
|
+
requires.any?
|
69
|
+
end
|
70
|
+
|
71
|
+
# Dont validate if asked to skip or receives is empty
|
72
|
+
def validate_received_arguments?(skip_validations)
|
73
|
+
return if [true, :receives].include?(skip_validations)
|
74
|
+
receives.any?
|
64
75
|
end
|
65
76
|
|
66
77
|
# Validates the required arguments
|
@@ -9,7 +9,7 @@ module AyeCommander
|
|
9
9
|
def included(includer)
|
10
10
|
super
|
11
11
|
includer.extend AyeCommander::Command::ClassMethods
|
12
|
-
%i
|
12
|
+
%i[@limiters @succeeds @hooks].each do |var|
|
13
13
|
if instance_variable_defined? var
|
14
14
|
includer.instance_variable_set var, instance_variable_get(var)
|
15
15
|
end
|
@@ -21,7 +21,7 @@ module AyeCommander
|
|
21
21
|
# the variables to the inheriter.
|
22
22
|
def inherited(inheriter)
|
23
23
|
super
|
24
|
-
%i
|
24
|
+
%i[@limiters @succeeds @hooks].each do |var|
|
25
25
|
if instance_variable_defined? var
|
26
26
|
inheriter.instance_variable_set var, instance_variable_get(var)
|
27
27
|
end
|
@@ -13,7 +13,7 @@ describe AyeCommander::Commander::ClassMethods do
|
|
13
13
|
|
14
14
|
it 'saves the necessary instance variables for the commander' do
|
15
15
|
includer.execute :taco, :burrito
|
16
|
-
expect(includer2.executes).to eq %i
|
16
|
+
expect(includer2.executes).to eq %i[taco burrito]
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -25,7 +25,7 @@ describe AyeCommander::Commander::ClassMethods do
|
|
25
25
|
|
26
26
|
it 'saves the necessary instance variables for the commander' do
|
27
27
|
commander.execute :taco, :burrito
|
28
|
-
expect(inheriter.executes).to eq %i
|
28
|
+
expect(inheriter.executes).to eq %i[taco burrito]
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -62,7 +62,7 @@ describe AyeCommander::Commander::ClassMethods do
|
|
62
62
|
context '.execute' do
|
63
63
|
it 'adds the received arguments to the executes array' do
|
64
64
|
commander.execute :taco, :burrito
|
65
|
-
expect(commander.executes).to eq %i
|
65
|
+
expect(commander.executes).to eq %i[taco burrito]
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -9,6 +9,17 @@ describe AyeCommander::MissingRequiredArgumentError do
|
|
9
9
|
errori = error.new [:taco]
|
10
10
|
expect(errori.message).to eq 'Missing required arguments: [:taco]'
|
11
11
|
end
|
12
|
+
|
13
|
+
it 'should print the class and message with #inspect' do
|
14
|
+
errori = error.new [:taco]
|
15
|
+
expected = '#<AyeCommander::MissingRequiredArgumentError: Missing required arguments: [:taco]>'
|
16
|
+
expect(errori.inspect).to eq expected
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should print the message with #to_s' do
|
20
|
+
errori = error.new [:taco]
|
21
|
+
expect(errori.to_s).to eq 'Missing required arguments: [:taco]'
|
22
|
+
end
|
12
23
|
end
|
13
24
|
|
14
25
|
describe AyeCommander::UnexpectedReceivedArgumentError do
|
@@ -22,4 +33,15 @@ describe AyeCommander::UnexpectedReceivedArgumentError do
|
|
22
33
|
errori = error.new [:taco]
|
23
34
|
expect(errori.message).to eq 'Received unexpected arguments: [:taco]'
|
24
35
|
end
|
36
|
+
|
37
|
+
it 'should print the class and message with #inspect' do
|
38
|
+
errori = error.new [:taco]
|
39
|
+
expected = '#<AyeCommander::UnexpectedReceivedArgumentError: Received unexpected arguments: [:taco]>'
|
40
|
+
expect(errori.inspect).to eq expected
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should print the message with #to_s' do
|
44
|
+
errori = error.new [:taco]
|
45
|
+
expect(errori.to_s).to eq 'Received unexpected arguments: [:taco]'
|
46
|
+
end
|
25
47
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
describe AyeCommander::Hookable::ClassMethods do
|
2
2
|
include_context :command
|
3
3
|
|
4
|
-
%i
|
4
|
+
%i[before around after aborted].each do |kind|
|
5
5
|
context ".#{kind}" do
|
6
6
|
it "adds the args to the #{kind} hooks array" do
|
7
7
|
command.send kind, :some, :method
|
8
|
-
expect(command.send("#{kind}_hooks")).to eq [
|
8
|
+
expect(command.send("#{kind}_hooks")).to eq %i[some method]
|
9
9
|
expect(command.instance_variable_get(:@hooks)).to_not be_empty
|
10
10
|
expect(command.instance_variable_get(:@hooks).default).to be_empty
|
11
11
|
end
|
@@ -19,13 +19,13 @@ describe AyeCommander::Hookable::ClassMethods do
|
|
19
19
|
it 'adds the args at the end of the array' do
|
20
20
|
command.send kind, :first
|
21
21
|
command.send kind, :second, :third
|
22
|
-
expect(command.send("#{kind}_hooks")).to eq [
|
22
|
+
expect(command.send("#{kind}_hooks")).to eq %i[first second third]
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'adds the args at the beginning of the array with the prepend option' do
|
26
26
|
command.send kind, :first
|
27
27
|
command.send kind, :second, :third, prepend: true
|
28
|
-
expect(command.send("#{kind}_hooks")).to eq [
|
28
|
+
expect(command.send("#{kind}_hooks")).to eq %i[second third first]
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -41,7 +41,7 @@ describe AyeCommander::Hookable::ClassMethods do
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
%i
|
44
|
+
%i[before after aborted].each do |kind|
|
45
45
|
context ".call_#{kind}_hooks" do
|
46
46
|
before :each do
|
47
47
|
body = -> { success? }
|
@@ -20,7 +20,7 @@ describe AyeCommander::Inspectable do
|
|
20
20
|
|
21
21
|
it 'gives a hash representation of the innards of the class with the requested values' do
|
22
22
|
result = { :@variable => :something, :@other => :potato }
|
23
|
-
expect(instance.to_hash([
|
23
|
+
expect(instance.to_hash(%i[@variable other])).to eq result
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
describe AyeCommander::Limitable::ClassMethods do
|
2
2
|
include_context :command
|
3
|
-
let(:args)
|
3
|
+
let(:args) { %i[arg1 arg2] }
|
4
4
|
|
5
5
|
context '.uses' do
|
6
6
|
it 'should call save_variable' do
|
@@ -17,7 +17,7 @@ describe AyeCommander::Limitable::ClassMethods do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
%i
|
20
|
+
%i[receives requires returns].each do |limiter|
|
21
21
|
context ".#{limiter}" do
|
22
22
|
before :each do
|
23
23
|
command.public_send limiter, *args
|
@@ -34,12 +34,12 @@ describe AyeCommander::Limitable::ClassMethods do
|
|
34
34
|
|
35
35
|
it 'should add consecutive values without any problem' do
|
36
36
|
command.public_send limiter, :arg3
|
37
|
-
expect(command.limiters[limiter]).to eq %i
|
37
|
+
expect(command.limiters[limiter]).to eq %i[arg1 arg2 arg3]
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'should not add repeated args' do
|
41
41
|
command.public_send limiter, :arg1, :arg4
|
42
|
-
expect(command.limiters[limiter]).to eq %i
|
42
|
+
expect(command.limiters[limiter]).to eq %i[arg1 arg2 arg4]
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -7,30 +7,30 @@ describe AyeCommander::Status::ClassMethods do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'returns whathever the :@succeds class instance variable contains' do
|
10
|
-
command.instance_variable_set :@succeeds, %i
|
11
|
-
expect(command.succeeds).to eq %i
|
10
|
+
command.instance_variable_set :@succeeds, %i[im a little teapot]
|
11
|
+
expect(command.succeeds).to eq %i[im a little teapot]
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
context '.suceeds_with' do
|
16
|
-
let(:args) { %i
|
16
|
+
let(:args) { %i[succ1 succ2] }
|
17
17
|
|
18
18
|
before :each do
|
19
19
|
command.succeeds_with(*args)
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'adds the values to the succeeds array' do
|
23
|
-
expect(command.succeeds).to eq %i
|
23
|
+
expect(command.succeeds).to eq %i[success succ1 succ2]
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'allows consecutive succeeds' do
|
27
27
|
command.succeeds_with :potato
|
28
|
-
expect(command.succeeds).to eq %i
|
28
|
+
expect(command.succeeds).to eq %i[success succ1 succ2 potato]
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'doesnt add repeated succeeds' do
|
32
32
|
command.succeeds_with(*args)
|
33
|
-
expect(command.succeeds).to eq %i
|
33
|
+
expect(command.succeeds).to eq %i[success succ1 succ2]
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'removes :success from the array if called with the exclude_suceed option' do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
require 'simplecov'
|
6
|
-
SimpleCov.start do
|
7
|
-
add_filter 'spec/'
|
8
|
-
end
|
1
|
+
# NOTE Coverage must be required and initialized before anything else
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start do
|
4
|
+
add_filter 'spec/'
|
9
5
|
end
|
10
6
|
|
11
7
|
require 'pry'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aye_commander
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pyzlnar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A gem that helps to write commands in ruby.
|
14
14
|
email: pyzlnar@gmail.com
|
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
68
|
version: '0'
|
69
69
|
requirements: []
|
70
70
|
rubyforge_project:
|
71
|
-
rubygems_version: 2.
|
71
|
+
rubygems_version: 2.5.2
|
72
72
|
signing_key:
|
73
73
|
specification_version: 4
|
74
74
|
summary: A simple command pattern gem
|