Class: Hotdog::Commands::BaseCommand

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

Direct Known Subclasses

Down, Help, Hosts, Search, Tags, Up

Constant Summary collapse

PERSISTENT_DB =
"persistent.db"
MASK_DATABASE =
0xffff0000
MASK_QUERY =
0x0000ffff

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application) ⇒ BaseCommand



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

def initialize(application)
  @application = application
  @logger = application.options[:logger]
  @options = application.options
  @dog = Dogapi::Client.new(options[:api_key], options[:application_key])
  @prepared_statements = {}
end

Instance Attribute Details

#applicationObject (readonly)

Returns the value of attribute application.



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

def application
  @application
end

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

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



32
33
34
35
36
37
38
39
40
# File 'lib/hotdog/commands.rb', line 32

def execute(query, args=[])
  update_db
  q = query.strip
  if 0 < args.length
    q += " -- VALUES (#{args.map { |arg| Array === arg ? "(#{arg.join(", ")})" : arg.inspect }.join(", ")})"
  end
  logger.debug(q)
  prepare(@db, query).execute(args)
end

#fixed_string?Boolean



42
43
44
# File 'lib/hotdog/commands.rb', line 42

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

#reload(options = {}) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/hotdog/commands.rb', line 46

def reload(options={})
  if @db
    close_db(@db)
    @db = nil
  end
  update_db(options)
end

#run(args = []) ⇒ Object

Raises:

  • (NotImplementedError)


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

def run(args=[])
  raise(NotImplementedError)
end