Class: CLIChef::Ingredient

Inherits:
Object
  • Object
show all
Includes:
BBLib::Effortless
Defined in:
lib/cli_chef/components/ingredient.rb

Instance Method Summary collapse

Instance Method Details

#allowed?(value) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
# File 'lib/cli_chef/components/ingredient.rb', line 33

def allowed?(value)
  return true if allowed_values.empty?
  allowed_values.any? do |av|
    av === value || av.nil? && (value == true || value == false)
  end
end

#cleaned_argument(value = nil) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/cli_chef/components/ingredient.rb', line 21

def cleaned_argument(value = nil)
  allowed!(value)
  return '' if boolean_argument?
  [value].flatten(1).map(&:to_s).map do |arg|
    arg.match?(/\s/) && !arg.encap_by?('"') ? "\"#{arg.gsub('"','\\"')}\"" : arg
  end.join(delimiter)
end

#match?(name) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/cli_chef/components/ingredient.rb', line 29

def match?(name)
  self.name == name || aliases.include?(name)
end

#to_s(value = nil) ⇒ Object



15
16
17
18
19
# File 'lib/cli_chef/components/ingredient.rb', line 15

def to_s(value = nil)
  return '' if boolean_argument? && value == false
  cleaned_arg = cleaned_argument(value)
  argument == false ? '' : "#{flag}#{flag && !cleaned_arg.empty? ? flag_delimiter : nil}#{cleaned_arg}"
end