Sha256: 316811d3ba02f18261e4ae4a473cd2d15c5f6098cbc4649a7270adab03135fa4

Contents?: true

Size: 913 Bytes

Versions: 2

Compression:

Stored size: 913 Bytes

Contents

# frozen_string_literal: true

module Rating
  module Config
    module_function

    def config
      @config ||= begin
        file_path = File.expand_path('config/rating.yml')

        return {} unless File.exist?(file_path)

        YAML.safe_load(File.read(file_path))['rating']
      end
    end

    def rate_table
      @rate_table ||= config[__method__.to_s] || 'rating_rates'
    end

    def rating_table
      @rating_table ||= config[__method__.to_s] || 'rating_ratings'
    end

    def validations
      @validations ||= begin
        default_scope = %w[author_type resource_id resource_type scopeable_id scopeable_type]

        {
          rate: {
            case_sensitive: config.dig('validations', 'rate', 'case_sensitive') || false,
            scope:          config.dig('validations', 'rate', 'scope') || default_scope
          }
        }.deep_stringify_keys
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rating-0.8.0 lib/rating/config.rb
rating-0.7.0 lib/rating/config.rb