Module: Confstruct

Defined in:
lib/confstruct.rb,
lib/confstruct/configuration.rb,
lib/confstruct/hash_with_struct_access.rb

Defined Under Namespace

Classes: Configuration, Deferred, HashWithStructAccess

Constant Summary collapse

VERSION =
'1.1.0'

Class Method Summary collapse

Class Method Details

.deferred(&block) ⇒ Object



19
# File 'lib/confstruct/hash_with_struct_access.rb', line 19

def self.deferred █ Deferred.new(&block); end

.i18n(key = nil, &block) ⇒ Object

Raises:

  • (NameError)


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/confstruct/hash_with_struct_access.rb', line 21

def self.i18n key=nil, &block
  raise NameError, "I18n handler not loaded" unless Object.const_defined? :I18n # ensure the Rails I18n handler is loaded
  Deferred.new do |hwsa|
    val = block_given? ? eval_or_yield(hwsa, &block) : key
    if val.is_a?(Date) or val.is_a?(Time) or val.is_a?(DateTime)
      ::I18n.localize val
    else
      ::I18n.translate val
    end
  end
end