Class: YAMLCommand::Command

Inherits:
Executable::Command
  • Object
show all
Defined in:
lib/yaml_command/base.rb

Overview

Abstract base command that all others use.

Defined Under Namespace

Classes: EditCommand, GetCommand, SetCommand, SlurpCommand, SortCommand, SplatCommand, ViewCommand

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fileObject

YAML file to use as data source. This can be used as an alternative to ‘$stdin`.



28
29
30
# File 'lib/yaml_command/base.rb', line 28

def file
  @file
end

Class Method Details

.command_nameObject



8
9
10
# File 'lib/yaml_command/base.rb', line 8

def self.command_name
  'yaml'
end

Instance Method Details

#callObject

YAML Command



90
91
92
93
94
95
96
# File 'lib/yaml_command/base.rb', line 90

def call
  if file
    output(data)
  else
    puts cli
  end
end

#debug=(boolean) ⇒ Object

Debug mode.



13
14
15
# File 'lib/yaml_command/base.rb', line 13

def debug=(boolean)
  $DEBUG = boolean ? true : false
end

#debug?Boolean

Debug mode.

Returns:

  • (Boolean)


18
19
20
# File 'lib/yaml_command/base.rb', line 18

def debug?
  $DEBUG
end

#h!Object

Show minimal help message.



84
85
86
87
# File 'lib/yaml_command/base.rb', line 84

def h!
  puts cli
  exit
end

#help!Object

Show detailed help message.



78
79
80
81
# File 'lib/yaml_command/base.rb', line 78

def help!
  cli.show_help
  exit
end

#inspect=(boolean) ⇒ Object

Output using Ruby’s #inspect method.



32
33
34
# File 'lib/yaml_command/base.rb', line 32

def inspect=(boolean)
  @format = :inspect if boolean
end

#inspect?Boolean

Output using Ruby’s #inspect method.

Returns:

  • (Boolean)


37
38
39
# File 'lib/yaml_command/base.rb', line 37

def inspect?
  @format == :inspect
end

#json=(boolean) ⇒ Object

Output using #to_json.



54
55
56
# File 'lib/yaml_command/base.rb', line 54

def json=(boolean)
  @format = :json if boolean
end

#json?Boolean

Output using #to_json.

Returns:

  • (Boolean)


59
60
61
# File 'lib/yaml_command/base.rb', line 59

def json?
  @format == :json
end

#mute=(boolean) ⇒ Object

Surpress all output.



71
72
73
# File 'lib/yaml_command/base.rb', line 71

def mute=(boolean)
  @format = :mute if boolean
end

#mute?Boolean

Surpress all output.

Returns:

  • (Boolean)


66
67
68
# File 'lib/yaml_command/base.rb', line 66

def mute?
  @format == :mute
end

#yaml=(boolean) ⇒ Object

Output using #to_yaml.



42
43
44
# File 'lib/yaml_command/base.rb', line 42

def yaml=(boolean)
  @format = :yaml if boolean
end

#yaml?Boolean

Output using #to_yaml.

Returns:

  • (Boolean)


47
48
49
# File 'lib/yaml_command/base.rb', line 47

def yaml?
  @format == :yaml
end