Class: I18nliner::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/i18nliner/scope.rb

Direct Known Subclasses

ControllerScope

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope = nil, options = {}) ⇒ Scope

Returns a new instance of Scope.


10
11
12
13
14
15
# File 'lib/i18nliner/scope.rb', line 10

def initialize(scope = nil, options = {})
  @scope = scope ? "#{scope}." : scope
  @allow_relative = options.fetch(:allow_relative, false)
  @remove_whitespace = options.fetch(:remove_whitespace, false)
  @context = options.fetch(:context, nil)
end

Instance Attribute Details

#allow_relativeObject (readonly) Also known as: allow_relative?

Returns the value of attribute allow_relative


4
5
6
# File 'lib/i18nliner/scope.rb', line 4

def allow_relative
  @allow_relative
end

#contextObject (readonly)

Returns the value of attribute context


5
6
7
# File 'lib/i18nliner/scope.rb', line 5

def context
  @context
end

#remove_whitespaceObject Also known as: remove_whitespace?

Returns the value of attribute remove_whitespace


7
8
9
# File 'lib/i18nliner/scope.rb', line 7

def remove_whitespace
  @remove_whitespace
end

#scopeObject (readonly)

Returns the value of attribute scope


3
4
5
# File 'lib/i18nliner/scope.rb', line 3

def scope
  @scope
end

Class Method Details

.rootObject


31
32
33
# File 'lib/i18nliner/scope.rb', line 31

def self.root
  @root ||= new
end

Instance Method Details

#normalize_key(key, inferred, i18n_scope) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/i18nliner/scope.rb', line 17

def normalize_key(key, inferred, i18n_scope)
  return key if key.nil?
  if key.is_a?(Array)
    return key.map { |k| normalize_key(k, inferred, i18n_scope) }
  end

  key = key.to_s.dup
  if allow_relative? && key.sub!(/\A\./, '')
    scope + key
  else
    key
  end
end

#root?Boolean

Returns:

  • (Boolean)

35
36
37
# File 'lib/i18nliner/scope.rb', line 35

def root?
  scope.blank?
end