Class: Memoir::Request
- Inherits:
-
Object
- Object
- Memoir::Request
- Defined in:
- lib/memoir/request.rb
Constant Summary collapse
- VALID_OPTIONS =
{ no_annotations: 'noAnnotations', global_annotations: 'globalAnnotations', ms_resolution: 'msResolution', show_tsuids: 'showTSUIDs', show_summary: 'showSummary', show_query: 'showQuery', delete: 'delete' }.freeze
Instance Attribute Summary collapse
-
#arrays ⇒ Object
Returns the value of attribute arrays.
-
#end_time ⇒ Object
Returns the value of attribute end_time.
-
#options ⇒ Object
Returns the value of attribute options.
-
#queries ⇒ Object
Returns the value of attribute queries.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
Instance Method Summary collapse
- #<<(query) ⇒ Object
- #add_query(query) ⇒ Object
- #clear_queries ⇒ Object
-
#initialize(start_time, end_time = nil, **options) ⇒ Request
constructor
A new instance of Request.
- #remove_query(query) ⇒ Object
- #to_h ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(start_time, end_time = nil, **options) ⇒ Request
Returns a new instance of Request.
14 15 16 17 18 19 20 21 22 |
# File 'lib/memoir/request.rb', line 14 def initialize(start_time, end_time = nil, **) fail Memoir::Errors::ArgumentError, 'start_time cannot be nil' unless start_time @start_time = start_time @end_time = end_time @queries = [] @options = @arrays = false end |
Instance Attribute Details
#arrays ⇒ Object
Returns the value of attribute arrays.
2 3 4 |
# File 'lib/memoir/request.rb', line 2 def arrays @arrays end |
#end_time ⇒ Object
Returns the value of attribute end_time.
2 3 4 |
# File 'lib/memoir/request.rb', line 2 def end_time @end_time end |
#options ⇒ Object
Returns the value of attribute options.
2 3 4 |
# File 'lib/memoir/request.rb', line 2 def @options end |
#queries ⇒ Object
Returns the value of attribute queries.
2 3 4 |
# File 'lib/memoir/request.rb', line 2 def queries @queries end |
#start_time ⇒ Object
Returns the value of attribute start_time.
2 3 4 |
# File 'lib/memoir/request.rb', line 2 def start_time @start_time end |
Instance Method Details
#<<(query) ⇒ Object
24 25 26 |
# File 'lib/memoir/request.rb', line 24 def <<(query) add_query(query) end |
#add_query(query) ⇒ Object
28 29 30 |
# File 'lib/memoir/request.rb', line 28 def add_query(query) queries << query end |
#clear_queries ⇒ Object
36 37 38 |
# File 'lib/memoir/request.rb', line 36 def clear_queries queries.clear end |
#remove_query(query) ⇒ Object
32 33 34 |
# File 'lib/memoir/request.rb', line 32 def remove_query(query) queries.delete query end |
#to_h ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/memoir/request.rb', line 44 def to_h validate! hash = { 'start' => start_time.instance_of?(Memoir::TimePeriod) ? "#{start_time}-ago" : start_time.to_i, 'queries' => queries.map(&:to_h) } hash['end'] = end_time.to_i if end_time .each_pair { |key, value| hash[VALID_OPTIONS[key]] = value } hash end |
#to_json ⇒ Object
40 41 42 |
# File 'lib/memoir/request.rb', line 40 def to_json JSON.pretty_generate(to_h) end |