Class: Geostats::Commands::Set

Inherits:
Base
  • Object
show all
Defined in:
lib/geostats/commands/set.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #invoke

Constructor Details

This class inherits a constructor from Geostats::Commands::Base

Instance Method Details

#beforeObject



15
16
17
# File 'lib/geostats/commands/set.rb', line 15

def before
  connect_database
end

#parse_argsObject

Raises:



10
11
12
13
# File 'lib/geostats/commands/set.rb', line 10

def parse_args
  raise UsageError if @args.length > 2
  @key, @value = @args
end

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/geostats/commands/set.rb', line 19

def run
  if @key
    if @value
      Setting.set(@key, @value)
      puts "#{@key} = #{@value}"
    else
      puts "#{@key} = #{Setting.get(@key) || "<null>"}"
    end
  else
    Setting.all.each do |setting|
      puts "#{setting.key} = #{setting.value || "<null>"}"
    end
  end
end

#usageObject



4
5
6
7
8
# File 'lib/geostats/commands/set.rb', line 4

def usage
  STDERR.puts "Usage: geostats set"
  STDERR.puts "                set <key>"
  STDERR.puts "                set <key> <value>"
end