class Dotman::Action::Link
Attributes
from[R]
to[R]
Public Class Methods
new(from, to)
click to toggle source
# File lib/dotman/actions/link.rb, line 3 def initialize(from, to) @from, @to = from, to end
Public Instance Methods
to_statement()
click to toggle source
# File lib/dotman/actions/link.rb, line 7 def to_statement Shell.statement(does_not_exist, create_link, check_link) end
Private Instance Methods
check_link()
click to toggle source
# File lib/dotman/actions/link.rb, line 19 def check_link Shell.statement(link_is_set_up, link_set_up, link_not_set_up) end
create_link()
click to toggle source
# File lib/dotman/actions/link.rb, line 27 def create_link block = [ Shell.command('ln -s "$BASE_DIR/%s" "$HOME_DIR/%s"' % pair), Shell.echo(:yellow, 'Link $BASE_DIR/%s → $HOME_DIR/%s created' % pair), ] dirname = File.dirname(pair[1]) if dirname != '.' block.prepend Shell.command('mkdir --parents $HOME_DIR/%s' % dirname) end Shell.block(block) end
does_not_exist()
click to toggle source
# File lib/dotman/actions/link.rb, line 23 def does_not_exist Shell.comparison('$HOME_DIR/' + to, '! -e') end
link_is_set_up()
click to toggle source
# File lib/dotman/actions/link.rb, line 41 def link_is_set_up Shell.comparison('$(realpath $HOME_DIR/%s)' % to, '=', '$BASE_DIR/' + from) end
link_not_set_up()
click to toggle source
# File lib/dotman/actions/link.rb, line 49 def link_not_set_up Shell.echo(:red, 'Link $BASE_DIR/%s → $HOME_DIR/%s is not set up' % pair) end
link_set_up()
click to toggle source
# File lib/dotman/actions/link.rb, line 45 def link_set_up Shell.echo(:green, 'Link $BASE_DIR/%s → $HOME_DIR/%s looking good' % pair) end
pair()
click to toggle source
# File lib/dotman/actions/link.rb, line 15 def pair [from, to] end