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.



32
33
34
35
# File 'lib/rails_wizard/config.rb', line 32

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

Instance Attribute Details

#detailsObject (readonly)

Returns the value of attribute details.



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

def details
  @details
end

#promptObject (readonly)

Returns the value of attribute prompt.



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

def prompt
  @prompt
end

Instance Method Details

#compileObject



37
38
39
# File 'lib/rails_wizard/config.rb', line 37

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

#conditionsObject



45
46
47
# File 'lib/rails_wizard/config.rb', line 45

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

#config_conditionsObject



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

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

#questionObject



41
42
43
# File 'lib/rails_wizard/config.rb', line 41

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

#recipe_conditionsObject



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

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