Module: Rating::Config

Defined in:
lib/rating/config.rb

Class Method Summary collapse

Class Method Details

.configObject



7
8
9
10
11
12
13
# File 'lib/rating/config.rb', line 7

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

    File.exist?(file_path) ? YAML.safe_load_file(file_path)['rating'] : {}
  end
end

.rate_tableObject



15
16
17
# File 'lib/rating/config.rb', line 15

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

.rating_levelsObject



23
24
25
# File 'lib/rating/config.rb', line 23

def rating_levels
  @rating_levels ||= config[__method__.to_s] || 5
end

.rating_tableObject



19
20
21
# File 'lib/rating/config.rb', line 19

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

.rating_z_scoreObject



27
28
29
# File 'lib/rating/config.rb', line 27

def rating_z_score
  @rating_z_score ||= config[__method__.to_s] || 1.96
end

.validationsObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rating/config.rb', line 31

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