Class: Hotdog::Commands::BaseCommand

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

Direct Known Subclasses

Down, Help, Hosts, Search, Tag, Tags, Untag, Up, Version

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application) ⇒ BaseCommand

Returns a new instance of BaseCommand.



15
16
17
18
19
20
21
22
# File 'lib/hotdog/commands.rb', line 15

def initialize(application)
  @application = application
  @logger = application.logger
  @options = application.options
  @dog = nil # lazy initialization
  @prepared_statements = {}
  @persistent_db_path = File.join(@options.fetch(:confdir, "."), "hotdog.sqlite3")
end

Instance Attribute Details

#applicationObject (readonly)

Returns the value of attribute application.



23
24
25
# File 'lib/hotdog/commands.rb', line 23

def application
  @application
end

#loggerObject (readonly)

Returns the value of attribute logger.



24
25
26
# File 'lib/hotdog/commands.rb', line 24

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



25
26
27
# File 'lib/hotdog/commands.rb', line 25

def options
  @options
end

#persistent_db_pathObject (readonly)

Returns the value of attribute persistent_db_path.



26
27
28
# File 'lib/hotdog/commands.rb', line 26

def persistent_db_path
  @persistent_db_path
end

Instance Method Details

#define_options(optparse, options = {}) ⇒ Object



54
55
56
# File 'lib/hotdog/commands.rb', line 54

def define_options(optparse, options={})
  # nop
end

#execute(q, args = []) ⇒ Object



32
33
34
35
# File 'lib/hotdog/commands.rb', line 32

def execute(q, args=[])
  update_db
  execute_db(@db, q, args)
end

#fixed_string?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/hotdog/commands.rb', line 37

def fixed_string?()
  @options[:fixed_string]
end

#parse_options(optparse, args = []) ⇒ Object



58
59
60
# File 'lib/hotdog/commands.rb', line 58

def parse_options(optparse, args=[])
  optparse.parse(args)
end

#reload(options = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/hotdog/commands.rb', line 41

def reload(options={})
  options = @options.merge(options)
  if options[:offline]
    logger.info("skip reloading on offline mode.")
  else
    if @db
      close_db(@db)
      @db = nil
    end
    update_db(options)
  end
end

#run(args = [], options = {}) ⇒ Object

Raises:

  • (NotImplementedError)


28
29
30
# File 'lib/hotdog/commands.rb', line 28

def run(args=[], options={})
  raise(NotImplementedError)
end