Module: Parliament::Grom::Decorator
- Defined in:
- lib/parliament/grom/decorator.rb,
lib/parliament/grom/decorator/group.rb,
lib/parliament/grom/decorator/house.rb,
lib/parliament/grom/decorator/laying.rb,
lib/parliament/grom/decorator/person.rb,
lib/parliament/grom/decorator/helpers.rb,
lib/parliament/grom/decorator/version.rb,
lib/parliament/grom/decorator/procedure.rb,
lib/parliament/grom/decorator/laid_thing.rb,
lib/parliament/grom/decorator/laying_body.rb,
lib/parliament/grom/decorator/work_package.rb,
lib/parliament/grom/decorator/business_item.rb,
lib/parliament/grom/decorator/helpers/utils.rb,
lib/parliament/grom/decorator/procedure_step.rb,
lib/parliament/grom/decorator/helpers/date_helper.rb,
lib/parliament/grom/decorator/work_packaged_thing.rb,
lib/parliament/grom/decorator/statutory_instrument_paper.rb,
lib/parliament/grom/decorator/proposed_negative_statutory_instrument_paper.rb
Overview
Namespace for Grom decorators.
Defined Under Namespace
Modules: BusinessItem, Group, Helpers, House, LaidThing, Laying, LayingBody, Person, Procedure, ProcedureStep, ProposedNegativeStatutoryInstrumentPaper, StatutoryInstrumentPaper, WorkPackage, WorkPackagedThing
Constant Summary collapse
- MAPPING =
mapping_hash.freeze
- VERSION =
'1.0.5'.freeze
Class Method Summary collapse
-
.decorate(object) ⇒ Grom::Node
Decorates objects with alias methods extended from decorator modules.
-
.decorate_with_type(object, type) ⇒ Grom::Node
Decorates objects with alias methods extended from a decorator module.
-
.gem_path ⇒ Object
Gets the root directory of the gem.
- .load! ⇒ Object
Class Method Details
.decorate(object) ⇒ Grom::Node
Decorates objects with alias methods extended from decorator modules. This method reads each of the ‘#type` values and extends the object with a decorator for that type, if available.
41 42 43 44 45 46 47 48 49 |
# File 'lib/parliament/grom/decorator.rb', line 41 def decorate(object) return object unless object.respond_to?(:type) Array(object.type).each do |type| object = decorate_with_type(object, type) end object end |
.decorate_with_type(object, type) ⇒ Grom::Node
Decorates objects with alias methods extended from a decorator module. This method decorated an object with a module matching the type provided.
57 58 59 60 61 62 |
# File 'lib/parliament/grom/decorator.rb', line 57 def decorate_with_type(object, type) decorator = MAPPING[::Grom::Helper.get_id(type)] # Get the decorator for a type, or nil object.extend(decorator) unless decorator.nil? object end |
.gem_path ⇒ Object
Gets the root directory of the gem
25 26 27 |
# File 'lib/parliament/grom/decorator.rb', line 25 def gem_path File. '../../..', __dir__ end |
.load! ⇒ Object
29 30 31 32 33 |
# File 'lib/parliament/grom/decorator.rb', line 29 def load! # Loads the translation file into the I18n gem I18n.load_path += Dir[File.join(gem_path, 'config', 'locales', '*.yml')] I18n.backend.load_translations end |