Class: Locomotive::Steam::Middlewares::ThreadSafe

Inherits:
Object
  • Object
show all
Defined in:
lib/locomotive/steam/middlewares/thread_safe.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#envObject

Returns the value of attribute env.



6
7
8
# File 'lib/locomotive/steam/middlewares/thread_safe.rb', line 6

def env
  @env
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/locomotive/steam/middlewares/thread_safe.rb', line 8

def call(env)
  threadsafed = dup
  threadsafed.env = env

  # time = Benchmark.realtime do
  threadsafed._call # thread-safe purpose
  # end

  # puts "[Benchmark][#{self.class.name}] Time elapsed #{time*1000} milliseconds"

  threadsafed.next
end

#decorate_entry(entry) ⇒ Object



76
77
78
79
# File 'lib/locomotive/steam/middlewares/thread_safe.rb', line 76

def decorate_entry(entry)
  return nil if entry.nil?
  Locomotive::Steam::Decorators::I18nDecorator.new(entry, locale, default_locale)
end

#default_liquid_contextObject



81
82
83
84
85
86
87
88
89
# File 'lib/locomotive/steam/middlewares/thread_safe.rb', line 81

def default_liquid_context
  ::Liquid::Context.new({ 'site' => site.to_liquid }, {}, {
    request:        request,
    locale:         locale,
    site:           site,
    services:       services,
    repositories:   services.repositories
  }, true)
end

#default_localeObject



64
65
66
# File 'lib/locomotive/steam/middlewares/thread_safe.rb', line 64

def default_locale
  site.default_locale
end

#liquid_assignsObject



56
57
58
# File 'lib/locomotive/steam/middlewares/thread_safe.rb', line 56

def liquid_assigns
  @liquid_assigns ||= env.fetch('steam.liquid_assigns')
end

#live_editing?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/locomotive/steam/middlewares/thread_safe.rb', line 72

def live_editing?
  !!env['steam.live_editing']
end

#localeObject



52
53
54
# File 'lib/locomotive/steam/middlewares/thread_safe.rb', line 52

def locale
  @locale ||= env.fetch('steam.locale')
end

#localesObject



60
61
62
# File 'lib/locomotive/steam/middlewares/thread_safe.rb', line 60

def locales
  site.locales
end

#nextObject



21
22
23
24
# File 'lib/locomotive/steam/middlewares/thread_safe.rb', line 21

def next
  # avoid to be called twice
  @next_response || (@next_response = app.call(env))
end

#pageObject



44
45
46
# File 'lib/locomotive/steam/middlewares/thread_safe.rb', line 44

def page
  @page ||= env.fetch('steam.page')
end

#paramsObject



68
69
70
# File 'lib/locomotive/steam/middlewares/thread_safe.rb', line 68

def params
  @params ||= self.request.params.with_indifferent_access
end

#pathObject



48
49
50
# File 'lib/locomotive/steam/middlewares/thread_safe.rb', line 48

def path
  @path ||= env.fetch('steam.path')
end

#repositoriesObject



32
33
34
# File 'lib/locomotive/steam/middlewares/thread_safe.rb', line 32

def repositories
  @repositories ||= services.repositories
end

#requestObject



36
37
38
# File 'lib/locomotive/steam/middlewares/thread_safe.rb', line 36

def request
  @request ||= env.fetch('steam.request')
end

#servicesObject

Shortcuts =



28
29
30
# File 'lib/locomotive/steam/middlewares/thread_safe.rb', line 28

def services
  @services ||= env.fetch('steam.services')
end

#siteObject



40
41
42
# File 'lib/locomotive/steam/middlewares/thread_safe.rb', line 40

def site
  @site ||= env.fetch('steam.site')
end