Class: RailsWizard::Config::Prompt

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_wizard/config.rb

Direct Known Subclasses

MultipleChoice, TrueFalse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(details) ⇒ Prompt

Returns a new instance of Prompt.



30
31
32
33
# File 'lib/rails_wizard/config.rb', line 30

def initialize(details)
  @details = details
  @prompt = details['prompt']
end

Instance Attribute Details

#detailsObject (readonly)

Returns the value of attribute details.



29
30
31
# File 'lib/rails_wizard/config.rb', line 29

def details
  @details
end

#promptObject (readonly)

Returns the value of attribute prompt.



29
30
31
# File 'lib/rails_wizard/config.rb', line 29

def prompt
  @prompt
end

Instance Method Details

#compileObject



35
36
37
# File 'lib/rails_wizard/config.rb', line 35

def compile
  "#{question} if #{conditions}"
end

#conditionsObject



43
44
45
# File 'lib/rails_wizard/config.rb', line 43

def conditions
  [config_conditions, recipe_conditions].join(' && ')
end

#config_conditionsObject



47
48
49
50
51
52
53
54
55
# File 'lib/rails_wizard/config.rb', line 47

def config_conditions
  if details['if']
    "config['#{details['if']}']"
  elsif details['unless']
    "!config['#{details['unless']}']"
  else
    'true'
  end
end

#questionObject



39
40
41
# File 'lib/rails_wizard/config.rb', line 39

def question
  "ask_wizard(#{prompt.inspect})"
end

#recipe_conditionsObject



57
58
59
60
61
62
63
64
65
# File 'lib/rails_wizard/config.rb', line 57

def recipe_conditions
  if details['if_recipe']
    "recipe?('#{details['if_recipe']}')"
  elsif details['unless_recipe']
    "!recipe?('#{details['unless_recipe']}')"
  else
    'true'
  end
end