lib/influxer/metrics/relation.rb in influxer-0.1.0 vs lib/influxer/metrics/relation.rb in influxer-0.1.1
- old
+ new
@@ -58,10 +58,16 @@
self # self
end # end
CODE
end
+
+ class << self
+ # delegate array methods to to_a
+ delegate :to_xml, :to_yaml, :length, :collect, :map, :each, :all?, :include?, :to_ary, :join, to: :to_a
+ end
+
# Initialize new Relation for 'klass' (Class) metrics.
#
# Available params:
# :attributes - hash of attributes to be included to new Metrics object and where clause of Relation
#
@@ -131,24 +137,38 @@
end
def to_a
return @records if loaded?
load
- @records
end
def inspect
entries = to_a.take(11).map!(&:inspect)
entries[10] = '...' if entries.size == 11
"#<#{self.class.name} [#{entries.join(', ')}]>"
end
- def as_json
- to_a.as_json
+ def empty?
+ unless loaded?
+ # we don't need selects here
+ select_values.clear
+ limit(1).load
+ end
+ return @records.empty?
end
+ def as_json(options=nil)
+ to_a.as_json(options)
+ end
+
+ def load
+ @records = get_points(@instance.client.cached_query(to_sql))
+ @loaded = true
+ @records
+ end
+
def delete_all
sql = ["delete"]
sql << "from #{@instance.series}"
@@ -183,10 +203,11 @@
end
self
end
+
protected
def build_where(args, hargs, negate)
case
when (args.present? and args[0].is_a?(String))
where_values.concat args.map{|str| "(#{str})"}
@@ -232,14 +253,9 @@
unless negate
"#{key}>#{quoted(val.begin)} and #{key}<#{quoted(val.end)}"
else
"#{key}<#{quoted(val.begin)} and #{key}>#{quoted(val.end)}"
end
- end
-
- def load
- @records = get_points(@instance.client.cached_query(to_sql))
- @loaded = true
end
def loaded?
@loaded
end
\ No newline at end of file