Class: Branchtree::Commands::Common

Inherits:
Object
  • Object
show all
Includes:
Branchtree::Context, TTY::Option
Defined in:
lib/branchtree/commands/common.rb

Direct Known Subclasses

Checkout, Edit, Help, Parent, Show, Update

Instance Method Summary collapse

Methods included from Branchtree::Context

logger

Instance Method Details

#executeObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/branchtree/commands/common.rb', line 34

def execute
  if params[:help]
    puts help
    exit 0
  end

  if params[:loglevel]
    logger.log_at(params[:loglevel].to_sym)
    logger.debug "Logging at level #{params[:loglevel]}."
  end
end

#load_situationObject



46
47
48
# File 'lib/branchtree/commands/common.rb', line 46

def load_situation
  Situation.new.tap(&:read)
end

#load_treeObject



50
51
52
53
# File 'lib/branchtree/commands/common.rb', line 50

def load_tree
  logger.debug "Loading mapfile from #{params[:mapfile]}."
  Tree.load(params[:mapfile])
end

#pluralize(quantity, word, plural: "#{word}s") ⇒ Object



55
56
57
58
59
60
61
# File 'lib/branchtree/commands/common.rb', line 55

def pluralize(quantity, word, plural: "#{word}s")
  if quantity == 1
    "1 #{word}"
  else
    "#{quantity} #{plural}"
  end
end