Class: Soryo::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/command.rb

Direct Known Subclasses

BuildCommand, SendCommand, TestCommand

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Command

Returns a new instance of Command.



17
18
19
20
21
22
23
24
# File 'lib/commands/command.rb', line 17

def initialize(options)
    @config = Soryo::Config.new
    unless options.nil?
        @config.merge_with(options)
    end

    get_settings_file
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/commands/command.rb', line 7

def config
  @config
end

Class Method Details

.add_command(program) ⇒ Object



38
39
40
# File 'lib/commands/command.rb', line 38

def self.add_command(program)
    abort('Command.self.add_command should not be called on their own')
end

.add_options(c) ⇒ Object



34
35
36
# File 'lib/commands/command.rb', line 34

def self.add_options(c)
    c.option 'config_file', '--config', 'choose a different config file'
end

.descendantsObject



9
10
11
12
13
14
15
# File 'lib/commands/command.rb', line 9

def self.descendants
    descendants = []
    ObjectSpace.each_object(singleton_class) do |k|
        descendants.unshift k unless k == self
    end
    descendants
end

Instance Method Details

#get_settings_fileObject



26
27
28
29
30
31
32
# File 'lib/commands/command.rb', line 26

def get_settings_file
    if @config[:settings_file]
        @config.read_yaml(@config[:settings_file])
    elsif Pathname.new('settings.yaml').exist?
        @config.read_yaml('settings.yaml')
    end
end