Class: RedashExporter::Query
- Inherits:
-
Object
- Object
- RedashExporter::Query
- Includes:
- Comparable
- Defined in:
- lib/redash_exporter/query.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#sort_key ⇒ Object
Returns the value of attribute sort_key.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #[](key) ⇒ Object
- #export(dir: '.', force: false) ⇒ Object
-
#initialize(raw) ⇒ Query
constructor
A new instance of Query.
- #to_json(*_args) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(raw) ⇒ Query
Returns a new instance of Query.
13 14 15 16 |
# File 'lib/redash_exporter/query.rb', line 13 def initialize(raw) @data = raw.deep_symbolize_keys @sort_key = :id end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
10 11 12 |
# File 'lib/redash_exporter/query.rb', line 10 def data @data end |
#sort_key ⇒ Object
Returns the value of attribute sort_key.
10 11 12 |
# File 'lib/redash_exporter/query.rb', line 10 def sort_key @sort_key end |
Instance Method Details
#<=>(other) ⇒ Object
39 40 41 |
# File 'lib/redash_exporter/query.rb', line 39 def <=>(other) self[@sort_key] <=> other[@sort_key] end |
#[](key) ⇒ Object
18 19 20 |
# File 'lib/redash_exporter/query.rb', line 18 def [](key) @data[key.to_sym] end |
#export(dir: '.', force: false) ⇒ Object
43 44 45 46 |
# File 'lib/redash_exporter/query.rb', line 43 def export(dir: '.', force: false, **) path = File.("#{dir}/#{file_name}") Exporter.export(path, to_s, force: force) end |
#to_json(*_args) ⇒ Object
35 36 37 |
# File 'lib/redash_exporter/query.rb', line 35 def to_json(*_args) JSON.generate(@data) end |
#to_s ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/redash_exporter/query.rb', line 22 def to_s <<~SQL /** * #{@data[:name]} * * created at #{@data[:created_at]} * last updated at #{@data[:updated_at]} * created by #{@data.dig(:user, :name)} (#{@data.dig(:user, :email)}) **/ #{@data[:query]} SQL end |