Class: Natsukantou::Setup::ConfigPrompt
- Inherits:
-
Object
- Object
- Natsukantou::Setup::ConfigPrompt
- Defined in:
- lib/natsukantou/setup/config_prompt.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#know_ruby ⇒ Object
readonly
Returns the value of attribute know_ruby.
-
#prompt ⇒ Object
readonly
Returns the value of attribute prompt.
-
#translators ⇒ Object
readonly
Returns the value of attribute translators.
Instance Method Summary collapse
- #ask ⇒ Object
- #execute ⇒ Object
-
#initialize ⇒ ConfigPrompt
constructor
A new instance of ConfigPrompt.
- #output ⇒ Object
Constructor Details
#initialize ⇒ ConfigPrompt
Returns a new instance of ConfigPrompt.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/natsukantou/setup/config_prompt.rb', line 95 def initialize @prompt = TTY::Prompt.new registry = Natsukantou::Setup::Registry.instance @translators = registry.translators.map do |args| Natsukantou::Setup::Component.new(*args) end @filters = registry.middlewares.map do |args| Natsukantou::Setup::Component.new(*args) end @config = {} end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
111 112 113 |
# File 'lib/natsukantou/setup/config_prompt.rb', line 111 def config @config end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
111 112 113 |
# File 'lib/natsukantou/setup/config_prompt.rb', line 111 def filters @filters end |
#know_ruby ⇒ Object (readonly)
Returns the value of attribute know_ruby.
112 113 114 |
# File 'lib/natsukantou/setup/config_prompt.rb', line 112 def know_ruby @know_ruby end |
#prompt ⇒ Object (readonly)
Returns the value of attribute prompt.
111 112 113 |
# File 'lib/natsukantou/setup/config_prompt.rb', line 111 def prompt @prompt end |
#translators ⇒ Object (readonly)
Returns the value of attribute translators.
111 112 113 |
# File 'lib/natsukantou/setup/config_prompt.rb', line 111 def translators @translators end |
Instance Method Details
#ask ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/natsukantou/setup/config_prompt.rb', line 119 def ask @know_ruby = prompt.yes?('Do you know Ruby or JSON syntax?') translator = prompt.select( "Choose translation engine:", translators.map { |t| [t.name, t] }.to_h ) config[:translator] = { component: translator, parameters: ask_initialize_parameters(translator) } config[:filters] = [] selected_filters = prompt.multi_select( "Select one or many filters (using spacebar):", filters.map { |t| [t.name, t] }.to_h ) selected_filters.each do |filter| config[:filters] << { component: filter, parameters: ask_initialize_parameters(filter) } end end |
#execute ⇒ Object
114 115 116 117 |
# File 'lib/natsukantou/setup/config_prompt.rb', line 114 def execute ask output end |
#output ⇒ Object
147 148 149 150 151 152 153 |
# File 'lib/natsukantou/setup/config_prompt.rb', line 147 def output template = ERB.new( File.read((File. 'output.erb', __dir__)), trim_mode: "<>-" ) template.result(binding) end |