Class: GitPusshuTen::Initializer

Inherits:
Object
  • Object
show all
Defined in:
lib/gitpusshuten/initializer.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Initializer

Method to be called from CLI/Executable



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gitpusshuten/initializer.rb', line 6

def initialize(*args)
  invoke_independent_command!(args)
  
  if not File.exist?(configuration_file)
    GitPusshuTen::Log.error "Couldn't find the GitPusshuTen configuration file in #{configuration_file}."
    exit
  end

  ##
  # Parse the CLI arguments
  cli = GitPusshuTen::CLI.new(args)

  ##
  # Load in the requested environment and it's configuration
  configuration = GitPusshuTen::Configuration.new(cli.environment).parse!(configuration_file)

  ##
  # Load in hooks
  hooks = GitPusshuTen::Hooks.new(cli.environment, configuration).parse!(hooks_file).parse_modules!

  ##
  # Configure the environment connection establisher
  environment = GitPusshuTen::Environment.new(configuration)

  ##
  # Bootstrap the command
  GitPusshuTen::Command.new(cli, configuration, hooks, environment).perform!
end

Instance Method Details

#configuration_fileObject

Path to assumed configuration file



37
38
39
# File 'lib/gitpusshuten/initializer.rb', line 37

def configuration_file
  gitpusshuten_root + '/config.rb'
end

#gitpusshuten_rootObject

Path to the assumed .gitpusshuten directory



49
50
51
# File 'lib/gitpusshuten/initializer.rb', line 49

def gitpusshuten_root
  File.expand_path(File.join(Dir.pwd, '.gitpusshuten'))
end

#hooks_fileObject

Path to assumed hooks file



43
44
45
# File 'lib/gitpusshuten/initializer.rb', line 43

def hooks_file
  gitpusshuten_root + '/hooks.rb'
end

#invoke_independent_command!(args) ⇒ Object

If a command that does not rely on an initialized environment, run it without attemping to parse environment specific files.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/gitpusshuten/initializer.rb', line 57

def invoke_independent_command!(args)
  
  ##
  # Flatten Arguments to be able to test if the array is empty
  # and not an empty array in an empty array
  args.flatten!
  
  ##
  # Parses the CLI
  cli = GitPusshuTen::CLI.new(args)
  
  ##
  # Parses the Configuration
  if File.exist?(configuration_file)
    configuration = GitPusshuTen::Configuration.new(cli.environment).parse!(configuration_file)
  else
    configuration = nil
  end
  
  ##
  # Initializes the help command by default if there aren't any arguments
  if args.empty?
    GitPusshuTen::Command.new(cli, configuration, nil, nil)
    exit
  end
  
  ##
  # Append more arguments to the array below to allow more commands
  # to invoke without initializing an environment
  if %w[help version initialize].include? args.flatten.first
    "GitPusshuTen::Commands::#{args.flatten.first.classify}".constantize.new(
      cli, configuration, nil, nil
    ).perform!
    exit
  end
end