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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da0a543274b37fae29f538f76fad4d4f623843c9
4
- data.tar.gz: cb01c076185caf5b56cd74a40b6946e3cd39e433
3
+ metadata.gz: 5cd9e163ad88759356856bb67d1631806f3a6061
4
+ data.tar.gz: 92352f5d37a173072f885c6b44c6ae8c4b3bf64e
5
5
  SHA512:
6
- metadata.gz: bd388cbf2ad8c23963f21d7ed0201a620c573a0e1e8839087788e5a714c100ad6d23c398f6130b9c79719b1d4f0d57410d0bb0627765f7fb5ba8e44fa5eea00d
7
- data.tar.gz: 672f0c73a5ff813f6cf233b2376f8ecaa5502fbd98f2d842e86de76776b445f4027f8610a2727cfc244aacd71691175d71954f893f98eccbc86051b9ad07eedc
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
- def call
39
- end
38
+ define_method(:call) {}
40
39
  end
41
40
  end
@@ -4,6 +4,14 @@ module AyeCommander
4
4
  def initialize(info = nil)
5
5
  @info = info
6
6
  end
7
+
8
+ def inspect
9
+ "#<#{self.class}: #{self}>"
10
+ end
11
+
12
+ def to_s
13
+ message
14
+ end
7
15
  end
8
16
 
9
17
  # Raised when command specifies 'requires' and one or more required arguments
@@ -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(before around after aborted).freeze
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(receives requires returns).freeze
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
- unless [true, :requires].include?(skip_validations) || requires.empty?
57
+ if validate_required_arguments?(skip_validations)
58
58
  validate_required_arguments(args)
59
59
  end
60
60
 
61
- unless [true, :receives].include?(skip_validations) || receives.empty?
62
- validate_received_arguments(args)
63
- end
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(@limiters @succeeds @hooks).each do |var|
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(@limiters @succeeds @hooks).each do |var|
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
@@ -1,3 +1,3 @@
1
1
  module AyeCommander
2
- VERSION = '1.0.1'.freeze
2
+ VERSION = '1.0.2'.freeze
3
3
  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(taco burrito)
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(taco burrito)
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(taco burrito)
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(before around after aborted).each do |kind|
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 [:some, :method]
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 [:first, :second, :third]
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 [:second, :third, :first]
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(before after aborted).each do |kind|
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([:@variable, :other])).to eq result
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) { %i(arg1 arg2) }
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(receives requires returns).each do |limiter|
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(arg1 arg2 arg3)
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(arg1 arg2 arg4)
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(im a little teapot)
11
- expect(command.succeeds).to eq %i(im a little teapot)
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(succ1 succ2) }
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(success succ1 succ2)
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(success succ1 succ2 potato)
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(success succ1 succ2)
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
- if ENV['CODECLIMATE_REPO_TOKEN']
2
- require 'codeclimate-test-reporter'
3
- CodeClimate::TestReporter.start
4
- else
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.1
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: 2016-08-15 00:00:00.000000000 Z
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.4.8
71
+ rubygems_version: 2.5.2
72
72
  signing_key:
73
73
  specification_version: 4
74
74
  summary: A simple command pattern gem