Class: GdsApi::Panopticon::Registerer

Inherits:
Object
  • Object
show all
Defined in:
lib/gds_api/panopticon/registerer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options)
  @logger = options[:logger] || GdsApi::Base.logger
  @owning_app = options[:owning_app]
  @rendering_app = options[:rendering_app]
  @kind = options[:kind] || 'custom-application'
  @panopticon = options[:panopticon]
  @endpoint_url = options[:endpoint_url] || Plek.current.find("panopticon")
  @timeout = options[:timeout] || 10
end

Instance Attribute Details

#kindObject

Returns the value of attribute kind.



6
7
8
# File 'lib/gds_api/panopticon/registerer.rb', line 6

def kind
  @kind
end

#loggerObject

Returns the value of attribute logger.



6
7
8
# File 'lib/gds_api/panopticon/registerer.rb', line 6

def logger
  @logger
end

#owning_appObject

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_appObject

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
# 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
  [:need_id, :section, :indexable_content, :paths, :prefixes].each do |attr_name|
    if record.respond_to? attr_name
      hash[attr_name] = record.send(attr_name)
    end
  end
  hash
end

#register(record) ⇒ Object

record should respond to #slug and #title, or override #record_to_artefact



39
40
41
# File 'lib/gds_api/panopticon/registerer.rb', line 39

def register(record)
  register_artefact(record_to_artefact(record))
end