Module: Service

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::API, ActiveModel::Attributes, Memery, Initializer
Included in:
Bom::XmlFromZone, HeatingSystemCalculator::BaseCalculator
Defined in:
app/concerns/service.rb

Defined Under Namespace

Modules: Initializer Classes: Result

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Initializer

#initialize

Class Method Details

.call(*args) ⇒ Object



16
17
18
# File 'app/concerns/service.rb', line 16

def call(*args)
  new(*args).call
end

Instance Method Details

#attributes_usedObject



59
60
61
# File 'app/concerns/service.rb', line 59

def attributes_used
  attributes.transform_keys(&:to_sym).except(:logger)
end

#build_result(output, last_modified: nil, etag: nil, cache_key: nil) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/concerns/service.rb', line 63

def build_result(output, last_modified: nil, etag: nil, cache_key: nil)
  if etag.nil?
    cache_key ||= output.cache_key if output.respond_to?(:cache_key)
    etag = Digest::MD5.hexdigest(cache_key) if cache_key
    etag ||= Digest::MD5.hexdigest(attributes_used.to_s)
  end
  if last_modified.nil?
    last_modified = output.try(:updated_at)
    last_modified ||= begin
      output.try(:[], :updated_at)
    rescue StandardError
      nil
    end
    last_modified = output.try(:created_at)
    last_modified ||= begin
      output.try(:[], :created_at)
    rescue StandardError
      nil
    end
    last_modified ||= Time.current
  end
  Result.new(output:, params: attributes_used, last_modified:, etag:)
end

#loggerObject



55
56
57
# File 'app/concerns/service.rb', line 55

def logger
  @logger ||= Rails.logger
end