Sha256: 8393d616f460f44a316ca91bb6a9d081ee9715b945467c16b60522392210b257

Contents?: true

Size: 860 Bytes

Versions: 21

Compression:

Stored size: 860 Bytes

Contents

module ForestLiana
  class HasManyGetter
    def initialize(resource, association, params)
      @resource = resource
      @association = association
      @params = params
    end

    def perform
      @records = @resource.find(@params[:id]).send(@params[:association_name])
    end

    def records
      @records.limit(limit).offset(offset)
    end

    def count
      @records.to_a.length
    end

    private

    def offset
      return 0 unless pagination?

      number = @params[:page][:number]
      if number && number.to_i > 0
        (number.to_i - 1) * limit
      else
        0
      end
    end

    def limit
      return 10 unless pagination?

      if @params[:page][:size]
        @params[:page][:size].to_i
      else
        10
      end
    end

    def pagination?
      @params[:page] && @params[:page][:number]
    end

  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
forest_liana-1.2.5 app/services/forest_liana/has_many_getter.rb
forest_liana-1.2.3 app/services/forest_liana/has_many_getter.rb
forest_liana-1.2.2 app/services/forest_liana/has_many_getter.rb
forest_liana-1.2.1 app/services/forest_liana/has_many_getter.rb
forest_liana-1.1.35 app/services/forest_liana/has_many_getter.rb
forest_liana-1.1.34 app/services/forest_liana/has_many_getter.rb
forest_liana-1.1.33 app/services/forest_liana/has_many_getter.rb
forest_liana-1.1.32 app/services/forest_liana/has_many_getter.rb
forest_liana-1.1.31 app/services/forest_liana/has_many_getter.rb
forest_liana-1.1.30 app/services/forest_liana/has_many_getter.rb
forest_liana-1.1.29 app/services/forest_liana/has_many_getter.rb
forest_liana-1.1.28 app/services/forest_liana/has_many_getter.rb
forest_liana-1.1.27 app/services/forest_liana/has_many_getter.rb
forest_liana-1.1.26 app/services/forest_liana/has_many_getter.rb
forest_liana-1.1.25 app/services/forest_liana/has_many_getter.rb
forest_liana-1.1.23 app/services/forest_liana/has_many_getter.rb
forest_liana-1.1.22 app/services/forest_liana/has_many_getter.rb
forest_liana-1.1.20 app/services/forest_liana/has_many_getter.rb
forest_liana-1.1.19 app/services/forest_liana/has_many_getter.rb
forest_liana-1.1.18 app/services/forest_liana/has_many_getter.rb