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
configure
class method to apply any normalization to the options hash -
call the
setup
method yielding attributes and options to configure the model class
Defined Under Namespace
Modules: ClassMethods Classes: Translation
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
-
#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.
58 59 60 |
# File 'lib/mobility/backend.rb', line 58 def attribute @attribute end |
#model ⇒ Object (readonly)
Returns Model on which backend is defined.
61 62 63 |
# File 'lib/mobility/backend.rb', line 61 def model @model end |
Class Method Details
.included(base) ⇒ Object
Extend included class with setup
method and other class methods
116 117 118 119 |
# File 'lib/mobility/backend.rb', line 116 def self.included(base) base.extend ClassMethods base.singleton_class.attr_reader :options, :model_class end |
Instance Method Details
#each {|Translation| ... } ⇒ Object
Yields translations to block
90 91 92 |
# File 'lib/mobility/backend.rb', line 90 def each each_locale { |locale| yield Translation.new(self, locale) } end |
#each_locale {|Locale| ... } ⇒ Object
Yields locales available for this attribute.
85 86 |
# File 'lib/mobility/backend.rb', line 85 def each_locale end |
#initialize(*args) ⇒ Object
66 67 68 69 |
# File 'lib/mobility/backend.rb', line 66 def initialize(*args) @model = args[0] @attribute = args[1] end |
#locales ⇒ Array<Symbol>
List locales available for this backend.
96 97 98 |
# File 'lib/mobility/backend.rb', line 96 def locales map(&:locale) end |
#model_class ⇒ Class
Returns name of model in which backend is used.
|
# File 'lib/mobility/backend.rb', line 106
|
#options ⇒ Hash
Returns options.
111 112 113 |
# File 'lib/mobility/backend.rb', line 111 def self.class. end |