Class: Ettu

Inherits:
Object
  • Object
show all
Defined in:
lib/ettu.rb,
lib/ettu/railtie.rb,
lib/ettu/version.rb,
lib/ettu/fresh_when.rb,
lib/ettu/configuration.rb

Defined Under Namespace

Modules: FreshWhen Classes: Configuration, Railtie

Constant Summary collapse

VERSION =
'4.2.0'
@@config =
Configuration.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record_or_options = nil, additional_options = {}, controller = nil) ⇒ Ettu

Returns a new instance of Ettu.



23
24
25
26
27
28
29
30
# File 'lib/ettu.rb', line 23

def initialize(record_or_options = nil, additional_options = {}, controller = nil)
  @controller, @asset_etags = controller, {}
  if record_or_options.is_a? Hash
    @record, @options = nil, record_or_options
  else
    @record, @options = record_or_options, additional_options
  end
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/ettu.rb', line 13

def options
  @options
end

Class Method Details

.configure {|@@config| ... } ⇒ Object

Yields:

  • (@@config)


18
19
20
# File 'lib/ettu.rb', line 18

def configure
  yield @@config
end

Instance Method Details

#asset_etagsObject



53
54
55
56
# File 'lib/ettu.rb', line 53

def asset_etags
  assets = @options.fetch(:assets, @@config.assets)
  [*assets].map { |asset| asset_etag(asset) }
end

#etagsObject



32
33
34
35
36
37
# File 'lib/ettu.rb', line 32

def etags
  etags = [*response_etag]
  etags << view_etag
  etags.concat asset_etags
  etags.compact
end

#last_modifiedObject



39
40
41
# File 'lib/ettu.rb', line 39

def last_modified
  @options.fetch(:last_modified, @record.try(:updated_at))
end

#response_etagObject



43
44
45
# File 'lib/ettu.rb', line 43

def response_etag
  @options.fetch(:etag, @record)
end

#view_etagObject



47
48
49
50
51
# File 'lib/ettu.rb', line 47

def view_etag
  default_view = @@config.fetch(:view, "#{@controller.controller_name}/#{@controller.action_name}")
  view = @options.fetch(:view, default_view)
  @view_etag ||= view_digest(view)
end