Sha256: b6e6bd66e9cc66919d1db783936e120635576e72f53825867095215d2a592b0f

Contents?: true

Size: 1.15 KB

Versions: 27

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true
class Rack::App::Router::Tree::Leaf < ::Hash

  require 'rack/app/router/tree/leaf/mounted'

  E = Rack::App::Constants::ENV

  def set(env)
    case env.type
    when :APPLICATION
      self[env.type] = Rack::App::Router::Tree::Leaf::Mounted::Application.new(env.endpoint)
    when :MOUNT_POINT
      self[env.type] = Rack::App::Router::Tree::Leaf::Mounted.new(env.endpoint)
    else
      save_endpoint(env)
    end
  end

  def call_endpoint(env, current_path)
    app = self[current_path] || self[:ANY]
    (app && app.call(env)) || call_mount(env)
  end

  def call_mount(env)
    app = self[:MOUNT_POINT] || self[:APPLICATION]
    app && app.call(env)
  end

  protected

  def save_endpoint(env)
    if env.save_key.is_a?(Symbol)
      vein_for(env.save_key).set(env)
    else
      split_save_to_extnames(env)
    end
  end

  def split_save_to_extnames(env)
    save_key = env.save_key
    env.endpoint.config.serializer.extnames.each do |extname|
      vein_for(save_key + extname).set(env)
    end
    vein_for(save_key).set(env)
  end

  def vein_for(path_part)
    self[path_part] ||= Rack::App::Router::Tree::Vein.new
  end


end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
rack-app-7.5.1 lib/rack/app/router/tree/leaf.rb
rack-app-7.5.0 lib/rack/app/router/tree/leaf.rb
rack-app-7.4.0 lib/rack/app/router/tree/leaf.rb
rack-app-7.3.2 lib/rack/app/router/tree/leaf.rb
rack-app-7.3.1 lib/rack/app/router/tree/leaf.rb
rack-app-7.3.0 lib/rack/app/router/tree/leaf.rb
rack-app-7.2.2 lib/rack/app/router/tree/leaf.rb
rack-app-7.2.1 lib/rack/app/router/tree/leaf.rb
rack-app-7.2.0 lib/rack/app/router/tree/leaf.rb
rack-app-7.1.0 lib/rack/app/router/tree/leaf.rb
rack-app-7.0.0 lib/rack/app/router/tree/leaf.rb
rack-app-6.8.0 lib/rack/app/router/tree/leaf.rb
rack-app-6.7.1 lib/rack/app/router/tree/leaf.rb
rack-app-6.7.0 lib/rack/app/router/tree/leaf.rb
rack-app-6.6.0 lib/rack/app/router/tree/leaf.rb
rack-app-6.5.0 lib/rack/app/router/tree/leaf.rb
rack-app-6.4.1 lib/rack/app/router/tree/leaf.rb
rack-app-6.4.0 lib/rack/app/router/tree/leaf.rb
rack-app-6.3.3 lib/rack/app/router/tree/leaf.rb
rack-app-6.3.2 lib/rack/app/router/tree/leaf.rb