Class: Tempo::Views::ViewRecords::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/tempo/views/view_records/base.rb

Overview

Query records are handled by the console formatter, returning results from a call to Readline

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, options = {}) ⇒ Query

Returns a new instance of Query.



54
55
56
57
58
59
# File 'lib/tempo/views/view_records/base.rb', line 54

def initialize(query, options={})
  @query = query
  @type = "query"
  @match = options.fetch(:match, /(y|Y)(es)?/)
  @response = Reporter.add_view_record self
end

Instance Attribute Details

#matchObject

Returns the value of attribute match.



52
53
54
# File 'lib/tempo/views/view_records/base.rb', line 52

def match
  @match
end

#queryObject

Returns the value of attribute query.



52
53
54
# File 'lib/tempo/views/view_records/base.rb', line 52

def query
  @query
end

#responseObject

Returns the value of attribute response.



52
53
54
# File 'lib/tempo/views/view_records/base.rb', line 52

def response
  @response
end

#typeObject

Returns the value of attribute type.



52
53
54
# File 'lib/tempo/views/view_records/base.rb', line 52

def type
  @type
end

Instance Method Details

#format(&block) ⇒ Object



65
66
67
68
69
70
# File 'lib/tempo/views/view_records/base.rb', line 65

def format(&block)
  # TODO: should we create an interactive default? using:
  # confirm = Readline.readline('> ', true).match(/(y|Y)(es)?/)
  block ||= lambda { |q| puts "#{q.query}"; Readline.readline('> ', true) }
  response = block.call self
end

#positive_response?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/tempo/views/view_records/base.rb', line 61

def positive_response?
  true if @response.match(@match)
end