Class: FlatKit::Command

Inherits:
Object
  • Object
show all
Extended by:
DescendantTracker
Defined in:
lib/flat_kit/command.rb,
lib/flat_kit/command/cat.rb,
lib/flat_kit/command/sort.rb,
lib/flat_kit/command/merge.rb,
lib/flat_kit/command/stats.rb

Overview

Internal: The base class for all commands in the CLI

Direct Known Subclasses

Cat, Merge, Sort, Stats

Defined Under Namespace

Classes: Cat, Merge, Sort, Stats

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DescendantTracker

children, find_child, find_children, inherited

Constructor Details

#initialize(argv:, logger: ::FlatKit.logger, env: ENV) ⇒ Command

Returns a new instance of Command.



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

def initialize(argv:, logger: ::FlatKit.logger, env: ENV)
  @argv = argv
  @env = env
  @logger = logger
  parse
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



9
10
11
# File 'lib/flat_kit/command.rb', line 9

def argv
  @argv
end

#envObject (readonly)

Returns the value of attribute env.



9
10
11
# File 'lib/flat_kit/command.rb', line 9

def env
  @env
end

#loggerObject (readonly)

Returns the value of attribute logger.



9
10
11
# File 'lib/flat_kit/command.rb', line 9

def logger
  @logger
end

#optsObject (readonly)

Returns the value of attribute opts.



9
10
11
# File 'lib/flat_kit/command.rb', line 9

def opts
  @opts
end

#readersObject (readonly)

Returns the value of attribute readers.



9
10
11
# File 'lib/flat_kit/command.rb', line 9

def readers
  @readers
end

#writerObject (readonly)

Returns the value of attribute writer.



9
10
11
# File 'lib/flat_kit/command.rb', line 9

def writer
  @writer
end

Class Method Details

.descriptionObject

Raises:

  • (NotImplementedError)


15
16
17
# File 'lib/flat_kit/command.rb', line 15

def self.description
  raise NotImplementedError, "#{self.class} must implement #{self.class}.description"
end

.for(name) ⇒ Object



27
28
29
30
31
# File 'lib/flat_kit/command.rb', line 27

def self.for(name)
  children.find do |child_klass|
    child_klass.name == name
  end
end

.nameObject

Raises:

  • (NotImplementedError)


11
12
13
# File 'lib/flat_kit/command.rb', line 11

def self.name
  raise NotImplementedError, "#{self.class} must implement #{self.class}.name"
end

.namesObject



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

def self.names
  children.map(&:name)
end

.parserObject

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/flat_kit/command.rb', line 19

def self.parser
  raise NotImplementedError, "#{self.class} must implement #{self.class}.parser"
end

Instance Method Details

#callObject

Raises:

  • (NotImplementedError)


44
45
46
# File 'lib/flat_kit/command.rb', line 44

def call
  raise NotImplementedError, "#{self.class} must implement #{self.class}.description"
end

#parseObject

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/flat_kit/command.rb', line 40

def parse
  raise NotImplementedError, "#{self.class} must implement #{self.class}#parse"
end