Class: Mobility::Configuration
- Inherits:
-
Object
- Object
- Mobility::Configuration
- Defined in:
- lib/mobility/configuration.rb
Overview
Stores shared Mobility configuration referenced by all backends.
Defined Under Namespace
Classes: ReservedOptionKey
Constant Summary collapse
- RESERVED_OPTION_KEYS =
%i[backend model_class].freeze
Instance Attribute Summary collapse
-
#accessor_method ⇒ Symbol
Alias for mobility_accessor (defaults to
translates). -
#default_accessor_locales ⇒ Array<Symbol>
Returns set of default accessor locles to use (defaults to
I18n.available_locales). -
#default_backend ⇒ Symbol, Class
Default backend to use (can be symbol or actual backend class).
-
#default_fallbacks(fallbacks = {}) ⇒ I18n::Locale::Fallbacks
Default fallbacks instance.
-
#default_options ⇒ Hash
Default set of options.
-
#plugins ⇒ Array<Symbol>
Plugins to apply.
-
#query_method ⇒ Symbol
Name of query scope/dataset method (defaults to
i18n).
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/mobility/configuration.rb', line 61 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 |
Instance Attribute Details
#accessor_method ⇒ Symbol
Alias for mobility_accessor (defaults to translates)
12 13 14 |
# File 'lib/mobility/configuration.rb', line 12 def accessor_method @accessor_method end |
#default_accessor_locales ⇒ Array<Symbol>
Returns set of default accessor locles to use (defaults to
I18n.available_locales)
52 53 54 55 56 57 58 |
# File 'lib/mobility/configuration.rb', line 52 def default_accessor_locales if @default_accessor_locales.is_a?(Proc) @default_accessor_locales.call else @default_accessor_locales end end |
#default_backend ⇒ Symbol, Class
Default backend to use (can be symbol or actual backend class)
47 48 49 |
# File 'lib/mobility/configuration.rb', line 47 def default_backend @default_backend end |
#default_fallbacks(fallbacks = {}) ⇒ I18n::Locale::Fallbacks
Default fallbacks instance
40 41 42 |
# File 'lib/mobility/configuration.rb', line 40 def default_fallbacks(fallbacks = {}) @default_fallbacks.call(fallbacks) end |
#default_options ⇒ Hash
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'.
22 23 24 |
# File 'lib/mobility/configuration.rb', line 22 def @default_options end |
#plugins ⇒ Array<Symbol>
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.
36 37 38 |
# File 'lib/mobility/configuration.rb', line 36 def plugins @plugins end |
#query_method ⇒ Symbol
Name of query scope/dataset method (defaults to i18n)
16 17 18 |
# File 'lib/mobility/configuration.rb', line 16 def query_method @query_method end |