Sha256: f84d3913808a2cf62e83c51646563194b12243706a400ce08d3b81a1858570c2

Contents?: true

Size: 979 Bytes

Versions: 44

Compression:

Stored size: 979 Bytes

Contents

module ForestLiana
  class StatsController < ForestLiana::ApplicationController
    if Rails::VERSION::MAJOR < 4
      before_filter :find_resource
    else
      before_action :find_resource
    end

    def show
      case params[:type].try(:downcase)
      when 'value'
        stat = ValueStatGetter.new(@resource, params)
      when 'pie'
        stat = PieStatGetter.new(@resource, params)
      when 'line'
        stat = LineStatGetter.new(@resource, params)
      end

      stat.perform
      if stat.record
        render json: serialize_model(stat.record), serializer: nil
      else
        render json: {status: 404}, status: :not_found, serializer: nil
      end
    end

    private

    def find_resource
      @resource = SchemaUtils.find_model_from_table_name(params[:collection])

      if @resource.nil? || !@resource.ancestors.include?(ActiveRecord::Base)
        render json: {status: 404}, status: :not_found, serializer: nil
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
forest_liana-1.6.5 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.6.4 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.6.3 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.6.2 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.6.1 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.6.0 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.5.26 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.5.25 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.5.24 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.5.23 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.5.22 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.5.21 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.5.20 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.5.19 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.5.18 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.5.17 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.5.16 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.5.15 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.5.14 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.5.13 app/controllers/forest_liana/stats_controller.rb