Class: I18n::Backend::Callbacks

Inherits:
Delegator
  • Object
show all
Defined in:
lib/i18n/backend/callbacks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wrapped, before: nil, after: nil) ⇒ Callbacks

Returns a new instance of Callbacks.



8
9
10
11
12
13
# File 'lib/i18n/backend/callbacks.rb', line 8

def initialize(wrapped, before: nil, after: nil)
  super(wrapped)
  @wrapped = wrapped
  @before = before
  @after = after
end

Instance Attribute Details

#afterObject

Returns the value of attribute after.



6
7
8
# File 'lib/i18n/backend/callbacks.rb', line 6

def after
  @after
end

#beforeObject

Returns the value of attribute before.



5
6
7
# File 'lib/i18n/backend/callbacks.rb', line 5

def before
  @before
end

#wrappedObject (readonly)

Returns the value of attribute wrapped.



4
5
6
# File 'lib/i18n/backend/callbacks.rb', line 4

def wrapped
  @wrapped
end

Instance Method Details

#__getobj__Object



28
29
30
# File 'lib/i18n/backend/callbacks.rb', line 28

def __getobj__
  wrapped
end

#__setobj__(obj) ⇒ Object

implement the Delegator interface



24
25
26
# File 'lib/i18n/backend/callbacks.rb', line 24

def __setobj__(obj)
  @wrapped = obj
end

#translate(locale, key, options = {}) ⇒ Object



15
16
17
18
19
20
# File 'lib/i18n/backend/callbacks.rb', line 15

def translate(locale, key, options = {})
  locale, key, options = before.call(locale, key, options) if before
  result = wrapped.translate(locale, key, options)
  result = after.call(locale, key, options, result) if after
  result
end