class RedashExporter::Query

Attributes

data[RW]
sort_key[RW]

Public Class Methods

new(raw) click to toggle source
# File lib/redash_exporter/query.rb, line 13
def initialize(raw)
  @data = raw.deep_symbolize_keys
  @sort_key = :id
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/redash_exporter/query.rb, line 39
def <=>(other)
  self[@sort_key] <=> other[@sort_key]
end
[](key) click to toggle source
# File lib/redash_exporter/query.rb, line 18
def [](key)
  @data[key.to_sym]
end
export(dir: '.', force: false, **) click to toggle source
# File lib/redash_exporter/query.rb, line 43
def export(dir: '.', force: false, **)
  path = File.expand_path("#{dir}/#{file_name}")
  Exporter.export(path, to_s, force: force)
end
to_json(*_args) click to toggle source
# File lib/redash_exporter/query.rb, line 35
def to_json(*_args)
  JSON.generate(@data)
end
to_s() click to toggle source
# 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

Private Instance Methods

file_name() click to toggle source
# File lib/redash_exporter/query.rb, line 50
def file_name
  Zaru.sanitize! "#{@data[:id]}-#{@data[:name]}.sql"
end