Class: Rack::When::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/when/builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Builder

Returns a new instance of Builder.



5
6
7
# File 'lib/rack/when/builder.rb', line 5

def initialize *args
  *@envs, @block = args
end

Instance Method Details

#has_matching_env?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/rack/when/builder.rb', line 13

def has_matching_env?
  @envs.any? { |env| (ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development') =~ /^#{env.to_s.downcase}/ }
end

#mountObject



9
10
11
# File 'lib/rack/when/builder.rb', line 9

def mount
  @block.call if has_matching_env?
end