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
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
# 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,
  ]

  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



71
72
73
# File 'lib/gds_api/panopticon/registerer.rb', line 71

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