class Wordmove::Guardian

Attributes

action[R]
environment[R]
logger[R]
movefile[R]

Public Class Methods

new(options: nil, action: nil) click to toggle source
# File lib/wordmove/guardian.rb, line 5
def initialize(options: nil, action: nil)
  @movefile = Wordmove::Movefile.new(options[:config])
  @environment = @movefile.environment(options).to_sym
  @action = action
  @logger = Logger.new(STDOUT).tap { |l| l.level = Logger::DEBUG }
end

Public Instance Methods

allows(task) click to toggle source
# File lib/wordmove/guardian.rb, line 12
def allows(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

Private Instance Methods

forbidden?(task) click to toggle source
# File lib/wordmove/guardian.rb, line 23
def forbidden?(task)
  return false unless forbidden_tasks[task].present?

  forbidden_tasks[task] == true
end
forbidden_tasks() click to toggle source
# File lib/wordmove/guardian.rb, line 29
def forbidden_tasks
  environment_options = movefile.fetch(false)[environment]
  return {} unless environment_options.key?(:forbid)
  return {} unless environment_options[:forbid].key?(action)

  environment_options[:forbid][action]
end