-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathconfiguration.rb
86 lines (75 loc) · 2.45 KB
/
configuration.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
module Mobility
=begin
Stores shared Mobility configuration referenced by all backends.
=end
class Configuration
RESERVED_OPTION_KEYS = %i[backend model_class].freeze
# Alias for mobility_accessor (defaults to +translates+)
# @return [Symbol]
attr_accessor :accessor_method
# Name of query scope/dataset method (defaults to +i18n+)
# @return [Symbol]
attr_accessor :query_method
# Default set of options. These will be merged with any backend options
# when defining translated attributes (with +translates+). Default options
# may not include the keys 'backend' or 'model_class'.
# @return [Hash]
attr_reader :default_options
def default_options=(options)
if (keys = options.keys & RESERVED_OPTION_KEYS).present?
raise ReservedOptionKey,
"Default options may not contain the following reserved keys: #{keys.join(', ')}"
else
@default_options = options
end
end
# Plugins to apply. Order of plugins is important, as this becomes the
# order in which plugins modules are included into the backend class or
# attributes instance.
# @return [Array<Symbol>]
attr_accessor :plugins
# Default fallbacks instance
# @return [I18n::Locale::Fallbacks]
def default_fallbacks(fallbacks = {})
@default_fallbacks.call(fallbacks)
end
attr_writer :default_fallbacks
# Default backend to use (can be symbol or actual backend class)
# @return [Symbol,Class]
attr_accessor :default_backend
# Returns set of default accessor locles to use (defaults to
# +I18n.available_locales+)
# @return [Array<Symbol>]
def default_accessor_locales
if @default_accessor_locales.is_a?(Proc)
@default_accessor_locales.call
else
@default_accessor_locales
end
end
attr_writer :default_accessor_locales
def initialize
@accessor_method = :translates
@query_method = :i18n
@default_fallbacks = lambda { |fallbacks| I18n::Locale::Fallbacks.new(fallbacks) }
@default_accessor_locales = lambda { I18n.available_locales }
@default_options = {
cache: true,
dirty: false,
fallbacks: nil,
presence: true,
default: nil
}
@plugins = %i[
cache
dirty
fallbacks
presence
default
fallthrough_accessors
locale_accessors
]
end
class ReservedOptionKey < Exception; end
end
end