Sha256: 318670b9c2c008a77296cf0f87c27f3c19da7e514b0bb1ff23cee6343b6775d0

Contents?: true

Size: 1.15 KB

Versions: 16

Compression:

Stored size: 1.15 KB

Contents

module Locomotive::Steam::Middlewares

  class ThreadSafe

    attr_accessor_initialize :app
    attr_accessor :env

    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

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

    #= Shortcuts =

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

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

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

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

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

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

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

    def default_locale
      site.default_locale
    end

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

  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
locomotivecms_steam-1.2.0.beta1 lib/locomotive/steam/middlewares/thread_safe.rb
locomotivecms_steam-1.1.1 lib/locomotive/steam/middlewares/thread_safe.rb
locomotivecms_steam-1.1.0 lib/locomotive/steam/middlewares/thread_safe.rb
locomotivecms_steam-1.1.0.rc3 lib/locomotive/steam/middlewares/thread_safe.rb
locomotivecms_steam-1.1.0.rc2 lib/locomotive/steam/middlewares/thread_safe.rb
locomotivecms_steam-1.1.0.rc1 lib/locomotive/steam/middlewares/thread_safe.rb
locomotivecms_steam-1.0.1 lib/locomotive/steam/middlewares/thread_safe.rb
locomotivecms_steam-1.0.0 lib/locomotive/steam/middlewares/thread_safe.rb
locomotivecms_steam-1.0.0.rc10 lib/locomotive/steam/middlewares/thread_safe.rb
locomotivecms_steam-1.0.0.rc9 lib/locomotive/steam/middlewares/thread_safe.rb
locomotivecms_steam-1.0.0.rc8 lib/locomotive/steam/middlewares/thread_safe.rb
locomotivecms_steam-1.0.0.rc6 lib/locomotive/steam/middlewares/thread_safe.rb
locomotivecms_steam-1.0.0.rc4 lib/locomotive/steam/middlewares/thread_safe.rb
locomotivecms_steam-1.0.0.rc3 lib/locomotive/steam/middlewares/thread_safe.rb
locomotivecms_steam-1.0.0.rc2 lib/locomotive/steam/middlewares/thread_safe.rb
locomotivecms_steam-1.0.0.rc1 lib/locomotive/steam/middlewares/thread_safe.rb