class ThorAddons::Helpers::OptionType

Constants

TYPE_CLASS_MAP

Attributes

option[R]
type[R]

Public Class Methods

new(option, type) click to toggle source
# File lib/thor-addons/helpers/option_type.rb, line 8
def initialize(option, type)
  @option = option
  @type = type

  raise TypeError, "Invalid type: '#{type}'" unless
    TYPE_CLASS_MAP.keys.include?(type)
end

Public Instance Methods

convert_string() click to toggle source
# File lib/thor-addons/helpers/option_type.rb, line 28
def convert_string
  case type
  when :boolean then option.to_b
  when :array then option.to_a
  when :hash then option.to_h
  when :numeric then option.to_n
  else option
  end
end
valid?() click to toggle source
# File lib/thor-addons/helpers/option_type.rb, line 24
def valid?
  TYPE_CLASS_MAP[type].any? { |klass| option.is_a?(klass) }
end