class Sleek::QueryCommand
Internal: A query command. It's primarily responsible for breaking a timeframe into intervals (if applicable), running the query on each sub-timeframe, and wrapping up a result.
Attributes
bucket[R]
klass[R]
namespace[R]
options[R]
Public Class Methods
new(klass, namespace, bucket, options = {})
click to toggle source
Internal: Initialize the query command.
klass - the Sleek::Queries::Query
subclass. namespace - the Sleek::Namespace
object. bucket - the String bucket name. options - the optional Hash of options. Everything but
:timeframe and :interval will be passed on to the query class. :timeframe - the optional timeframe description. :timezone - the optional TZ identifier. :interval - the optional interval description. If passed, requires that :timeframe is passed as well.
Raises ArgumentError if :interval is passed but :timeframe is not.
# File lib/sleek/query_command.rb, line 23 def initialize(klass, namespace, bucket, options = {}) @klass = klass @namespace = namespace @bucket = bucket @timeframe = options.delete(:timeframe) @timezone = options.delete(:timezone) @interval = options.delete(:interval) @options = options if @interval.present? && @timeframe.blank? raise ArgumentError, 'interval requires timeframe' end end
Public Instance Methods
new_query(timeframe)
click to toggle source
Internal: Instantiate a query object.
timeframe - the time range.
# File lib/sleek/query_command.rb, line 56 def new_query(timeframe) klass.new(namespace, bucket, options.merge(timeframe: timeframe)) end
run()
click to toggle source
Internal: Run the query on each timeframe.
# File lib/sleek/query_command.rb, line 61 def run if series? series.map do |tf| { timeframe: tf, value: new_query(tf).run } end else new_query(timeframe).run end end
series()
click to toggle source
Internal: Split timeframe into sub-timeframes of interval.
# File lib/sleek/query_command.rb, line 49 def series Sleek::Interval.new(@interval, timeframe).timeframes end
series?()
click to toggle source
Internal: Check if options include interval.
# File lib/sleek/query_command.rb, line 38 def series? @interval.present? end
timeframe()
click to toggle source
Internal: Parse a time range from the timeframe description. description.
# File lib/sleek/query_command.rb, line 44 def timeframe Sleek::Timeframe.to_range(@timeframe, @timezone) if @timeframe end