Class: Saper::Arguments::Recipe

Inherits:
Saper::Argument show all
Defined in:
lib/saper/arguments/recipe.rb

Instance Method Summary collapse

Methods inherited from Saper::Argument

[], #action, exists?, inherited, #initialize, #mandatory?, new, #optional?, #set, subclasses, type, #value

Constructor Details

This class inherits a constructor from Saper::Argument

Instance Method Details

#normalize(value) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/saper/arguments/recipe.rb', line 9

def normalize(value)
  if value.is_a?(Recipe)
    return value
  end
  if value.is_a?(String)
    value = value.to_sym
  end
  unless value.is_a?(Symbol)
    raise InvalidArgument
  end
  if action.nil?
    raise NamespaceMissing
  end
  if action.namespace.nil?
    raise NamespaceMissing
  end
  unless value = action.namespace[value]
    raise ActionNotFound
  end
  value
end

#serializeObject



32
33
34
# File 'lib/saper/arguments/recipe.rb', line 32

def serialize
  value.id
end

#to_stringObject



36
37
38
# File 'lib/saper/arguments/recipe.rb', line 36

def to_string
  value.id.inspect
end

#valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/saper/arguments/recipe.rb', line 5

def valid?(value)
  value.is_a?(Symbol) || value.is_a?(String)
end