Class: Pug::Configuration
- Inherits:
-
Object
- Object
- Pug::Configuration
- Defined in:
- lib/pug/configuration.rb
Overview
Defines parameters used to setup Pug
Client Types collapse
- TERMINAL =
0
- TELEGRAM =
1
Instance Attribute Summary collapse
-
#actions ⇒ Array<Interfaces::Action>
User defined actions.
-
#chat_id ⇒ String
The chat_id for Telegram.
-
#token ⇒ String
The API token for Telegram.
-
#type ⇒ Integer
The type of client to setup.
Instance Method Summary collapse
-
#initialize(type = TERMINAL) ⇒ Configuration
constructor
A new instance of Configuration.
-
#validate ⇒ void
Validates if attributes are correctly setup for Pug.
Constructor Details
#initialize(type = TERMINAL) ⇒ Configuration
Returns a new instance of Configuration.
26 27 28 |
# File 'lib/pug/configuration.rb', line 26 def initialize(type = TERMINAL) @type = type end |
Instance Attribute Details
#actions ⇒ Array<Interfaces::Action>
Returns user defined actions.
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_id ⇒ String
Note:
This is optional if type is TERMINAL
Returns 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 |
#token ⇒ String
Note:
This is optional if type is TERMINAL
Returns 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 |
#type ⇒ Integer
Returns the type of client to setup.
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
#validate ⇒ void
This method returns an undefined value.
Validates if attributes are correctly setup for Pug
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 |