Class: Ecfr::RendererService::Diff

Inherits:
Base show all
Defined in:
lib/ecfr/renderer_service/diff.rb

Defined Under Namespace

Classes: DiffTooLarge, Undiffable

Constant Summary

Constants inherited from Base

Base::HTML_PATH

Constants inherited from Base

Base::SUPPORTED_ARRAY_ACCESSORS

Instance Attribute Summary collapse

Attributes inherited from Base

#metadata, #request_data, #response_status, #results

Class Method Summary collapse

Methods inherited from Base

base_url, service_name, service_path

Methods inherited from Base

basic_auth_client_options, #each, #initialize, metadata, metadata_key, result_key

Methods included from Extensible

#inherited

Methods included from AttributeMethodDefinition

included, #initialize

Methods inherited from Client

build, cache_key, client, client_pool, delete, execute, get, handle_response, perform, post, purge

Methods included from ParallelClient

included

Constructor Details

This class inherits a constructor from Ecfr::Base

Instance Attribute Details

#htmlString (readonly)

HTML document with inline changes

Returns:

  • (String)


7
8
# File 'lib/ecfr/renderer_service/diff.rb', line 7

attribute :html,
desc: "HTML document with inline changes"

Class Method Details

.compare(old_date:, new_date:, hierarchy: {}, options: {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ecfr/renderer_service/diff.rb', line 10

def self.compare(old_date:, new_date:, hierarchy: {}, options: {})
  hierarchy = hierarchy.dup

  complete = hierarchy.delete(:complete)
  options[:skip_ancestry_checks] = 1 if complete

  title = hierarchy.delete(:title)
  view_mode = options.delete(:view_mode) || :enhanced
  params = hierarchy.merge(options).merge(compare: old_date)

  begin
    new(
      {
        html: get(
          content_path(new_date, title, view_mode: view_mode),
          params
        ).body
      }.stringify_keys
    )
  rescue Ecfr::Client::ResponseError, Ecfr::Client::ServerError
    # diff too large - diff service generated broken pipe error or 500 code
    raise DiffTooLarge
  rescue Ecfr::Client::UnknownStatusCode
    raise Undiffable
  end
end