Class: Simp::Cli::Config::ListItem
- Defined in:
- lib/simp/cli/config/item.rb
Overview
A Item that asks for lists instead of Strings
note that @value is now an Array
Direct Known Subclasses
Item::ClientNets, Item::DNSSearch, Item::DNSServers, Item::FailoverLogServers, Item::LdapUri, Item::LogServers, Item::NTPServers, Item::SimpYumServers, Item::SssdDomains
Instance Attribute Summary collapse
-
#allow_empty_list ⇒ Object
Returns the value of attribute allow_empty_list.
Attributes inherited from Item
#allow_user_apply, #config_items, #description, #die_on_apply_fail, #fact, #fail_on_missing_answer, #key, #next_items_tree, #silent, #skip_apply, #skip_query, #skip_yaml, #value
Instance Method Summary collapse
- #highline_question_type ⇒ Object
-
#initialize ⇒ ListItem
constructor
A new instance of ListItem.
- #not_valid_message ⇒ Object
- #query_extras(q) ⇒ Object
-
#validate(list) ⇒ Object
validate the list and each item in the list.
-
#validate_item(x) ⇒ Object
validate a single list item.
Methods inherited from Item
#apply, #default_value, #next_items, #os_value, #print_banner, #print_summary, #puppet_value, #query, #query_ask, #query_status, #recommended_value, #safe_apply, #say_blue, #say_green, #say_red, #say_yellow, #to_yaml_s
Constructor Details
#initialize ⇒ ListItem
Returns a new instance of ListItem.
350 351 352 353 |
# File 'lib/simp/cli/config/item.rb', line 350 def initialize super @allow_empty_list = false end |
Instance Attribute Details
#allow_empty_list ⇒ Object
Returns the value of attribute allow_empty_list.
348 349 350 |
# File 'lib/simp/cli/config/item.rb', line 348 def allow_empty_list @allow_empty_list end |
Instance Method Details
#highline_question_type ⇒ Object
373 374 375 376 377 378 379 |
# File 'lib/simp/cli/config/item.rb', line 373 def highline_question_type # Convert the String (delimited by comma and/or whitespace) answer into an array lambda { |str| str = str.split(/,\s*|,?\s+/) if str.is_a? String str } end |
#not_valid_message ⇒ Object
355 356 357 358 359 |
# File 'lib/simp/cli/config/item.rb', line 355 def extra = 'hit enter to skip' extra = "hit enter to accept default value" if default_value "enter a comma or space-delimited list (#{extra})" end |
#query_extras(q) ⇒ Object
361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/simp/cli/config/item.rb', line 361 def query_extras( q ) # NOTE: this is a hack to massage Array input to/from a highline query. # It would probably be better (but more complex) to provide native Array # support for highline. # TODO: Override #query_ask using Highline's #gather? q.default = q.default.join( " " ) if q.default.is_a? Array reminder = ::HighLine.color( , ::HighLine.const_get('YELLOW') ) q.question = "#{reminder}\n#{q.question}" q end |
#validate(list) ⇒ Object
validate the list and each item in the list
382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/simp/cli/config/item.rb', line 382 def validate( list ) # reuse the highline lambda to santize input return true if (@allow_empty_list && list.nil?) list = highline_question_type.call( list ) if !list.is_a? Array return false if !list.is_a?(Array) return false if (!@allow_empty_list && list.empty? ) list.each{ |item| return false if !validate_item( item ) } true end |
#validate_item(x) ⇒ Object
validate a single list item
395 396 397 |
# File 'lib/simp/cli/config/item.rb', line 395 def validate_item( x ) fail 'not implemented!' end |