Module: Otto::ClassMethods

Included in:
Otto
Defined in:
lib/otto.rb

Overview

Class methods for Otto framework providing singleton access and configuration

Instance Method Summary collapse

Instance Method Details

#defaultObject



245
246
247
248
# File 'lib/otto.rb', line 245

def default
  @default ||= Otto.new
  @default
end

#env?(*guesses) ⇒ Boolean

Returns:

  • (Boolean)


262
263
264
# File 'lib/otto.rb', line 262

def env? *guesses
  guesses.flatten.any? { |n| ENV['RACK_ENV'].to_s == n.to_s }
end

#load(path) ⇒ Object



250
251
252
# File 'lib/otto.rb', line 250

def load(path)
  default.load path
end

#path(definition, params = {}) ⇒ Object



254
255
256
# File 'lib/otto.rb', line 254

def path(definition, params = {})
  default.path definition, params
end

#routesObject



258
259
260
# File 'lib/otto.rb', line 258

def routes
  default.routes
end

#unfreeze_for_testing(otto) ⇒ Otto

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Test-only method to unfreeze Otto configuration

This method resets the @configuration_frozen flag, allowing tests to bypass the ensure_not_frozen! check. It does NOT actually unfreeze Ruby objects (which is impossible once frozen).

IMPORTANT: Only works when RSpec is defined. Raises an error otherwise to prevent accidental use in production.

Parameters:

  • otto (Otto)

    The Otto instance to unfreeze

Returns:

  • (Otto)

    The unfrozen Otto instance

Raises:

  • (RuntimeError)

    if RSpec is not defined (not in test environment)



279
280
281
282
283
284
# File 'lib/otto.rb', line 279

def unfreeze_for_testing(otto)
  raise 'Otto.unfreeze_for_testing is only available in RSpec test environment' unless defined?(RSpec)

  otto.instance_variable_set(:@configuration_frozen, false)
  otto
end