Class: Docman::CreateSymlinkCmd

Inherits:
Command
  • Object
show all
Defined in:
lib/docman/commands/create_symlink_cmd.rb

Instance Attribute Summary

Attributes inherited from Command

#type

Instance Method Summary collapse

Methods inherited from Command

#add_action, #add_actions, #config, create, #describe, #initialize, #perform, #prefix, register_command, #replace_placeholder, #run_actions, #run_with_hooks

Methods included from Logging

#log, logger, #logger, #prefix, #properties_info, #with_logging

Constructor Details

This class inherits a constructor from Docman::Command

Instance Method Details

#executeObject



15
16
17
18
19
20
21
22
23
# File 'lib/docman/commands/create_symlink_cmd.rb', line 15

def execute
  source_path = File.join(@context['docroot_config'].docroot_dir, self['target_dir'])
  Dir.chdir source_path
  source_pathname = Pathname.new source_path
  target_pathname = Pathname.new @context['full_build_path']
  relative_path = target_pathname.relative_path_from source_pathname
  `ln -f -s #{relative_path} .`
  log "Created symlink in #{source_path} dir: '#{@context['name']}' to '#{relative_path}'"
end

#validate_commandObject



8
9
10
11
12
13
# File 'lib/docman/commands/create_symlink_cmd.rb', line 8

def validate_command
  raise "Please provide 'target_dir' param" if self['target_dir'].nil?
  raise "Please provide 'context'" if @context.nil?
  raise "Context should be of type 'Info'" unless @context.is_a? Docman::Info
  raise "Directory #{File.join(@context['docroot_config'].docroot_dir, self['target_dir'])} not exists" unless File.directory? File.join(@context['docroot_config'].docroot_dir, self['target_dir'])
end