Sha256: 6cbb26ad68aad2144f4ae736556d19dd9705d0611b18c060332688c78c8d96f6

Contents?: true

Size: 1.19 KB

Versions: 5

Compression:

Stored size: 1.19 KB

Contents

module Bebox
  module WizardsHelper

    # Ask for confirmation of any action
    def confirm_action?(message)
      require 'highline/import'
      quest message
      response =  ask(highline_quest('(y/n)')) do |q|
        q.default = "n"
      end
      return response == 'y' ? true : false
    end

    # Ask to write some input with validation
    def write_input(message, default=nil, validator=nil, not_valid_message=nil)
      require 'highline/import'
      response =  ask(highline_quest(message)) do |q|
        q.default = default if default
        q.validate = /\.(.*)/ if validator
        q.responses[:not_valid] = highline_warn(not_valid_message) if not_valid_message
      end
      return response
    end

    # Asks to choose an option
    def choose_option(options, question)
      require 'highline/import'
      choose do |menu|
        menu.header = title(question)
        options.each do |option|
          menu.choice(option)
        end
      end
    end

    # Check if the puppet resource has a valid name
    def valid_puppet_class_name?(name)
      valid_name = (name =~ /\A[a-z][a-z0-9_]*\Z/).nil? ? false : true
      valid_name && !Bebox::RESERVED_WORDS.include?(name)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bebox-0.1.5 lib/bebox/wizards/wizards_helper.rb
bebox-0.1.4 lib/bebox/wizards/wizards_helper.rb
bebox-0.1.3 lib/bebox/wizards/wizards_helper.rb
bebox-0.1.2 lib/bebox/wizards/wizards_helper.rb
bebox-0.1.1 lib/bebox/wizards/wizards_helper.rb