Module: Trane

Defined in:
lib/trane.rb,
lib/trane.rb,
lib/trane/types.rb,
lib/trane/engine.rb,
lib/trane/testing.rb,
lib/trane/version.rb,
lib/trane/docs/app.rb,
lib/trane/registry.rb,
lib/trane/controller.rb,
lib/trane/docs/cache.rb,
lib/trane/field_node.rb,
lib/trane/serializer.rb,
lib/trane/configuration.rb,
lib/trane/field_builder.rb,
lib/trane/boot_validator.rb,
lib/trane/error_registry.rb,
lib/trane/contract_loader.rb,
lib/trane/route_validator.rb,
lib/trane/param_definition.rb,
lib/trane/routing_extension.rb,
lib/trane/contract_validator.rb,
lib/trane/docs/html_renderer.rb,
lib/trane/controller/renderer.rb,
lib/trane/operation_definition.rb,
lib/trane/docs/service_definition.rb,
lib/trane/extra_attributes_filter.rb,
lib/trane/controller/error_handler.rb,
lib/trane/representation_definition.rb

Defined Under Namespace

Modules: ContractLoader, Controller, Docs, ExtraAttributesFilter, Registry, RoutingExtension, Testing, Types Classes: BodyBuilder, BootValidator, Configuration, ContractValidator, ContractViolation, Engine, Error, ErrorDefinition, ErrorKeysBuilder, ErrorsBuilder, FieldBuilder, FieldNode, OperationBuilder, OperationDefinition, ParamDefinition, RepresentationBuilder, RepresentationDefinition, RequestBuilder, RequestDefinition, ResponseBuilder, ResponseDefinition, RouteValidator, RoutingContractError, Serializer

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.configurationObject

Returns the process-level Configuration.



46
47
48
# File 'lib/trane.rb', line 46

def self.configuration
  @configuration
end

.configure {|configuration| ... } ⇒ Object

Yields:



41
42
43
# File 'lib/trane.rb', line 41

def self.configure
  yield configuration
end

.errors(&block) ⇒ Object



78
79
80
81
82
# File 'lib/trane.rb', line 78

def self.errors(&block)
  builder = ErrorsBuilder.new
  builder.instance_eval(&block)
  builder.definitions.each { |d| registry.register_error(d) }
end

.log_warning(message) ⇒ Object

Logs a warning through Rails.logger when available, falling back to Kernel#warn (stderr) outside Rails. Single home for the guard chain so every warn-level message in the gem routes identically.



87
88
89
90
91
92
93
# File 'lib/trane.rb', line 87

def self.log_warning(message)
  if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger
    Rails.logger.warn(message)
  else
    warn(message)
  end
end

.operation(name, &block) ⇒ Object



66
67
68
69
70
# File 'lib/trane.rb', line 66

def self.operation(name, &block)
  builder = OperationBuilder.new(name)
  builder.instance_eval(&block)
  registry.register_operation(builder.build)
end

.registryObject

Returns the process-level Registry::Instance.



51
52
53
# File 'lib/trane.rb', line 51

def self.registry
  @registry
end

.representation(name, &block) ⇒ Object



72
73
74
75
76
# File 'lib/trane.rb', line 72

def self.representation(name, &block)
  builder = RepresentationBuilder.new(name)
  builder.instance_eval(&block)
  registry.register_representation(builder.build)
end

.reset!Object

Restores Trane to a pristine state: empties the registry (snapshot and derived caches), clears the configuration (values and frozen flag), and invalidates the docs cache. Intended for test suites that need isolation between examples or that boot throwaway Rails applications.



59
60
61
62
63
64
# File 'lib/trane.rb', line 59

def self.reset!
  registry.reset!
  configuration.reset!
  Docs::Cache.invalidate!
  nil
end

.spelling_suggestion(term, candidates) ⇒ Object

Returns the closest spelling match for term among candidates, or nil when no candidate is close enough. Backs the "Did you mean?" hints in both the routing contract: hash validator and the route/registry cross-check, so the two validations never drift on suggestion logic.



99
100
101
102
# File 'lib/trane.rb', line 99

def self.spelling_suggestion(term, candidates)
  require "did_you_mean"
  DidYouMean::SpellChecker.new(dictionary: candidates.map(&:to_s)).correct(term.to_s).first
end