Class: Module

Inherits:
Object show all
Defined in:
lib/eac_ruby_utils/patches/module/patch.rb,
lib/eac_ruby_utils/patches/module/context.rb,
lib/eac_ruby_utils/patches/module/speaker.rb,
lib/eac_ruby_utils/patches/module/listable.rb,
lib/eac_ruby_utils/patches/module/immutable.rb,
lib/eac_ruby_utils/patches/module/compare_by.rb,
lib/eac_ruby_utils/patches/module/require_sub.rb,
lib/eac_ruby_utils/patches/module/simple_cache.rb,
lib/eac_ruby_utils/patches/module/common_concern.rb,
lib/eac_ruby_utils/patches/module/i18n_translate.rb,
lib/eac_ruby_utils/patches/module/abstract_methods.rb

Constant Summary collapse

TRANSLATE_LOCALE_KEY =
:__locale

Instance Method Summary collapse

Instance Method Details

#common_concern(&after_callback) ⇒ Object



6
7
8
# File 'lib/eac_ruby_utils/patches/module/common_concern.rb', line 6

def common_concern(&after_callback)
  ::EacRubyUtils::CommonConcern.new(&after_callback).setup(self)
end

#compare_by(*fields) ⇒ Object



6
7
8
# File 'lib/eac_ruby_utils/patches/module/compare_by.rb', line 6

def compare_by(*fields)
  ::EacRubyUtils::CompareBy.new(fields).apply(self)
end

#enable_abstract_methods(*methods) ⇒ Object



6
7
8
9
# File 'lib/eac_ruby_utils/patches/module/abstract_methods.rb', line 6

def enable_abstract_methods(*methods)
  include ::EacRubyUtils::AbstractMethods
  abstract_methods(*methods)
end

#enable_contextObject

Patches module with [EacRubyUtils::Contextualizable].



8
9
10
# File 'lib/eac_ruby_utils/patches/module/context.rb', line 8

def enable_context
  ::EacRubyUtils.patch(self, ::EacRubyUtils::Contextualizable)
end

#enable_immutableObject



7
8
9
# File 'lib/eac_ruby_utils/patches/module/immutable.rb', line 7

def enable_immutable
  ::EacRubyUtils.patch(self, ::EacRubyUtils::Immutable)
end

#enable_listableObject



7
8
9
# File 'lib/eac_ruby_utils/patches/module/listable.rb', line 7

def enable_listable
  ::EacRubyUtils.patch(self, ::EacRubyUtils::Listable)
end

#enable_simple_cacheObject



7
8
9
# File 'lib/eac_ruby_utils/patches/module/simple_cache.rb', line 7

def enable_simple_cache
  ::EacRubyUtils.patch(self, ::EacRubyUtils::SimpleCache)
end

#enable_speakerObject



6
7
8
# File 'lib/eac_ruby_utils/patches/module/speaker.rb', line 6

def enable_speaker
  include ::EacRubyUtils::Speaker::Sender
end

#i18n_translate(entry_suffix, values = {}) ⇒ Object



9
10
11
12
13
# File 'lib/eac_ruby_utils/patches/module/i18n_translate.rb', line 9

def i18n_translate(entry_suffix, values = {})
  on_i18n_locale(values.delete(TRANSLATE_LOCALE_KEY)) do
    ::I18n.translate(i18n_translate_entry_full(entry_suffix), values)
  end
end

#i18n_translate_entry_full(entry_suffix) ⇒ Object



15
16
17
# File 'lib/eac_ruby_utils/patches/module/i18n_translate.rb', line 15

def i18n_translate_entry_full(entry_suffix)
  "#{i18n_translate_entry_self_prefix}.#{entry_suffix}"
end

#i18n_translate_entry_self_prefixObject



19
20
21
# File 'lib/eac_ruby_utils/patches/module/i18n_translate.rb', line 19

def i18n_translate_entry_self_prefix
  name.underscore.gsub('/', '.')
end

#on_i18n_locale(locale) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/eac_ruby_utils/patches/module/i18n_translate.rb', line 23

def on_i18n_locale(locale)
  old_locale = ::I18n.locale
  begin
    ::I18n.locale = locale
    yield
  ensure
    ::I18n.locale = old_locale
  end
end

#patch(patch_module) ⇒ Object



6
7
8
# File 'lib/eac_ruby_utils/patches/module/patch.rb', line 6

def patch(patch_module)
  ::EacRubyUtils.patch(self, patch_module)
end

#require_sub(file_path, options = {}) ⇒ Object



6
7
8
# File 'lib/eac_ruby_utils/patches/module/require_sub.rb', line 6

def require_sub(file_path, options = {})
  ::EacRubyUtils.require_sub(file_path, { base: self }.merge(options))
end