Class: Cliqr::Config::Command Private

Inherits:
Action show all
Defined in:
lib/cliqr/config/command.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Configuration setting for a command

Instance Attribute Summary collapse

Attributes inherited from Action

#actions, #arguments, #handler, #help, #parent

Attributes inherited from OptionBased

#options

Attributes inherited from Named

#description, #name

Attributes inherited from EventBased

#events

Instance Method Summary collapse

Methods inherited from Action

#action, #action?, #actions?, #arguments?, #command, #help?, #parent?, #root, #root?

Methods inherited from OptionBased

#option, #option?, #options?

Methods inherited from Named

#description?, #name?

Methods inherited from EventBased

#event, #handle?

Methods inherited from Base

#skip_validation?

Methods included from Validation

#errors, included, #read_attributes, #valid?, #validate, #validations

Methods included from DSL

included

Constructor Details

#initializeCommand

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

New config instance with all attributes set as UNSET



33
34
35
36
37
38
39
# File 'lib/cliqr/config/command.rb', line 33

def initialize
  super

  @shell = UNSET
  @version = UNSET
  @color = UNSET
end

Instance Attribute Details

#colorSymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Enable or disable colors in a command handler (default enabled)

Returns:

  • (Symbol)


28
29
30
# File 'lib/cliqr/config/command.rb', line 28

def color
  @color
end

#shellCliqr::Command::ShellConfig

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Configuration for the shell for this command

Returns:

  • (Cliqr::Command::ShellConfig)


16
17
18
# File 'lib/cliqr/config/command.rb', line 16

def shell
  @shell
end

#versionStirng

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Version tag for this configuration

Returns:

  • (Stirng)


23
24
25
# File 'lib/cliqr/config/command.rb', line 23

def version
  @version
end

Instance Method Details

#color?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if colors are enabled for this setting

Returns:

  • (Boolean)


98
99
100
# File 'lib/cliqr/config/command.rb', line 98

def color?
  @color == Cliqr::Config::ENABLE_CONFIG
end

#finalizeCliqr::Config::Command

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Finalize config by adding default values for unset values



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cliqr/config/command.rb', line 44

def finalize
  super

  @color = Config.get_if_unset(@color, Cliqr::Config::ENABLE_CONFIG)
  @shell = Config.get_if_unset(@shell, proc { Cliqr::Util.build_shell_config(self) })
  @version = Config.get_if_unset(@version, nil)

  # disable colors in shell if colors are disabled here
  @shell.disable_color unless color?

  self
end

#set_config(name, value, *args, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set value for a config option

Parameters:

  • name (Symbol)

    Name of the config parameter

  • value (Object)

    Value for the config parameter

  • block (Proc)

    Function which populates configuration for a sub-attribute

Returns:

  • (Object)

    attribute’s value



64
65
66
67
68
69
70
71
# File 'lib/cliqr/config/command.rb', line 64

def set_config(name, value, *args, &block)
  case name
  when :shell
    handle_shell(value, &block)
  else
    super
  end
end

#setup_defaultsCliqr::Config::Command

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set up default attributes for this configuration

Returns:



76
77
78
79
80
81
# File 'lib/cliqr/config/command.rb', line 76

def setup_defaults
  super

  add_shell
  add_version
end

#shell?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if this configuration has shell action enabled

Returns:

  • (Boolean)


86
87
88
# File 'lib/cliqr/config/command.rb', line 86

def shell?
  @shell.enabled?
end

#version?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if version is enabled for this command

Returns:

  • (Boolean)

    true if help is enabled



93
94
95
# File 'lib/cliqr/config/command.rb', line 93

def version?
  !@version.nil?
end