Class: GitPusshuTen::Commands::Initialize
- Defined in:
- lib/gitpusshuten/commands/initialize.rb
Instance Attribute Summary collapse
-
#confirm_perform ⇒ Object
Incase template files already exist.
-
#working_directory ⇒ Object
Initialize specific attributes/arguments.
Attributes inherited from Base
#cli, #command, #configuration, #environment, #hooks, #perform_hooks
Instance Method Summary collapse
-
#copy_templates! ⇒ Object
Copies the “config.rb” and “hooks.rb” templates over to the .gitpusshuten inside the working directory.
-
#initialize(*objects) ⇒ Initialize
constructor
A new instance of Initialize.
-
#perform! ⇒ Object
Performs the Initialize command.
Methods inherited from Base
#c, #command_object, description, #e, #error, example, #g, #git, #help, #local, long_description, #message, #perform_hooks!, #post_perform!, #pre_perform!, #prompt_for_root_password!, #prompt_for_user_password!, #r, #requires_user_existence!, #silent, #standard, usage, #validate!, #warning, #y, #yes?
Constructor Details
#initialize(*objects) ⇒ Initialize
Returns a new instance of Initialize.
17 18 19 20 21 22 |
# File 'lib/gitpusshuten/commands/initialize.rb', line 17 def initialize(*objects) super @working_directory = Dir.pwd @confirm_perform = true end |
Instance Attribute Details
#confirm_perform ⇒ Object
Incase template files already exist
15 16 17 |
# File 'lib/gitpusshuten/commands/initialize.rb', line 15 def confirm_perform @confirm_perform end |
#working_directory ⇒ Object
Initialize specific attributes/arguments
11 12 13 |
# File 'lib/gitpusshuten/commands/initialize.rb', line 11 def working_directory @working_directory end |
Instance Method Details
#copy_templates! ⇒ Object
Copies the “config.rb” and “hooks.rb” templates over to the .gitpusshuten inside the working directory
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/gitpusshuten/commands/initialize.rb', line 42 def copy_templates! if File.directory?(File.join(working_directory, '.gitpusshuten')) warning "Git Pusshu Ten (プッシュ天) is already initialized in #{y(working_directory)}." warning "Re-initializing it will cause it to overwrite the current #{y("config.rb")} and #{y("hooks.rb")} files." warning "Are you sure you wish to continue?" @confirm_perform = yes? end if confirm_perform FileUtils.mkdir_p("#{working_directory}/.gitpusshuten") Dir[File.(File.join(File.dirname(__FILE__), '..', '..', 'templates', '*.rb'))].each do |template| FileUtils.cp(template, "#{working_directory}/.gitpusshuten/#{template.split('/').last}") end "Git Pusshu Ten (プッシュ天) initialized in: #{y(working_directory)}!" end end |
#perform! ⇒ Object
Performs the Initialize command
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/gitpusshuten/commands/initialize.rb', line 26 def perform! "Would you like to initialize Git Pusshu Ten (プッシュ天) with #{working_directory}?" if yes? copy_templates! if not git.initialized? git.initialize! end git.ignore! else "If you wish to initialize it elsewhere, please move into that directory and run #{y("heavenly initialize")} again." end end |