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

Inherits:
Object
  • Object
show all
Defined in:
lib/polishgeeks/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 )

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.typeObject

Returns the value of attribute type.



20
21
22
# File 'lib/polishgeeks/dev-tools/commands/base.rb', line 20

def type
  @type
end

.validatorsObject

Returns the value of attribute validators.



21
22
23
# File 'lib/polishgeeks/dev-tools/commands/base.rb', line 21

def validators
  @validators
end

Instance Attribute Details

#outputObject (readonly)

Output string that we get after executing this command



9
10
11
# File 'lib/polishgeeks/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/polishgeeks/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:

  • when invalid validator class name is defined

  • when validator conditions are not met



55
56
57
58
59
# File 'lib/polishgeeks/dev-tools/commands/base.rb', line 55

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:

  • what message should be printed when error occures



45
46
47
# File 'lib/polishgeeks/dev-tools/commands/base.rb', line 45

def error_message
  output
end

#executeObject

Raises:

  • this should be implemented in a subclass



32
33
34
# File 'lib/polishgeeks/dev-tools/commands/base.rb', line 32

def execute
  fail Errors::NotImplementedError
end

#valid?Boolean

Returns:

Raises:

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



39
40
41
# File 'lib/polishgeeks/dev-tools/commands/base.rb', line 39

def valid?
  fail Errors::NotImplementedError
end