Class: OpeningAct

Inherits:
Object
  • Object
show all
Extended by:
Inputable, Outputable, Verifiable
Defined in:
lib/opening_act.rb,
lib/opening_act/version.rb

Overview

Main class for OpeningAct

Constant Summary collapse

VERSION =
'0.1.11'.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Inputable

command_input, project_name_input, test_type_input, user_input

Methods included from Outputable

add_confirmation, curtain_call, directory_exists_commands, leave_the_stage, nested_git_confirmation, overwrite_confirmation, rename_confirmation, take_the_stage

Methods included from Verifiable

valid_characters?, valid_initial_character?, valid_name?, valid_test?

Class Attribute Details

.templateObject (readonly)

Returns the value of attribute template.



90
91
92
# File 'lib/opening_act.rb', line 90

def template
  @template
end

Class Method Details

.add_overwrite_rename_or_quitObject



26
27
28
29
30
# File 'lib/opening_act.rb', line 26

def self.add_overwrite_rename_or_quit
  directory_exists_commands
  command = command_input
  determine_action(command)
end

.correct_test_name?(test_type) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/opening_act.rb', line 32

def self.correct_test_name?(test_type)
  %w[minitest rspec].include?(test_type[1..-1])
end

.create_project_filesObject



36
37
38
39
40
41
# File 'lib/opening_act.rb', line 36

def self.create_project_files
  template.create
  template.remove_extra_files
  template.rename_files
  template.initiate_project
end

.determine_action(command) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/opening_act.rb', line 43

def self.determine_action(command)
  case command
  when 'add'              then add_confirmation
  when 'overwrite'        then overwrite_existing_dir
  when 'rename'           then rename_project
  when 'quit' || 'q'      then leave_the_stage
  else 'no command'
  end
end

.directory_exists?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/opening_act.rb', line 53

def self.directory_exists?
  Dir.exist? name
end

.flag?(test_type) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/opening_act.rb', line 57

def self.flag?(test_type)
  test_type[0] == '-'
end

.nested_git?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/opening_act.rb', line 61

def self.nested_git?
  File.exist? '.git'
end

.overwrite_existing_dirObject



65
66
67
68
69
# File 'lib/opening_act.rb', line 65

def self.overwrite_existing_dir
  FileUtils.rm_rf(template.name)

  overwrite_confirmation
end

.perform(name, test_name) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/opening_act.rb', line 14

def self.perform(name, test_name)
  return leave_the_stage if nested_git? && quit_playing?

  setup(name, test_name)
  add_overwrite_rename_or_quit while directory_exists?
  take_the_stage
  create_project_files
  curtain_call
end

.quit_playing?Boolean

Returns:

  • (Boolean)


71
72
73
74
75
# File 'lib/opening_act.rb', line 71

def self.quit_playing?
  nested_git_confirmation

  user_input.downcase != 'continue'
end

.rename_projectObject



77
78
79
80
# File 'lib/opening_act.rb', line 77

def self.rename_project
  template.name = project_name_input
  rename_confirmation
end

.setup(project_name, test_type) ⇒ Object



82
83
84
85
86
87
# File 'lib/opening_act.rb', line 82

def self.setup(project_name, test_type)
  project_name = project_name_input unless valid_name?(project_name)
  test_type = test_type_input unless valid_test?(test_type)

  @template = Template.new(project_name, test_type)
end