Class: PolishGeeks::DevTools::Commands::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/polish_geeks/dev_tools/commands/base.rb

Overview

This class is abstract.

Subclass and use

Base class for all the commands

Constant Summary collapse

TYPES =

Available command types. We have validators that check something and that should have a ‘valid?’ method and that check for errors, etc and generators that are executed to generate some stats, docs, etc

%i(validator generator).freeze

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.config_managerObject

ConfigManager instance can be provided, which allows us to find a config file for a command



22
23
24
# File 'lib/polish_geeks/dev_tools/commands/base.rb', line 22

def config_manager
  @config_manager
end

.typeObject

Returns the value of attribute type.



23
24
25
# File 'lib/polish_geeks/dev_tools/commands/base.rb', line 23

def type
  @type
end

.validatorsObject

Returns the value of attribute validators.



24
25
26
# File 'lib/polish_geeks/dev_tools/commands/base.rb', line 24

def validators
  @validators
end

Instance Attribute Details

#outputObject (readonly)

Output string that we get after executing this command



9
10
11
# File 'lib/polish_geeks/dev_tools/commands/base.rb', line 9

def output
  @output
end

#stored_outputObject

stored_output [PolishGeeks::DevTools::OutputStorer] storer with results of previous

commands (they might use output from previous/other commands)


12
13
14
# File 'lib/polish_geeks/dev_tools/commands/base.rb', line 12

def stored_output
  @stored_output
end

Instance Method Details

#ensure_executable!Object

Runs validators if any to check if all requirements of this command are met in order to execute it properly

Raises:



58
59
60
61
62
# File 'lib/polish_geeks/dev_tools/commands/base.rb', line 58

def ensure_executable!
  (self.class.validators || []).each do |validator_class|
    validator_class.new(stored_output).validate!
  end
end

#error_messageString

Note:

By default the whole output of an executed command will be printed

Returns what message should be printed when error occures.

Returns:

  • (String)

    what message should be printed when error occures



48
49
50
# File 'lib/polish_geeks/dev_tools/commands/base.rb', line 48

def error_message
  output
end

#executeObject

Raises:

  • (NotImplementedError)

    this should be implemented in a subclass



35
36
37
# File 'lib/polish_geeks/dev_tools/commands/base.rb', line 35

def execute
  raise Errors::NotImplementedError
end

#valid?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)

    this should be implemented in a subclass if it is a validator type (or no implementation required when it is a validator)



42
43
44
# File 'lib/polish_geeks/dev_tools/commands/base.rb', line 42

def valid?
  raise Errors::NotImplementedError
end