Sha256: f29e2fd177a5bf1c5436617534e0469d102b3c1882f508431cae171a90e3f07c

Contents?: true

Size: 993 Bytes

Versions: 39

Compression:

Stored size: 993 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_collection_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

39 entries across 39 versions & 1 rubygems

Version Path
forest_liana-2.1.1 app/controllers/forest_liana/stats_controller.rb
forest_liana-2.1.0 app/controllers/forest_liana/stats_controller.rb
forest_liana-2.0.4 app/controllers/forest_liana/stats_controller.rb
forest_liana-2.0.3 app/controllers/forest_liana/stats_controller.rb
forest_liana-2.0.2 app/controllers/forest_liana/stats_controller.rb
forest_liana-2.0.1 app/controllers/forest_liana/stats_controller.rb
forest_liana-2.0.0 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.9.8 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.9.7 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.9.6 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.9.5 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.9.4 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.9.3 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.9.2 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.9.1 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.9.0 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.8.1 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.8.0 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.7.10 app/controllers/forest_liana/stats_controller.rb
forest_liana-1.7.9 app/controllers/forest_liana/stats_controller.rb