Class: GdsApi::Panopticon::Registerer
- Inherits:
-
Object
- Object
- GdsApi::Panopticon::Registerer
- Defined in:
- lib/gds_api/panopticon/registerer.rb
Instance Attribute Summary collapse
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#owning_app ⇒ Object
Returns the value of attribute owning_app.
-
#rendering_app ⇒ Object
Returns the value of attribute rendering_app.
Instance Method Summary collapse
-
#initialize(options) ⇒ Registerer
constructor
A new instance of Registerer.
- #record_to_artefact(record) ⇒ Object
-
#register(record) ⇒ Object
record should respond to #slug and #title, or override #record_to_artefact.
Constructor Details
#initialize(options) ⇒ Registerer
Returns a new instance of Registerer.
8 9 10 11 12 13 14 15 16 |
# File 'lib/gds_api/panopticon/registerer.rb', line 8 def initialize() @logger = [:logger] || GdsApi::Base.logger @owning_app = [:owning_app] @rendering_app = [:rendering_app] @kind = [:kind] || 'custom-application' @panopticon = [:panopticon] @endpoint_url = [:endpoint_url] || Plek.current.find("panopticon") @timeout = [:timeout] || 10 end |
Instance Attribute Details
#kind ⇒ Object
Returns the value of attribute kind.
6 7 8 |
# File 'lib/gds_api/panopticon/registerer.rb', line 6 def kind @kind end |
#logger ⇒ Object
Returns the value of attribute logger.
6 7 8 |
# File 'lib/gds_api/panopticon/registerer.rb', line 6 def logger @logger end |
#owning_app ⇒ Object
Returns the value of attribute owning_app.
6 7 8 |
# File 'lib/gds_api/panopticon/registerer.rb', line 6 def owning_app @owning_app end |
#rendering_app ⇒ Object
Returns the value of attribute rendering_app.
6 7 8 |
# File 'lib/gds_api/panopticon/registerer.rb', line 6 def rendering_app @rendering_app end |
Instance Method Details
#record_to_artefact(record) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/gds_api/panopticon/registerer.rb', line 18 def record_to_artefact(record) hash = { slug: record.slug, owning_app: owning_app, kind: kind, name: record.title, description: record.description, state: record.state } if rendering_app hash[:rendering_app] = rendering_app end optional_params = [ :need_id, :need_ids, :section, :primary_section, :sections, :paths, :prefixes, :specialist_sectors, :organisation_ids, :indexable_content, :public_timestamp, :latest_change_note, :content_id, ] deprecated_params = { section: [:primary_section, :sections] } deprecated_params.each do |attr_name, replacements| if record.respond_to?(attr_name) replacements = Array(replacements) logger.warn "#{attr_name} has been deprecated in favour of #{replacements.join(' and ')}" end end optional_params.each do |attr_name| if record.respond_to? attr_name hash[attr_name] = record.public_send(attr_name) end end hash end |
#register(record) ⇒ Object
record should respond to #slug and #title, or override #record_to_artefact
73 74 75 |
# File 'lib/gds_api/panopticon/registerer.rb', line 73 def register(record) register_artefact(record_to_artefact(record)) end |