Class: Wordmove::Guardian

Inherits:
Object
  • Object
show all
Defined in:
lib/wordmove/guardian.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cli_options: nil, action: nil) ⇒ Guardian

Returns a new instance of Guardian.



5
6
7
8
9
10
# File 'lib/wordmove/guardian.rb', line 5

def initialize(cli_options: nil, action: nil)
  @movefile = Wordmove::Movefile.new(cli_options, nil, false)
  @environment = @movefile.environment.to_sym
  @action = action
  @logger = Logger.new($stdout).tap { |l| l.level = Logger::DEBUG }
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



3
4
5
# File 'lib/wordmove/guardian.rb', line 3

def action
  @action
end

#environmentObject (readonly)

Returns the value of attribute environment.



3
4
5
# File 'lib/wordmove/guardian.rb', line 3

def environment
  @environment
end

#loggerObject (readonly)

Returns the value of attribute logger.



3
4
5
# File 'lib/wordmove/guardian.rb', line 3

def logger
  @logger
end

#movefileObject (readonly)

Returns the value of attribute movefile.



3
4
5
# File 'lib/wordmove/guardian.rb', line 3

def movefile
  @movefile
end

Instance Method Details

#allow?(task) ⇒ Boolean Also known as: allows

Predicate form for checking if a task is allowed.

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
# File 'lib/wordmove/guardian.rb', line 13

def allow?(task)
  if forbidden?(task)
    logger.task("#{action.capitalize}ing #{task.capitalize}")
    logger.warn("You tried to #{action} #{task}, but is forbidden by configuration. Skipping")
  end

  !forbidden?(task)
end