balboa 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -6
- data/bin/balboa +6 -6
- data/lib/balboa/cli/application.rb +1 -1
- data/lib/balboa/cli/command/last_command.rb +1 -1
- data/lib/balboa/cli/command/punch_command.rb +4 -3
- data/lib/balboa/cli/defaults.rb +19 -17
- data/lib/balboa/cli/parser.rb +133 -0
- data/lib/balboa/interactor/capybara_interactor.rb +6 -5
- data/lib/balboa/interactor/command/fetch_last_punch_command.rb +1 -1
- data/lib/balboa/interactor/command/fill_punch_command.rb +1 -1
- data/lib/balboa/interactor/command/login_command.rb +2 -2
- data/lib/balboa/interactor/interactor_builder.rb +1 -1
- data/lib/balboa/interactor/interactor_wrapper.rb +1 -1
- data/lib/balboa/version.rb +1 -1
- data/spec/balboa/capybara_interactor_spec.rb +2 -8
- data/spec/balboa/cli/application_spec.rb +4 -7
- data/spec/balboa/cli/command/last_command_spec.rb +13 -0
- data/spec/balboa/cli/command/reset_command_spec.rb +21 -0
- data/spec/balboa/cli/command/star_wars_command_spec.rb +13 -0
- data/spec/balboa/cli/parser_spec.rb +171 -0
- data/spec/balboa/interactor/interactor_builder_spec.rb +19 -0
- data/spec/balboa/punch_date_spec.rb +7 -7
- data/spec/fixtures/file.yml +9 -0
- metadata +9 -3
- data/lib/balboa/cli/parser_builder.rb +0 -122
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c75e34d3e6ac77e6c54426f34b818a6ab89f062
|
4
|
+
data.tar.gz: 6a5a659d87bcb2411cc32e5a2271c7cef6298465
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f31f8113ddfc943b705d51a49131d831492e2c212fbab4d9a4127a41201874ddcc6fcdf66ec4ff06ceda1418624325bbe784afe93de2dedd2718be9668c6092
|
7
|
+
data.tar.gz: f2dd74759422b457b08be14979023417c4691ee94d8e4e1b59cf29038c5ea84e342c468114be927e02e605d7842e26ca8b46eb460dd51b0e8dd31ab1acdce636
|
data/Rakefile
CHANGED
@@ -23,10 +23,6 @@ end
|
|
23
23
|
namespace :test do
|
24
24
|
RSpec::Core::RakeTask.new(:spec)
|
25
25
|
|
26
|
-
Cucumber::Rake::Task.new(:features) do |t|
|
27
|
-
t.cucumber_opts = 'features --format progress --color'
|
28
|
-
end
|
29
|
-
|
30
26
|
task :mutant do
|
31
27
|
command = <<-EOS
|
32
28
|
RUBY_THREAD_VM_STACK_SIZE=64000\
|
@@ -34,7 +30,6 @@ namespace :test do
|
|
34
30
|
--include lib\
|
35
31
|
--require balboa\
|
36
32
|
--use rspec\
|
37
|
-
--since master^\
|
38
33
|
--jobs 4 'Balboa*'
|
39
34
|
EOS
|
40
35
|
system command
|
@@ -44,6 +39,6 @@ namespace :test do
|
|
44
39
|
task all: ['test:spec', 'test:features', :mutant]
|
45
40
|
end
|
46
41
|
|
47
|
-
task ci: ['test:
|
42
|
+
task ci: ['test:spec', 'quality:all']
|
48
43
|
|
49
44
|
task default: :ci
|
data/bin/balboa
CHANGED
@@ -2,18 +2,18 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require_relative '../lib/balboa'
|
5
|
-
require_relative '../lib/balboa/cli/
|
5
|
+
require_relative '../lib/balboa/cli/parser'
|
6
6
|
require_relative '../lib/balboa/interactor/interactor_builder'
|
7
7
|
|
8
8
|
require 'highline/import'
|
9
9
|
|
10
10
|
options = if File.exist?(Balboa::CONFIG_FILE)
|
11
|
-
|
12
|
-
else
|
13
|
-
|
14
|
-
end
|
11
|
+
YAML.load_file(Balboa::CONFIG_FILE)
|
12
|
+
else
|
13
|
+
Balboa::CLI::Defaults.prompt(HighLine)
|
14
|
+
end
|
15
15
|
|
16
|
-
Balboa::CLI::
|
16
|
+
Balboa::CLI::Parser.parse(ARGV, options)
|
17
17
|
|
18
18
|
raw_interactor = Balboa::Interactor::InteractorBuilder.create(options)
|
19
19
|
interactor = Balboa::Interactor::InteractorWrapper.new(raw_interactor)
|
@@ -12,10 +12,11 @@ module Balboa
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def execute
|
15
|
-
punch_dates.
|
16
|
-
$stdout.print("\n#{date.strftime("%d/%m/%Y")}")
|
15
|
+
punch_dates.reject! { |date| skip_date?(date) }
|
17
16
|
|
18
|
-
|
17
|
+
punch_dates.each do |date|
|
18
|
+
$stdout.print("\n#{date.strftime('%d/%m/%Y')}")
|
19
|
+
@interactor.punch(date)
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
data/lib/balboa/cli/defaults.rb
CHANGED
@@ -9,7 +9,7 @@ module Balboa
|
|
9
9
|
new(*args).prompt
|
10
10
|
end
|
11
11
|
|
12
|
-
def initialize(cli, config={})
|
12
|
+
def initialize(cli, config = {})
|
13
13
|
@config = config
|
14
14
|
@cli = cli
|
15
15
|
end
|
@@ -28,25 +28,27 @@ module Balboa
|
|
28
28
|
|
29
29
|
def create_file
|
30
30
|
@config.reject! { |_, key| key.empty? }
|
31
|
-
@config
|
31
|
+
@config['skips'] = []
|
32
32
|
|
33
|
-
File.open(Balboa::CONFIG_FILE, 'w')
|
33
|
+
File.open(Balboa::CONFIG_FILE, 'w') do |file|
|
34
|
+
file.write(@config.to_yaml)
|
35
|
+
end
|
34
36
|
end
|
35
37
|
|
36
38
|
def prompt_attributes
|
37
|
-
@config
|
38
|
-
@config
|
39
|
-
@config
|
39
|
+
@config['email'] = prompt_email
|
40
|
+
@config['password'] = prompt_password
|
41
|
+
@config['project'] = prompt_project
|
40
42
|
end
|
41
43
|
|
42
44
|
def prompt_email
|
43
|
-
@cli.ask(
|
45
|
+
@cli.ask('E-mail: ')
|
44
46
|
end
|
45
47
|
|
46
48
|
def prompt_password
|
47
|
-
@cli.say("\
|
49
|
+
@cli.say("\nPassword can be stored as text or passed via option!")
|
48
50
|
|
49
|
-
@cli.ask(
|
51
|
+
@cli.ask('Password: ') { |qst| qst.echo = '*' }
|
50
52
|
end
|
51
53
|
|
52
54
|
def prompt_project
|
@@ -54,26 +56,26 @@ module Balboa
|
|
54
56
|
end
|
55
57
|
|
56
58
|
def prompt_schedule
|
57
|
-
@config
|
58
|
-
@config
|
59
|
-
@config
|
60
|
-
@config
|
59
|
+
@config['start_at'] = prompt_start
|
60
|
+
@config['lunch_at'] = prompt_lunch
|
61
|
+
@config['restart_at'] = prompt_restart
|
62
|
+
@config['leave_at'] = prompt_leave
|
61
63
|
end
|
62
64
|
|
63
65
|
def prompt_start
|
64
|
-
@cli.ask("\nFirst shift: ") { |qst| qst.default =
|
66
|
+
@cli.ask("\nFirst shift: ") { |qst| qst.default = '8' }
|
65
67
|
end
|
66
68
|
|
67
69
|
def prompt_lunch
|
68
|
-
@cli.ask("\nLunch: ") { |qst| qst.default =
|
70
|
+
@cli.ask("\nLunch: ") { |qst| qst.default = '12' }
|
69
71
|
end
|
70
72
|
|
71
73
|
def prompt_restart
|
72
|
-
@cli.ask("\nSecond shift: ") { |qst| qst.default =
|
74
|
+
@cli.ask("\nSecond shift: ") { |qst| qst.default = '13' }
|
73
75
|
end
|
74
76
|
|
75
77
|
def prompt_leave
|
76
|
-
@cli.ask("\nLeave: ") { |qst| qst.default =
|
78
|
+
@cli.ask("\nLeave: ") { |qst| qst.default = '17' }
|
77
79
|
end
|
78
80
|
end
|
79
81
|
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module Balboa
|
7
|
+
module CLI
|
8
|
+
class Parser
|
9
|
+
def self.parse(*args)
|
10
|
+
new(*args).parse
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(argv, default_config)
|
14
|
+
@config = default_config
|
15
|
+
@argv = argv
|
16
|
+
@parser = OptionParser.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse
|
20
|
+
configure_parser
|
21
|
+
|
22
|
+
@parser.parse!(@argv)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def configure_parser
|
28
|
+
program_name = @parser.program_name
|
29
|
+
|
30
|
+
@parser.banner = <<-EOF.gsub(/^[ ]+/, '')
|
31
|
+
\nUsage: #{program_name} [commands] [options]"
|
32
|
+
|
33
|
+
Commands:
|
34
|
+
|
35
|
+
#{program_name} last
|
36
|
+
#{program_name} punch -p '123456' -s '12/06/1992,13/06/1992,14/06/1992'
|
37
|
+
#{program_name} reset
|
38
|
+
EOF
|
39
|
+
|
40
|
+
set_options
|
41
|
+
set_utilities
|
42
|
+
end
|
43
|
+
|
44
|
+
def set_options
|
45
|
+
@parser.separator "\nOptions:"
|
46
|
+
set_attributes
|
47
|
+
set_skipped_dates
|
48
|
+
set_custom_defaults
|
49
|
+
end
|
50
|
+
|
51
|
+
def set_utilities
|
52
|
+
@parser.separator "\nUtilities:"
|
53
|
+
set_help_option
|
54
|
+
set_version_option
|
55
|
+
set_balboa_picture
|
56
|
+
end
|
57
|
+
|
58
|
+
def set_custom_defaults
|
59
|
+
message = 'Read configuration options from FILE'
|
60
|
+
|
61
|
+
@parser.on('-c', '--config \'FILE\'', message) do |file|
|
62
|
+
@config.merge!(YAML.load_file(file))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# :reek:TooManyStatements
|
67
|
+
def set_attributes
|
68
|
+
@parser.on('-e', '--email \'EMAIL\'') do |email|
|
69
|
+
@config['email'] = email
|
70
|
+
end
|
71
|
+
|
72
|
+
@parser.on('-p', '--password \'PASSWORD\'') do |password|
|
73
|
+
@config['password'] = password
|
74
|
+
end
|
75
|
+
|
76
|
+
@parser.on('-w', '--project \'PROJECT\'') do |project|
|
77
|
+
@config['project'] = project
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def set_skipped_dates
|
82
|
+
message = 'Skip input dates'
|
83
|
+
|
84
|
+
@parser.on('-s', '--skip \'DATES\'', message, Array) do |dates|
|
85
|
+
parse_dates(dates)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def parse_dates(dates)
|
90
|
+
@config.merge!('skips' => dates.map { |date| Date.parse(date) })
|
91
|
+
end
|
92
|
+
|
93
|
+
def set_help_option
|
94
|
+
@parser.on('-h', '--help', 'Show this message') do
|
95
|
+
$stdout.puts @parser
|
96
|
+
exit
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def set_version_option
|
101
|
+
@parser.on('-v', '--version', 'Show version') do
|
102
|
+
$stdout.puts "#{@parser.program_name} #{Balboa::VERSION}\n"
|
103
|
+
exit
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# rubocop:disable Metrics/MethodLength
|
108
|
+
def set_balboa_picture
|
109
|
+
@parser.separator("\n" + [
|
110
|
+
'░░░░░░▄▄███████████████▄▄░░░░',
|
111
|
+
'░░░▄██████████████████████▄░░',
|
112
|
+
'░░█████████▀███████▀████████░',
|
113
|
+
'░█████████▀▀█▀█░░▀██▄██▄████░',
|
114
|
+
'░░████████▄▄█░▀▀▄▄█░░▀░████░░',
|
115
|
+
'░░███████▀░░░▄▄▄▄░░░▄▄▄███░░░',
|
116
|
+
'░▀███████░░▄▀▀██▀░░█▄░▄▀███░░',
|
117
|
+
'░░██████▀░░█░██▀▀░░████░██░░░',
|
118
|
+
'░████████░░░░▀▀░░░░▀▄░▀▀█░░░░',
|
119
|
+
'░█▀██████░░░░░░░░░░░░█░░█░░░░',
|
120
|
+
'░▀▄████▄▀░░░░░░░░░░░▀▀░░░█░░░',
|
121
|
+
'░▄██████▀▄░░░░░░░░░▄▄▄░░░█░░░',
|
122
|
+
'░███████░█░░░░░░░░██▄▄█░░░█░░',
|
123
|
+
'░░██████░░█░░░░░░░░░░░░░░░█░░',
|
124
|
+
'░▀▄█████░░░▀▄░░░░░░░░░░░░▄▀░░',
|
125
|
+
'░░░░███▀░░░░░▀▀▀█▄▄▄░░░░█▀░░░',
|
126
|
+
'░░░░▄▀░░░░░░░░░▀▄░░░██▀▀▀░░░░',
|
127
|
+
'░░▄▀░░░░░░░░░░░░░░▀░░▀▀▀▀▀▄░░',
|
128
|
+
'▄▀░░░░░░░░░░░░░░░░░░░░░░▄░█▀▄'
|
129
|
+
].join("\n"))
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -3,19 +3,18 @@
|
|
3
3
|
module Balboa
|
4
4
|
module Interactor
|
5
5
|
class CapybaraInteractor
|
6
|
-
|
7
6
|
CommandNotFound = Class.new(RuntimeError)
|
8
7
|
|
9
8
|
LoginCommandNotFound = Class.new(RuntimeError)
|
10
9
|
|
11
10
|
attr_reader :options
|
12
11
|
|
13
|
-
def initialize(options={})
|
12
|
+
def initialize(options = {})
|
14
13
|
@options = options
|
15
|
-
@commands = Hash.new {
|
14
|
+
@commands = Hash.new { raise CommandNotFound }
|
16
15
|
@signed_in = false
|
17
16
|
end
|
18
|
-
|
17
|
+
|
19
18
|
def add_command(key, command)
|
20
19
|
@commands[key.to_s] = command
|
21
20
|
end
|
@@ -34,7 +33,9 @@ module Balboa
|
|
34
33
|
|
35
34
|
attr_accessor :signed_in
|
36
35
|
|
37
|
-
|
36
|
+
def signed_in?
|
37
|
+
signed_in
|
38
|
+
end
|
38
39
|
|
39
40
|
def login
|
40
41
|
@commands['login'].execute
|
data/lib/balboa/version.rb
CHANGED
@@ -28,15 +28,12 @@ describe Balboa::Interactor::CapybaraInteractor do
|
|
28
28
|
it 'responds to last but raises if no command provided' do
|
29
29
|
interactor = described_class.new
|
30
30
|
|
31
|
-
last = double('cmd', execute: nil)
|
32
31
|
login = double('login', execute: nil)
|
33
32
|
|
34
33
|
interactor.add_command('login', login)
|
35
34
|
|
36
35
|
error = Balboa::Interactor::CapybaraInteractor::CommandNotFound
|
37
|
-
expect {
|
38
|
-
interactor.last
|
39
|
-
}.to raise_error error
|
36
|
+
expect { interactor.last }.to raise_error error
|
40
37
|
end
|
41
38
|
|
42
39
|
it 'holds the options so commands can use it' do
|
@@ -48,15 +45,12 @@ describe Balboa::Interactor::CapybaraInteractor do
|
|
48
45
|
it 'responds to punch but raises if no command provided' do
|
49
46
|
interactor = described_class.new
|
50
47
|
|
51
|
-
punch = double('cmd', execute: nil)
|
52
48
|
login = double('login', execute: nil)
|
53
49
|
|
54
50
|
interactor.add_command('login', login)
|
55
51
|
|
56
52
|
error = Balboa::Interactor::CapybaraInteractor::CommandNotFound
|
57
|
-
expect {
|
58
|
-
interactor.punch(Date.today)
|
59
|
-
}.to raise_error error
|
53
|
+
expect { interactor.punch(Date.today) }.to raise_error error
|
60
54
|
end
|
61
55
|
|
62
56
|
it 'signs in only once' do
|
@@ -36,17 +36,14 @@ describe Balboa::CLI::Application do
|
|
36
36
|
allow(command).to receive(:execute).and_raise
|
37
37
|
|
38
38
|
app.add_command(:cmd, command)
|
39
|
-
|
40
|
-
expect {
|
41
|
-
app.execute
|
42
|
-
}.to raise_error(RuntimeError)
|
39
|
+
|
40
|
+
expect { app.execute }.to raise_error(RuntimeError)
|
43
41
|
end
|
44
42
|
|
45
43
|
it 'raises error when command not found' do
|
46
44
|
app = described_class.new('cmd')
|
47
45
|
|
48
|
-
|
49
|
-
|
50
|
-
}.to raise_error(Balboa::CLI::Application::CommandNotFound)
|
46
|
+
error = Balboa::CLI::Application::CommandNotFound
|
47
|
+
expect { app.execute }.to raise_error(error)
|
51
48
|
end
|
52
49
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Balboa::CLI::Command::LastCommand do
|
6
|
+
it 'prints out the result of interactor last method' do
|
7
|
+
interactor = double('itr', last: 42)
|
8
|
+
|
9
|
+
expect(STDOUT).to receive(:puts).with("\n42")
|
10
|
+
|
11
|
+
described_class.new(interactor).execute
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Balboa::CLI::Command::ResetCommand do
|
6
|
+
it 'deletes the .balboa.yml file' do
|
7
|
+
expect(File).to receive(:delete).with('.balboa.yml')
|
8
|
+
|
9
|
+
described_class.new.execute
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'prints out a success message' do
|
13
|
+
success_message = "\nBalboa restored to initial settings!"
|
14
|
+
|
15
|
+
allow(File).to receive(:delete).with('.balboa.yml')
|
16
|
+
|
17
|
+
expect(STDOUT).to receive(:puts).with(success_message)
|
18
|
+
|
19
|
+
described_class.new.execute
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Balboa::CLI::Command::StarWarsCommand do
|
6
|
+
it 'is a trap!' do
|
7
|
+
command = described_class.new
|
8
|
+
|
9
|
+
expect(command).to receive(:system).with('telnet towel.blinkenlights.nl')
|
10
|
+
|
11
|
+
command.execute
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
require_relative '../../../lib/balboa/cli/parser'
|
6
|
+
|
7
|
+
describe Balboa::CLI::Parser do
|
8
|
+
it 'parses a password option into a hash of configurations' do
|
9
|
+
config = {}
|
10
|
+
argv = ['-p', 'test']
|
11
|
+
|
12
|
+
described_class.parse(argv, config)
|
13
|
+
|
14
|
+
expect(config).to eq('password' => 'test')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'parses a password full option into a hash of configurations' do
|
18
|
+
config = {}
|
19
|
+
argv = ['--password', 'test']
|
20
|
+
|
21
|
+
described_class.parse(argv, config)
|
22
|
+
|
23
|
+
expect(config).to eq('password' => 'test')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'parses a project option into a hash of configurations' do
|
27
|
+
config = {}
|
28
|
+
argv = ['-w', 'test']
|
29
|
+
|
30
|
+
described_class.parse(argv, config)
|
31
|
+
|
32
|
+
expect(config).to eq('project' => 'test')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'parses a project full option into a hash of configurations' do
|
36
|
+
config = {}
|
37
|
+
argv = ['--project', 'test']
|
38
|
+
|
39
|
+
described_class.parse(argv, config)
|
40
|
+
|
41
|
+
expect(config).to eq('project' => 'test')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'parses a email option into a hash of configurations' do
|
45
|
+
config = {}
|
46
|
+
argv = ['-e', 'test']
|
47
|
+
|
48
|
+
described_class.parse(argv, config)
|
49
|
+
|
50
|
+
expect(config).to eq('email' => 'test')
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'parses a email full option into a hash of configurations' do
|
54
|
+
config = {}
|
55
|
+
argv = ['--email', 'test']
|
56
|
+
|
57
|
+
described_class.parse(argv, config)
|
58
|
+
|
59
|
+
expect(config).to eq('email' => 'test')
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'parses a config option into a hash of configurations' do
|
63
|
+
config = {}
|
64
|
+
argv = ['-c', 'spec/fixtures/file.yml']
|
65
|
+
|
66
|
+
described_class.parse(argv, config)
|
67
|
+
|
68
|
+
expectation = {
|
69
|
+
'email' => 'email',
|
70
|
+
'password' => 'password',
|
71
|
+
'project' => 'project',
|
72
|
+
'start_at' => '8',
|
73
|
+
'lunch_at' => '12',
|
74
|
+
'restart_at' => '13',
|
75
|
+
'leave_at' => '17',
|
76
|
+
'skips' => []
|
77
|
+
}
|
78
|
+
expect(config).to eq(expectation)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'parses a config full option into a hash of configurations' do
|
82
|
+
config = {}
|
83
|
+
argv = ['--config', 'spec/fixtures/file.yml']
|
84
|
+
|
85
|
+
described_class.parse(argv, config)
|
86
|
+
|
87
|
+
expectation = {
|
88
|
+
'email' => 'email',
|
89
|
+
'password' => 'password',
|
90
|
+
'project' => 'project',
|
91
|
+
'start_at' => '8',
|
92
|
+
'lunch_at' => '12',
|
93
|
+
'restart_at' => '13',
|
94
|
+
'leave_at' => '17',
|
95
|
+
'skips' => []
|
96
|
+
}
|
97
|
+
expect(config).to eq(expectation)
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'raises ENOENT on invalid path to file' do
|
101
|
+
config = {}
|
102
|
+
argv = ['-c', 'wrong path to file']
|
103
|
+
|
104
|
+
parser = described_class.new(argv, config)
|
105
|
+
|
106
|
+
expect { parser.parse }.to raise_error(Errno::ENOENT)
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'parses a skipped date option into a hash of configurations' do
|
110
|
+
config = {}
|
111
|
+
argv = ['-s', '13/06/1992,15/06/2002']
|
112
|
+
|
113
|
+
described_class.parse(argv, config)
|
114
|
+
|
115
|
+
expectation = {
|
116
|
+
'skips' => [
|
117
|
+
Date.new(1992, 6, 13), Date.new(2002, 6, 15)
|
118
|
+
]
|
119
|
+
}
|
120
|
+
expect(config).to eq(expectation)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'raises argument error in case of a wrong date format' do
|
124
|
+
config = {}
|
125
|
+
argv = ['-s', 'test']
|
126
|
+
|
127
|
+
parser = described_class.new(argv, config)
|
128
|
+
|
129
|
+
expect { parser.parse }.to raise_error(ArgumentError)
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'parses a skipped date full option into a hash of configurations' do
|
133
|
+
config = {}
|
134
|
+
argv = ['--skip', '12/06/1992,12/06/1992']
|
135
|
+
|
136
|
+
described_class.parse(argv, config)
|
137
|
+
|
138
|
+
expectation = {
|
139
|
+
'skips' => [
|
140
|
+
Date.new(1992, 6, 12), Date.new(1992, 6, 12)
|
141
|
+
]
|
142
|
+
}
|
143
|
+
expect(config).to eq(expectation)
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'parses options that override or fulfill config' do
|
147
|
+
config = {
|
148
|
+
'password' => '1',
|
149
|
+
'project' => '3'
|
150
|
+
}
|
151
|
+
argv = ['-p', '3', '-e', '2', '-w', '1']
|
152
|
+
|
153
|
+
described_class.parse(argv, config)
|
154
|
+
|
155
|
+
expectation = {
|
156
|
+
'password' => '3',
|
157
|
+
'email' => '2',
|
158
|
+
'project' => '1'
|
159
|
+
}
|
160
|
+
|
161
|
+
expect(config).to eq(expectation)
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'raises on invalid arguments' do
|
165
|
+
config = {}
|
166
|
+
argv = ['-z']
|
167
|
+
parser = described_class.new(argv, config)
|
168
|
+
|
169
|
+
expect { parser.parse }.to raise_error(OptionParser::InvalidOption)
|
170
|
+
end
|
171
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
require_relative '../../../lib/balboa/interactor/interactor_builder'
|
6
|
+
|
7
|
+
describe Balboa::Interactor::InteractorBuilder do
|
8
|
+
it 'responds to create as class method' do
|
9
|
+
interactor = described_class.create({})
|
10
|
+
|
11
|
+
expect(interactor).not_to be nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'responds to create as instance method' do
|
15
|
+
interactor = described_class.new({}).create
|
16
|
+
|
17
|
+
expect(interactor).not_to be nil
|
18
|
+
end
|
19
|
+
end
|
@@ -5,14 +5,14 @@ require 'highline/import'
|
|
5
5
|
|
6
6
|
describe Balboa::PunchDate do
|
7
7
|
it 'responds to to_s' do
|
8
|
-
date = Date.new(2011,1,1)
|
8
|
+
date = Date.new(2011, 1, 1)
|
9
9
|
punch_date = described_class.new(date, nil)
|
10
10
|
|
11
11
|
expect(punch_date.to_s).to eq('2011-01-01')
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'responds to strftime' do
|
15
|
-
date = Date.new(2011,1,1)
|
15
|
+
date = Date.new(2011, 1, 1)
|
16
16
|
punch_date = described_class.new(date, nil)
|
17
17
|
|
18
18
|
expect(punch_date.strftime('%d/%m/%Y')).to eq('01/01/2011')
|
@@ -20,21 +20,21 @@ describe Balboa::PunchDate do
|
|
20
20
|
|
21
21
|
context 'punchable' do
|
22
22
|
it 'returns false on satudays' do
|
23
|
-
date = Date.new(2011,1,1)
|
23
|
+
date = Date.new(2011, 1, 1)
|
24
24
|
punch_date = described_class.new(date, nil)
|
25
25
|
|
26
26
|
expect(punch_date.punchable?).to be false
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'returns false on sundays' do
|
30
|
-
date = Date.new(2011,1,2)
|
30
|
+
date = Date.new(2011, 1, 2)
|
31
31
|
punch_date = described_class.new(date, nil)
|
32
32
|
|
33
33
|
expect(punch_date.punchable?).to be false
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'returns true on a week day that is not a holiday' do
|
37
|
-
date = Date.new(2011,1,3)
|
37
|
+
date = Date.new(2011, 1, 3)
|
38
38
|
punch_date = described_class.new(date, nil)
|
39
39
|
|
40
40
|
expect(punch_date.punchable?).to be true
|
@@ -45,7 +45,7 @@ describe Balboa::PunchDate do
|
|
45
45
|
output = StringIO.new
|
46
46
|
cli = HighLine.new(input, output)
|
47
47
|
|
48
|
-
date = Date.new(2011,4,21)
|
48
|
+
date = Date.new(2011, 4, 21)
|
49
49
|
punch_date = described_class.new(date, cli)
|
50
50
|
|
51
51
|
expect(punch_date.punchable?).to be false
|
@@ -56,7 +56,7 @@ describe Balboa::PunchDate do
|
|
56
56
|
output = StringIO.new
|
57
57
|
cli = HighLine.new(input, output)
|
58
58
|
|
59
|
-
date = Date.new(2011,4,21)
|
59
|
+
date = Date.new(2011, 4, 21)
|
60
60
|
punch_date = described_class.new(date, cli)
|
61
61
|
|
62
62
|
expect(punch_date.punchable?).to be true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: balboa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Waldyr de Souza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -96,7 +96,7 @@ files:
|
|
96
96
|
- lib/balboa/cli/command/reset_command.rb
|
97
97
|
- lib/balboa/cli/command/star_wars_command.rb
|
98
98
|
- lib/balboa/cli/defaults.rb
|
99
|
-
- lib/balboa/cli/
|
99
|
+
- lib/balboa/cli/parser.rb
|
100
100
|
- lib/balboa/config_file.rb
|
101
101
|
- lib/balboa/host.rb
|
102
102
|
- lib/balboa/interactor/capybara_interactor.rb
|
@@ -109,10 +109,16 @@ files:
|
|
109
109
|
- lib/balboa/version.rb
|
110
110
|
- spec/balboa/capybara_interactor_spec.rb
|
111
111
|
- spec/balboa/cli/application_spec.rb
|
112
|
+
- spec/balboa/cli/command/last_command_spec.rb
|
113
|
+
- spec/balboa/cli/command/reset_command_spec.rb
|
114
|
+
- spec/balboa/cli/command/star_wars_command_spec.rb
|
112
115
|
- spec/balboa/cli/defaults_spec.rb
|
116
|
+
- spec/balboa/cli/parser_spec.rb
|
117
|
+
- spec/balboa/interactor/interactor_builder_spec.rb
|
113
118
|
- spec/balboa/interactor/interactor_wrapper_spec.rb
|
114
119
|
- spec/balboa/punch_date_spec.rb
|
115
120
|
- spec/balboa_spec.rb
|
121
|
+
- spec/fixtures/file.yml
|
116
122
|
- spec/spec_helper.rb
|
117
123
|
homepage:
|
118
124
|
licenses:
|
@@ -1,122 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'optparse'
|
4
|
-
require 'yaml'
|
5
|
-
|
6
|
-
module Balboa
|
7
|
-
module CLI
|
8
|
-
class ParserBuilder
|
9
|
-
def self.create(*args)
|
10
|
-
new(*args).create
|
11
|
-
end
|
12
|
-
|
13
|
-
def initialize(argv, config)
|
14
|
-
@config = config
|
15
|
-
@parser = OptionParser.new(argv)
|
16
|
-
end
|
17
|
-
|
18
|
-
def create
|
19
|
-
configure_parser
|
20
|
-
|
21
|
-
@parser
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def configure_parser
|
27
|
-
program_name = @parser.program_name
|
28
|
-
|
29
|
-
@parser.banner = <<-EOF.gsub(/^[ ]+/, '')
|
30
|
-
\nUsage: #{program_name} [commands] [options]"
|
31
|
-
|
32
|
-
Commands:
|
33
|
-
|
34
|
-
#{program_name} last
|
35
|
-
#{program_name} punch -p '123456' -s '12/06/1992,13/06/1992,14/06/1992'
|
36
|
-
#{program_name} reset
|
37
|
-
EOF
|
38
|
-
|
39
|
-
set_options
|
40
|
-
set_utilities
|
41
|
-
end
|
42
|
-
|
43
|
-
def set_options
|
44
|
-
@parser.separator "\nOptions:"
|
45
|
-
set_attributes
|
46
|
-
set_skipped_dates
|
47
|
-
set_custom_defaults
|
48
|
-
end
|
49
|
-
|
50
|
-
def set_utilities
|
51
|
-
@parser.separator "\nUtilities:"
|
52
|
-
set_help_option
|
53
|
-
set_version_option
|
54
|
-
set_balboa_picture
|
55
|
-
end
|
56
|
-
|
57
|
-
def set_custom_defaults
|
58
|
-
@parser.on('-c', '--config \'FILE\'', 'Read configuration options from FILE') do |file|
|
59
|
-
@config.merge!(YAML.load_file(file)) if File.exist?(file)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def set_attributes
|
64
|
-
@parser.on('-e', '--email \'EMAIL\'') do |email|
|
65
|
-
@config.merge!('email' => email)
|
66
|
-
end.on('-p', '--password \'PASSWORD\'') do |password|
|
67
|
-
@config.merge!('password' => password)
|
68
|
-
end.on('-w', '--project \'PROJECT\'') do |project|
|
69
|
-
@config.merge!('project' => project)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def set_skipped_dates
|
74
|
-
@parser.on('-s', '--skip \'DATES\'', 'Skip input dates', Array) do |dates|
|
75
|
-
parse_dates(dates)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def parse_dates(dates)
|
80
|
-
@config.merge!('skips' => dates.map { |date| Date.parse(date) })
|
81
|
-
end
|
82
|
-
|
83
|
-
def set_help_option
|
84
|
-
@parser.on('-h', '--help', 'Show this message') do
|
85
|
-
$stdout.puts @parser
|
86
|
-
exit
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def set_version_option
|
91
|
-
@parser.on('-v', '--version', 'Show version') do
|
92
|
-
$stdout.puts "#{@parser.program_name} #{Balboa::VERSION}\n"
|
93
|
-
exit
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def set_balboa_picture
|
98
|
-
@parser.separator("\n" + [
|
99
|
-
"░░░░░▄▄███████████████▄▄░░░░",
|
100
|
-
"░░▄██████████████████████▄░░",
|
101
|
-
"░█████████▀███████▀████████░",
|
102
|
-
"█████████▀▀█▀█░░▀██▄██▄████░",
|
103
|
-
"░████████▄▄█░▀▀▄▄█░░▀░████░░",
|
104
|
-
"░███████▀░░░▄▄▄▄░░░▄▄▄███░░░",
|
105
|
-
"▀███████░░▄▀▀██▀░░█▄░▄▀███░░",
|
106
|
-
"░██████▀░░█░██▀▀░░████░██░░░",
|
107
|
-
"████████░▄░░▀▀░░░░▀▄░▀▀█░░░░",
|
108
|
-
"█▀██████▀░▄░░▄░░░░░░█░░█░░░░",
|
109
|
-
"▀▄████▄▀░░░▀▀░░▀░▄░░▀░░░█░░░",
|
110
|
-
"▄██████▀▄░░░░░░░░░██▄▄▄░█░░░",
|
111
|
-
"███████░█░░░░░░░░█▀▄▄▄█░░█░░",
|
112
|
-
"░██████░░█░░░░░░░░░▀░░░░░░▀▄",
|
113
|
-
"▀▄█████░░░▀▄░░░░░░░░░░░░░░░█",
|
114
|
-
"░░░███▀░░░░░░▀░░░░▄░░░░░░▄█░",
|
115
|
-
"░░░▄▀░░░░░░░░░▀▄░░░▀▀▀▀▀█▀░░",
|
116
|
-
"░▀░░░░░░░░░░░░░░░▀░░░░░░▀▄░░",
|
117
|
-
"░░░░░░░░░░░░░░░░░░░░░░░▄░█▀▄",
|
118
|
-
].join("\n"))
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|