class Pineapples::Actions::Target

Constants

FILENAME_REGEX
GUARD_REGEX
PASS_REGEX

Attributes

fullpath[R]
generator[R]
given[R]
relative[R]

Public Class Methods

new(target, generator) click to toggle source
# File lib/pineapples/actions/base/target.rb, line 13
def initialize(target, generator)
  raise Error, 'Target should not be falsy' if !target

  @generator = generator
  @given = target.to_s

  match!

  @fullpath = File.expand_path(@given, generator.current_app_dir)
  @relative = generator.relative_to_current_app_dir(@fullpath)
end

Public Instance Methods

skip?() click to toggle source
# File lib/pineapples/actions/base/target.rb, line 25
def skip?
  @skip
end

Private Instance Methods

evaluate_filename_method!() click to toggle source
# File lib/pineapples/actions/base/target.rb, line 56
def evaluate_filename_method!
  method = find_generator_method!(methods_to_find(:filename))
  filename = generator.send(method)
  @given.sub!(match(:filename)[0], filename)
end
evaluate_guard_method!() click to toggle source
# File lib/pineapples/actions/base/target.rb, line 50
def evaluate_guard_method!
  method = find_generator_method!(methods_to_find(:guard))
  @skip = generator.send(method)
  @given.sub!(match(:guard)[0], '')
end
evaluate_pass_method!() click to toggle source
# File lib/pineapples/actions/base/target.rb, line 44
def evaluate_pass_method!
  method = find_generator_method!(methods_to_find(:pass))
  @skip = !generator.send(method)
  @given.sub!(match(:pass)[0], '')
end
find_generator_method!(methods) click to toggle source
# File lib/pineapples/actions/base/target.rb, line 72
def find_generator_method!(methods)
  Array(methods).each { |method| return method if generator.respond_to?(method, true) }
  raise Error, methods_missing_error_message(methods)
end
match(type) click to toggle source
# File lib/pineapples/actions/base/target.rb, line 62
def match(type)
  regexp = self.class.const_get(type.to_s.upcase + '_REGEX')
  regexp.match(@given)
end
match!() click to toggle source
# File lib/pineapples/actions/base/target.rb, line 31
def match!
  loop do
    matched = false
    [:pass, :guard, :filename].each do |type|
      if match(type)
        send(:"evaluate_#{type}_method!")
        matched = true and break
      end
    end
    break if !matched || @skip
  end
end
methods_missing_error_message(methods) click to toggle source
# File lib/pineapples/actions/base/target.rb, line 77
def methods_missing_error_message(methods)
  methods = Array(methods)
  methods_message = methods.length > 1 ? 'methods' : 'method'

  "No instance #{methods_message} #{methods.join(', ')} for AppGenerator, can't evaluate filepath #{given}"
end
methods_to_find(type) click to toggle source
# File lib/pineapples/actions/base/target.rb, line 67
def methods_to_find(type)
  method = match(type)[1].strip
  type == :filename ? method : [method, method + '?']
end