Module: Chassis

Defined in:
lib/chassis.rb,
lib/chassis/form.rb,
lib/chassis/repo.rb,
lib/chassis/error.rb,
lib/chassis/logger.rb,
lib/chassis/faraday.rb,
lib/chassis/version.rb,
lib/chassis/delegate.rb,
lib/chassis/registry.rb,
lib/chassis/hash_utils.rb,
lib/chassis/observable.rb,
lib/chassis/array_utils.rb,
lib/chassis/persistence.rb,
lib/chassis/web_service.rb,
lib/chassis/rack/bouncer.rb,
lib/chassis/serializable.rb,
lib/chassis/string_utils.rb,
lib/chassis/circuit_panel.rb,
lib/chassis/dirty_session.rb,
lib/chassis/initializable.rb,
lib/chassis/rack/no_robots.rb,
lib/chassis/repo/base_repo.rb,
lib/chassis/repo/null_repo.rb,
lib/chassis/repo/delegation.rb,
lib/chassis/repo/record_map.rb,
lib/chassis/repo/redis_repo.rb,
lib/chassis/repo/memory_repo.rb,
lib/chassis/repo/pstore_repo.rb,
lib/chassis/rack/health_check.rb,
lib/chassis/rack/instrumentation.rb,
lib/chassis/rack/json_body_parser.rb,
lib/chassis/repo/lazy_association.rb

Defined Under Namespace

Modules: ArrayUtils, HashUtils, Initializable, Observable, Persistence, Rack, Serializable, StringUtils Classes: BaseRepo, CircuitPanel, Delegation, DirtySession, EncodeJson, FormModule, HttpRequestFailedError, Instrumentation, Logger, Logging, MemoryRepo, NullRepo, PStoreRepo, ParseJson, RedisRepo, Registry, Repo, ServerErrorHandler, WebService

Constant Summary collapse

Proxy =
Prox
UnknownFormFieldError =
Chassis.error do |field|
   "#{field} given but not allowed."
end
RecordNotFoundError =
Chassis.error do |klass, id|
  "Could not locate #{klass} with id #{id}"
end
QueryNotImplementedError =
Chassis.error do |selector|
  "Adapter does not support #{selector.class}!"
end
GraphQueryNotImplementedError =
Chassis.error do |selector|
  "Adapter does not know how to graph #{selector.class}!"
end
NoQueryResultError =
Chassis.error do |selector|
  "Query #{selector.class} must return results!"
end
HttpClientError =

4xx errors

Class.new HttpRequestFailedError
HttpBadRequestError =
Class.new HttpClientError
HttpUnauthorizedError =
Class.new HttpClientError
HttpPaymentRequiredError =
Class.new HttpClientError
HttpForbiddenError =
Class.new HttpClientError
HttpNotFoundError =
Class.new HttpClientError
HttpMethodNotAllowedError =
Class.new HttpClientError
HttpNotAcceptableError =
Class.new HttpClientError
HttpProxyAuthenticationRequiredError =
Class.new HttpClientError
HttpRequestTimeoutError =
Class.new HttpClientError
HttpConflictError =
Class.new HttpClientError
HttpGoneError =
Class.new HttpClientError
HttpLengthRequiredError =
Class.new HttpClientError
HttpPreconditionFailedError =
Class.new HttpClientError
HttpRequestEntityTooLargeError =
Class.new HttpClientError
HttpRequestUriTooLongError =
Class.new HttpClientError
HttpUnsupportedMediaTypeError =
Class.new HttpClientError
HttpRequestRangeNotSatisfiableError =
Class.new HttpClientError
HttpExpectationFailedError =
Class.new HttpClientError
HttpUnprocessableEntityError =
Class.new HttpClientError
HttpLockedError =
Class.new HttpClientError
HttpFailedDependencyError =
Class.new HttpClientError
HttpUpgradeRequiredError =
Class.new HttpClientError
HttpServerError =

5xx errors

Class.new HttpRequestFailedError
HttpInternalServerError =
Class.new HttpServerError
HttpNotImplementedError =
Class.new HttpServerError
HttpBadGatewayError =
Class.new HttpServerError
HttpServiceUnavailableError =
Class.new HttpServerError
HttpGatewayTimeoutError =
Class.new HttpServerError
HttpVersionNotSupportedError =
Class.new HttpServerError
HttpInsufficientStorageError =
Class.new HttpServerError
HttpNotExtendedError =
Class.new HttpServerError
HTTP_STATUS_CODE_ERROR_MAP =
{
  400 => HttpBadRequestError,
  401 => HttpUnauthorizedError,
  402 => HttpPaymentRequiredError,
  403 => HttpForbiddenError,
  404 => HttpNotFoundError,
  405 => HttpMethodNotAllowedError,
  406 => HttpNotAcceptableError,
  407 => HttpProxyAuthenticationRequiredError,
  408 => HttpRequestTimeoutError,
  409 => HttpConflictError,
  410 => HttpGoneError,
  411 => HttpLengthRequiredError,
  412 => HttpPreconditionFailedError,
  413 => HttpRequestEntityTooLargeError,
  414 => HttpRequestUriTooLongError,
  415 => HttpUnsupportedMediaTypeError,
  416 => HttpRequestRangeNotSatisfiableError,
  417 => HttpExpectationFailedError,
  422 => HttpUnprocessableEntityError,
  423 => HttpLockedError,
  424 => HttpFailedDependencyError,
  426 => HttpUpgradeRequiredError,

  # 5xx errors
  500 => HttpInternalServerError,
  501 => HttpNotImplementedError,
  502 => HttpBadGatewayError,
  503 => HttpServiceUnavailableError,
  504 => HttpGatewayTimeoutError,
  505 => HttpVersionNotSupportedError,
  507 => HttpInsufficientStorageError,
  510 => HttpNotExtendedError
}
VERSION =
"0.1.0"
DelegationError =
Chassis.error do |method, delegate|
  "Cannot delegate #{method} without #{delegate}"
end
UnregisteredError =
Chassis.error do |key|
  "#{key.inspect} is not registered!"
end
UnknownObjectClassError =
Chassis.error do
  "Rename class to end in Repo or define object_class"
end
HealthCheckError =
Class.new RuntimeError

Class Method Summary collapse

Class Method Details

.circuit_panel(&block) ⇒ Object



18
19
20
# File 'lib/chassis/circuit_panel.rb', line 18

def circuit_panel(&block)
  CircuitPanel.build &block
end

.delegate(*methods) ⇒ Object



25
26
27
# File 'lib/chassis/delegate.rb', line 25

def delegate(*methods)
  Delegation.new *methods
end

.error(*args, &block) ⇒ Object



3
4
5
# File 'lib/chassis/error.rb', line 3

def error(*args, &block)
  Tnt.boom *args, &block
end

.faraday(host, options = {}) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/chassis/faraday.rb', line 210

def faraday(host, options = {})
  namespace = options.delete :namespace
  logger = options.delete(:logger) || Logger.new.tap { |l| l.progname = 'faraday' }

  Faraday.new host, options do |conn|
    conn.request :instrumentation, namespace
    conn.request :encode_json

    conn.response :parse_json
    conn.response :server_error_handler
    conn.response :logging, logger

    yield conn if block_given?
  end
end

.formObject



52
53
54
# File 'lib/chassis/form.rb', line 52

def form
  FormModule.new
end

.repoObject



60
61
62
# File 'lib/chassis/repo.rb', line 60

def repo
  Repo.default
end

.streamObject



30
31
32
# File 'lib/chassis.rb', line 30

def stream
  @stream
end

.stream=(stream) ⇒ Object



34
35
36
# File 'lib/chassis.rb', line 34

def stream=(stream)
  @stream = stream
end