Skip to content

Business intelligence made simple

Indent private methods so you know where they are

Andrew Kane47beb5a3c954
diff --git a/app/controllers/blazer/checks_controller.rb b/app/controllers/blazer/checks_controller.rb
index ed475dca..402aa6a5 100644
--- a/app/controllers/blazer/checks_controller.rb
+++ b/app/controllers/blazer/checks_controller.rb
@@ -45,12 +45,12 @@ module Blazer
private
- def check_params
- params.require(:check).permit(:query_id, :emails, :invert, :check_type, :schedule)
- end
+ def check_params
+ params.require(:check).permit(:query_id, :emails, :invert, :check_type, :schedule)
+ end
- def set_check
- @check = Blazer::Check.find(params[:id])
- end
+ def set_check
+ @check = Blazer::Check.find(params[:id])
+ end
end
end
diff --git a/app/controllers/blazer/dashboards_controller.rb b/app/controllers/blazer/dashboards_controller.rb
index 607511ff..38564356 100644
--- a/app/controllers/blazer/dashboards_controller.rb
+++ b/app/controllers/blazer/dashboards_controller.rb
@@ -69,37 +69,37 @@ module Blazer
redirect_to dashboard_path(@dashboard, variable_params)
end
- protected
+ private
- def dashboard_params
- params.require(:dashboard).permit(:name)
- end
+ def dashboard_params
+ params.require(:dashboard).permit(:name)
+ end
- def set_dashboard
- @dashboard = Blazer::Dashboard.find(params[:id])
- end
+ def set_dashboard
+ @dashboard = Blazer::Dashboard.find(params[:id])
+ end
- def update_dashboard(dashboard)
- dashboard.assign_attributes(dashboard_params)
- Blazer::Dashboard.transaction do
- if params[:query_ids].is_a?(Array)
- query_ids = params[:query_ids].map(&:to_i)
- @queries = Blazer::Query.find(query_ids).sort_by { |q| query_ids.index(q.id) }
- end
- if dashboard.save
- if @queries
- @queries.each_with_index do |query, i|
- dashboard_query = dashboard.dashboard_queries.where(query_id: query.id).first_or_initialize
- dashboard_query.position = i
- dashboard_query.save!
- end
- if dashboard.persisted?
- dashboard.dashboard_queries.where.not(query_id: query_ids).destroy_all
+ def update_dashboard(dashboard)
+ dashboard.assign_attributes(dashboard_params)
+ Blazer::Dashboard.transaction do
+ if params[:query_ids].is_a?(Array)
+ query_ids = params[:query_ids].map(&:to_i)
+ @queries = Blazer::Query.find(query_ids).sort_by { |q| query_ids.index(q.id) }
+ end
+ if dashboard.save
+ if @queries
+ @queries.each_with_index do |query, i|
+ dashboard_query = dashboard.dashboard_queries.where(query_id: query.id).first_or_initialize
+ dashboard_query.position = i
+ dashboard_query.save!
+ end
+ if dashboard.persisted?
+ dashboard.dashboard_queries.where.not(query_id: query_ids).destroy_all
+ end
end
+ true
end
- true
end
end
- end
end
end
diff --git a/app/controllers/blazer/queries_controller.rb b/app/controllers/blazer/queries_controller.rb
index c82c919c..d83d6216 100644
--- a/app/controllers/blazer/queries_controller.rb
+++ b/app/controllers/blazer/queries_controller.rb
@@ -188,138 +188,138 @@ module Blazer
private
- def continue_run
- render json: {run_id: @run_id, timestamp: @timestamp}, status: :accepted
- end
-
- def render_run
- @checks = @query ? @query.checks.order(:id) : []
-
- @first_row = @rows.first || []
- @column_types = []
- if @rows.any?
- @columns.each_with_index do |column, i|
- @column_types << (
- case @first_row[i]
- when Integer
- "int"
- when Float, BigDecimal
- "float"
- else
- "string-ins"
- end
- )
- end
+ def continue_run
+ render json: {run_id: @run_id, timestamp: @timestamp}, status: :accepted
end
- @filename = @query.name.parameterize if @query
- @min_width_types = @columns.each_with_index.select { |c, i| @first_row[i].is_a?(Time) || @first_row[i].is_a?(String) || @data_source.smart_columns[c] }.map(&:last)
-
- @boom = @result.boom if @result
-
- @linked_columns = @data_source.linked_columns
-
- @markers = []
- [["latitude", "longitude"], ["lat", "lon"], ["lat", "lng"]].each do |keys|
- lat_index = @columns.index(keys.first)
- lon_index = @columns.index(keys.last)
- if lat_index && lon_index
- @markers =
- @rows.select do |r|
- r[lat_index] && r[lon_index]
- end.map do |r|
- {
- title: r.each_with_index.map{ |v, i| i == lat_index || i == lon_index ? nil : "<strong>#{@columns[i]}:</strong> #{v}" }.compact.join("<br />").truncate(140),
- latitude: r[lat_index],
- longitude: r[lon_index]
- }
- end
+ def render_run
+ @checks = @query ? @query.checks.order(:id) : []
+
+ @first_row = @rows.first || []
+ @column_types = []
+ if @rows.any?
+ @columns.each_with_index do |column, i|
+ @column_types << (
+ case @first_row[i]
+ when Integer
+ "int"
+ when Float, BigDecimal
+ "float"
+ else
+ "string-ins"
+ end
+ )
+ end
end
- end
- respond_to do |format|
- format.html do
- render layout: false
+ @filename = @query.name.parameterize if @query
+ @min_width_types = @columns.each_with_index.select { |c, i| @first_row[i].is_a?(Time) || @first_row[i].is_a?(String) || @data_source.smart_columns[c] }.map(&:last)
+
+ @boom = @result.boom if @result
+
+ @linked_columns = @data_source.linked_columns
+
+ @markers = []
+ [["latitude", "longitude"], ["lat", "lon"], ["lat", "lng"]].each do |keys|
+ lat_index = @columns.index(keys.first)
+ lon_index = @columns.index(keys.last)
+ if lat_index && lon_index
+ @markers =
+ @rows.select do |r|
+ r[lat_index] && r[lon_index]
+ end.map do |r|
+ {
+ title: r.each_with_index.map{ |v, i| i == lat_index || i == lon_index ? nil : "<strong>#{@columns[i]}:</strong> #{v}" }.compact.join("<br />").truncate(140),
+ latitude: r[lat_index],
+ longitude: r[lon_index]
+ }
+ end
+ end
end
- format.csv do
- send_data csv_data(@columns, @rows, @data_source), type: "text/csv; charset=utf-8; header=present", disposition: "attachment; filename=\"#{@query.try(:name).try(:parameterize).presence || 'query'}.csv\""
+
+ respond_to do |format|
+ format.html do
+ render layout: false
+ end
+ format.csv do
+ send_data csv_data(@columns, @rows, @data_source), type: "text/csv; charset=utf-8; header=present", disposition: "attachment; filename=\"#{@query.try(:name).try(:parameterize).presence || 'query'}.csv\""
+ end
end
end
- end
- def set_queries(limit = nil)
- @my_queries =
- if limit && blazer_user && !params[:filter] && Blazer.audit
- queries_by_ids(Blazer::Audit.where(user_id: blazer_user.id).where("created_at > ?", 30.days.ago).where("query_id IS NOT NULL").group(:query_id).order("count_all desc").count.keys)
- else
- []
- end
+ def set_queries(limit = nil)
+ @my_queries =
+ if limit && blazer_user && !params[:filter] && Blazer.audit
+ queries_by_ids(Blazer::Audit.where(user_id: blazer_user.id).where("created_at > ?", 30.days.ago).where("query_id IS NOT NULL").group(:query_id).order("count_all desc").count.keys)
+ else
+ []
+ end
- @queries = Blazer::Query.named.select(:id, :name, :creator_id, :statement)
- @queries = @queries.includes(:creator) if Blazer.user_class
+ @queries = Blazer::Query.named.select(:id, :name, :creator_id, :statement)
+ @queries = @queries.includes(:creator) if Blazer.user_class
- if blazer_user && params[:filter] == "mine"
- @queries = @queries.where(creator_id: blazer_user.id).reorder(updated_at: :desc)
- elsif blazer_user && params[:filter] == "viewed" && Blazer.audit
- @queries = queries_by_ids(Blazer::Audit.where(user_id: blazer_user.id).order(created_at: :desc).limit(500).pluck(:query_id).uniq)
- else
- @queries = @queries.where("id NOT IN (?)", @my_queries.map(&:id)) if @my_queries.any?
- @queries = @queries.limit(limit) if limit
- @queries = @queries.order(:name)
- end
- @queries = @queries.to_a
+ if blazer_user && params[:filter] == "mine"
+ @queries = @queries.where(creator_id: blazer_user.id).reorder(updated_at: :desc)
+ elsif blazer_user && params[:filter] == "viewed" && Blazer.audit
+ @queries = queries_by_ids(Blazer::Audit.where(user_id: blazer_user.id).order(created_at: :desc).limit(500).pluck(:query_id).uniq)
+ else
+ @queries = @queries.where("id NOT IN (?)", @my_queries.map(&:id)) if @my_queries.any?
+ @queries = @queries.limit(limit) if limit
+ @queries = @queries.order(:name)
+ end
+ @queries = @queries.to_a
- @more = limit && @queries.size >= limit
+ @more = limit && @queries.size >= limit
- @queries = (@my_queries + @queries).select { |q| !q.name.to_s.start_with?("#") || q.try(:creator).try(:id) == blazer_user.try(:id) }
+ @queries = (@my_queries + @queries).select { |q| !q.name.to_s.start_with?("#") || q.try(:creator).try(:id) == blazer_user.try(:id) }
- @queries =
- @queries.map do |q|
- {
- id: q.id,
- name: q.name,
- creator: blazer_user && q.try(:creator) == blazer_user ? "You" : q.try(:creator).try(Blazer.user_name),
- vars: extract_vars(q.statement).join(", "),
- to_param: q.to_param
- }
- end
- end
+ @queries =
+ @queries.map do |q|
+ {
+ id: q.id,
+ name: q.name,
+ creator: blazer_user && q.try(:creator) == blazer_user ? "You" : q.try(:creator).try(Blazer.user_name),
+ vars: extract_vars(q.statement).join(", "),
+ to_param: q.to_param
+ }
+ end
+ end
- def queries_by_ids(favorite_query_ids)
- queries = Blazer::Query.named.where(id: favorite_query_ids)
- queries = queries.includes(:creator) if Blazer.user_class
- queries = queries.index_by(&:id)
- favorite_query_ids.map { |query_id| queries[query_id] }.compact
- end
+ def queries_by_ids(favorite_query_ids)
+ queries = Blazer::Query.named.where(id: favorite_query_ids)
+ queries = queries.includes(:creator) if Blazer.user_class
+ queries = queries.index_by(&:id)
+ favorite_query_ids.map { |query_id| queries[query_id] }.compact
+ end
- def set_query
- @query = Blazer::Query.find(params[:id].to_s.split("-").first)
- end
+ def set_query
+ @query = Blazer::Query.find(params[:id].to_s.split("-").first)
+ end
- def query_params
- params.require(:query).permit(:name, :description, :statement, :data_source)
- end
+ def query_params
+ params.require(:query).permit(:name, :description, :statement, :data_source)
+ end
- def blazer_params
- params[:blazer] || {}
- end
+ def blazer_params
+ params[:blazer] || {}
+ end
- def csv_data(columns, rows, data_source)
- CSV.generate do |csv|
- csv << columns
- rows.each do |row|
- csv << row.each_with_index.map { |v, i| v.is_a?(Time) ? blazer_time_value(data_source, columns[i], v) : v }
+ def csv_data(columns, rows, data_source)
+ CSV.generate do |csv|
+ csv << columns
+ rows.each do |row|
+ csv << row.each_with_index.map { |v, i| v.is_a?(Time) ? blazer_time_value(data_source, columns[i], v) : v }
+ end
end
end
- end
- def blazer_time_value(data_source, k, v)
- data_source.local_time_suffix.any? { |s| k.ends_with?(s) } ? v.to_s.sub(" UTC", "") : v.in_time_zone(Blazer.time_zone)
- end
- helper_method :blazer_time_value
+ def blazer_time_value(data_source, k, v)
+ data_source.local_time_suffix.any? { |s| k.ends_with?(s) } ? v.to_s.sub(" UTC", "") : v.in_time_zone(Blazer.time_zone)
+ end
+ helper_method :blazer_time_value
- def blazer_run_id
- params[:run_id].to_s.gsub(/[^a-z0-9\-]/i, "")
- end
+ def blazer_run_id
+ params[:run_id].to_s.gsub(/[^a-z0-9\-]/i, "")
+ end
end
end