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/party.rb,
lib/parliament/grom/decorator/answer.rb,
lib/parliament/grom/decorator/gender.rb,
lib/parliament/grom/decorator/laying.rb,
lib/parliament/grom/decorator/person.rb,
lib/parliament/grom/decorator/treaty.rb,
lib/parliament/grom/decorator/concept.rb,
lib/parliament/grom/decorator/helpers.rb,
lib/parliament/grom/decorator/version.rb,
lib/parliament/grom/decorator/audience.rb,
lib/parliament/grom/decorator/position.rb,
lib/parliament/grom/decorator/question.rb,
lib/parliament/grom/decorator/procedure.rb,
lib/parliament/grom/decorator/collection.rb,
lib/parliament/grom/decorator/house_seat.rb,
lib/parliament/grom/decorator/incumbency.rb,
lib/parliament/grom/decorator/laid_thing.rb,
lib/parliament/grom/decorator/formal_body.rb,
lib/parliament/grom/decorator/laying_body.rb,
lib/parliament/grom/decorator/parliaments.rb,
lib/parliament/grom/decorator/web_article.rb,
lib/parliament/grom/decorator/article_type.rb,
lib/parliament/grom/decorator/member_image.rb,
lib/parliament/grom/decorator/work_package.rb,
lib/parliament/grom/decorator/business_item.rb,
lib/parliament/grom/decorator/contact_point.rb,
lib/parliament/grom/decorator/answering_body.rb,
lib/parliament/grom/decorator/postal_address.rb,
lib/parliament/grom/decorator/procedure_step.rb,
lib/parliament/grom/decorator/european_region.rb,
lib/parliament/grom/decorator/gender_identity.rb,
lib/parliament/grom/decorator/procedure_route.rb,
lib/parliament/grom/decorator/seat_incumbency.rb,
lib/parliament/grom/decorator/formal_body_type.rb,
lib/parliament/grom/decorator/party_membership.rb,
lib/parliament/grom/decorator/constituency_area.rb,
lib/parliament/grom/decorator/formal_body_chair.rb,
lib/parliament/grom/decorator/constituency_group.rb,
lib/parliament/grom/decorator/government_position.rb,
lib/parliament/grom/decorator/helpers/date_helper.rb,
lib/parliament/grom/decorator/opposition_position.rb,
lib/parliament/grom/decorator/work_packaged_thing.rb,
lib/parliament/grom/decorator/government_incumbency.rb,
lib/parliament/grom/decorator/opposition_incumbency.rb,
lib/parliament/grom/decorator/formal_body_membership.rb,
lib/parliament/grom/decorator/work_packageable_thing.rb,
lib/parliament/grom/decorator/parliamentary_incumbency.rb,
lib/parliament/grom/decorator/answering_body_allocation.rb,
lib/parliament/grom/decorator/statutory_instrument_paper.rb,
lib/parliament/grom/decorator/gov_register_government_organisation.rb,
lib/parliament/grom/decorator/proposed_negative_statutory_instrument_paper.rb
Overview
Namespace for Grom decorators.
Defined Under Namespace
Modules: Answer, AnsweringBody, AnsweringBodyAllocation, ArticleType, Audience, BusinessItem, Collection, Concept, ConstituencyArea, ConstituencyGroup, ContactPoint, EuropeanRegion, FormalBody, FormalBodyChair, FormalBodyMembership, FormalBodyType, Gender, GenderIdentity, GovRegisterGovernmentOrganisation, GovernmentIncumbency, GovernmentPosition, Group, Helpers, House, HouseSeat, Incumbency, LaidThing, Laying, LayingBody, MemberImage, OppositionIncumbency, OppositionPosition, ParliamentPeriod, ParliamentaryIncumbency, Party, PartyMembership, Person, Position, PostalAddress, Procedure, ProcedureRoute, ProcedureStep, ProposedNegativeStatutoryInstrumentPaper, Question, SeatIncumbency, StatutoryInstrumentPaper, Treaty, WebArticle, WorkPackage, WorkPackageableThing, WorkPackagedThing
Constant Summary collapse
- MAPPING =
mapping_hash.freeze
- VERSION =
'0.32.1'.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 |