Module: Mobility::Backend
- Includes:
- Enumerable
- Included in:
- Mobility::Backends::Hash, Mobility::Backends::Null
- Defined in:
- lib/mobility/backend.rb
Overview
Defines a minimum set of shared components included in any backend. These are:
-
a reader returning the
model
on which the backend is defined (#model) -
a reader returning the
attribute
for which the backend is defined (#attribute) -
a constructor setting these two elements (
model
,attribute
) -
a
setup
method adding any configuration code to the model class (ClassMethods#setup)
On top of this, a backend will normally:
-
implement a
read
instance method to read from the backend -
implement a
write
instance method to write to the backend -
implement an
each_locale
instance method to iterate through available locales (used to define otherEnumerable
traversal and search methods) -
implement a
valid_keys
class method returning an array of symbols corresponding to valid keys for configuring this backend. -
implement a
configure
class method to apply any normalization to the keys on the options hash included invalid_keys
-
call the
setup
method yielding attributes and options (and optionally the configured backend class) to configure the model class
Defined Under Namespace
Modules: ClassMethods, ConfiguredBackend Classes: ConfiguredError, Translation, UnconfiguredError
Instance Attribute Summary collapse
-
#attribute ⇒ String
readonly
Backend attribute.
-
#model ⇒ Object
readonly
Model on which backend is defined.
Class Method Summary collapse
-
.included(base) ⇒ Object
Extend included class with
setup
method and other class methods.
Instance Method Summary collapse
- #==(backend) ⇒ Object
-
#each {|Translation| ... } ⇒ Object
Yields translations to block.
-
#each_locale {|Locale| ... } ⇒ Object
Yields locales available for this attribute.
- #initialize(*args) ⇒ Object
-
#locales ⇒ Array<Symbol>
List locales available for this backend.
-
#model_class ⇒ Class
Returns name of model in which backend is used.
-
#options ⇒ Hash
Options.
-
#present?(locale, options = {}) ⇒ TrueClass, FalseClass
Whether translation is present for locale.
Instance Attribute Details
#attribute ⇒ String (readonly)
Returns Backend attribute.
67 68 69 |
# File 'lib/mobility/backend.rb', line 67 def attribute @attribute end |
#model ⇒ Object (readonly)
Returns Model on which backend is defined.
70 71 72 |
# File 'lib/mobility/backend.rb', line 70 def model @model end |
Class Method Details
.included(base) ⇒ Object
Extend included class with setup
method and other class methods
131 132 133 |
# File 'lib/mobility/backend.rb', line 131 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#==(backend) ⇒ Object
80 81 82 83 84 |
# File 'lib/mobility/backend.rb', line 80 def ==(backend) backend.class == self.class && backend.attribute == attribute && backend.model == model end |
#each {|Translation| ... } ⇒ Object
Yields translations to block
105 106 107 |
# File 'lib/mobility/backend.rb', line 105 def each each_locale { |locale| yield Translation.new(self, locale) } end |
#each_locale {|Locale| ... } ⇒ Object
Yields locales available for this attribute.
100 101 |
# File 'lib/mobility/backend.rb', line 100 def each_locale end |
#initialize(*args) ⇒ Object
75 76 77 78 |
# File 'lib/mobility/backend.rb', line 75 def initialize(*args) @model = args[0] @attribute = args[1] end |
#locales ⇒ Array<Symbol>
List locales available for this backend.
111 112 113 |
# File 'lib/mobility/backend.rb', line 111 def locales map(&:locale) end |
#model_class ⇒ Class
Returns name of model in which backend is used.
|
# File 'lib/mobility/backend.rb', line 121
|
#options ⇒ Hash
Returns options.
126 127 128 |
# File 'lib/mobility/backend.rb', line 126 def self.class. end |