Class: Pug::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/pug/configuration.rb

Overview

Defines parameters used to setup Pug

Client Types collapse

TERMINAL =
0
TELEGRAM =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type = TERMINAL) ⇒ Configuration

Returns a new instance of Configuration.

Parameters:

  • type (Integer) (defaults to: TERMINAL)

    type of client to setup



26
27
28
# File 'lib/pug/configuration.rb', line 26

def initialize(type = TERMINAL)
  @type = type
end

Instance Attribute Details

#actionsArray<Interfaces::Action>

Returns user defined actions.

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pug/configuration.rb', line 17

class Configuration
  attr_accessor :type, :token, :chat_id, :actions

  # @!group Client Types
  TERMINAL = 0
  TELEGRAM = 1
  # @!endgroup

  # @param type [Integer] type of client to setup
  def initialize(type = TERMINAL)
    @type = type
  end

  # Validates if attributes are correctly setup for Pug
  # @raise RuntimeError if type is not a valid Client type
  # @raise RuntimeError if Telegram client and no token & chat_id
  # @raise RuntimeError if provided actions are nil
  # @return [void]
  def validate
    valid_type = [TERMINAL, TELEGRAM].include?(type)
    raise 'Invalid client type' unless valid_type
    bad_config = @token.nil? || @chat_id.nil?
    raise 'Invalid Telegram config' if @type == TELEGRAM && bad_config
    raise 'No actions provided' if @actions.nil?
  end
end

#chat_idString

Note:

This is optional if type is TERMINAL

Returns the chat_id for Telegram.

Returns:

  • (String)

    the chat_id for Telegram



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pug/configuration.rb', line 17

class Configuration
  attr_accessor :type, :token, :chat_id, :actions

  # @!group Client Types
  TERMINAL = 0
  TELEGRAM = 1
  # @!endgroup

  # @param type [Integer] type of client to setup
  def initialize(type = TERMINAL)
    @type = type
  end

  # Validates if attributes are correctly setup for Pug
  # @raise RuntimeError if type is not a valid Client type
  # @raise RuntimeError if Telegram client and no token & chat_id
  # @raise RuntimeError if provided actions are nil
  # @return [void]
  def validate
    valid_type = [TERMINAL, TELEGRAM].include?(type)
    raise 'Invalid client type' unless valid_type
    bad_config = @token.nil? || @chat_id.nil?
    raise 'Invalid Telegram config' if @type == TELEGRAM && bad_config
    raise 'No actions provided' if @actions.nil?
  end
end

#tokenString

Note:

This is optional if type is TERMINAL

Returns the API token for Telegram.

Returns:

  • (String)

    the API token for Telegram



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pug/configuration.rb', line 17

class Configuration
  attr_accessor :type, :token, :chat_id, :actions

  # @!group Client Types
  TERMINAL = 0
  TELEGRAM = 1
  # @!endgroup

  # @param type [Integer] type of client to setup
  def initialize(type = TERMINAL)
    @type = type
  end

  # Validates if attributes are correctly setup for Pug
  # @raise RuntimeError if type is not a valid Client type
  # @raise RuntimeError if Telegram client and no token & chat_id
  # @raise RuntimeError if provided actions are nil
  # @return [void]
  def validate
    valid_type = [TERMINAL, TELEGRAM].include?(type)
    raise 'Invalid client type' unless valid_type
    bad_config = @token.nil? || @chat_id.nil?
    raise 'Invalid Telegram config' if @type == TELEGRAM && bad_config
    raise 'No actions provided' if @actions.nil?
  end
end

#typeInteger

Returns the type of client to setup.

Returns:

  • (Integer)

    the type of client to setup

See Also:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pug/configuration.rb', line 17

class Configuration
  attr_accessor :type, :token, :chat_id, :actions

  # @!group Client Types
  TERMINAL = 0
  TELEGRAM = 1
  # @!endgroup

  # @param type [Integer] type of client to setup
  def initialize(type = TERMINAL)
    @type = type
  end

  # Validates if attributes are correctly setup for Pug
  # @raise RuntimeError if type is not a valid Client type
  # @raise RuntimeError if Telegram client and no token & chat_id
  # @raise RuntimeError if provided actions are nil
  # @return [void]
  def validate
    valid_type = [TERMINAL, TELEGRAM].include?(type)
    raise 'Invalid client type' unless valid_type
    bad_config = @token.nil? || @chat_id.nil?
    raise 'Invalid Telegram config' if @type == TELEGRAM && bad_config
    raise 'No actions provided' if @actions.nil?
  end
end

Instance Method Details

#validatevoid

This method returns an undefined value.

Validates if attributes are correctly setup for Pug

Raises:

  • RuntimeError if type is not a valid Client type

  • RuntimeError if Telegram client and no token & chat_id

  • RuntimeError if provided actions are nil



35
36
37
38
39
40
41
# File 'lib/pug/configuration.rb', line 35

def validate
  valid_type = [TERMINAL, TELEGRAM].include?(type)
  raise 'Invalid client type' unless valid_type
  bad_config = @token.nil? || @chat_id.nil?
  raise 'Invalid Telegram config' if @type == TELEGRAM && bad_config
  raise 'No actions provided' if @actions.nil?
end