Module: Briefly
- Defined in:
- lib/briefly.rb,
lib/briefly/rails.rb,
lib/briefly/errors.rb,
lib/briefly/facade.rb,
lib/briefly/builder.rb,
lib/briefly/version.rb,
lib/briefly/rails/db.rb,
lib/briefly/definition.rb,
lib/briefly/rails/reload.rb,
lib/briefly/error_registry.rb
Overview
Defined Under Namespace
Modules: Rails Classes: Builder, Definition, Error, ErrorRegistry, Facade, ReservedNameError, UnknownPackError, UnknownShortcutError
Constant Summary collapse
- UNSET =
Sentinel distinguishing "not memoized yet" from a memoized
nil. Object.new.freeze
- VERSION =
The gem version.
"0.1.0"
Class Attribute Summary collapse
-
.errors ⇒ Briefly::ErrorRegistry
readonly
The global registry.
Class Method Summary collapse
-
.define { ... } ⇒ Briefly::Facade
Builds a facade.
-
.pack(name) ⇒ #install
Resolves a short name to a pack.
-
.register(name, pack) ⇒ self
Registers a pack under a short name, so
use "myapp/redis"resolves it. -
.rescue_from(error_class) {|error, shortcut_name| ... } ⇒ self
Registers a handler that applies to every shortcut on every facade, consulted only after the facade's own handlers.
Class Attribute Details
.errors ⇒ Briefly::ErrorRegistry (readonly)
Returns the global registry.
92 93 94 |
# File 'lib/briefly.rb', line 92 def errors @errors end |
Class Method Details
.define { ... } ⇒ Briefly::Facade
Builds a facade. The block is +instance_eval+'d on a Builder.
39 |
# File 'lib/briefly.rb', line 39 def define(&) = Facade.new.configure(&) |
.pack(name) ⇒ #install
Resolves a short name to a pack. A registered constant path is resolved here, not at registration, so a pack's file loads only when something uses it.
The path is walked one segment at a time rather than handed to Object.const_get whole, so a
NameError raised inside a pack's file as it autoloads propagates untouched. Rescuing around
the whole resolution would launder that bug into an UnknownPackError.
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/briefly.rb', line 62 def pack(name) entry = @packs.fetch(name.to_s) { raise UnknownPackError, "unknown pack: #{name.inspect}" } return entry unless entry.is_a?(String) entry.split("::").reduce(Object) do |mod, segment| unless mod.const_defined?(segment, false) raise UnknownPackError, "pack #{name.inspect} names #{entry.inspect}, which does not resolve" end mod.const_get(segment, false) end end |
.register(name, pack) ⇒ self
Registers a pack under a short name, so use "myapp/redis" resolves it. Re-registering a name
overrides it. There is no inflection and no path guessing: this table is the only source of truth.
47 48 49 50 |
# File 'lib/briefly.rb', line 47 def register(name, pack) @packs[name.to_s] = pack self end |
.rescue_from(error_class) {|error, shortcut_name| ... } ⇒ self
Registers a handler that applies to every shortcut on every facade, consulted only after the facade's own handlers. Takes no shortcut names.
81 82 83 84 85 86 87 88 89 |
# File 'lib/briefly.rb', line 81 def rescue_from(error_class, &handler) unless error_class.is_a?(Class) raise ArgumentError, "rescue_from expects the error class first, got #{error_class.inspect}" end raise ArgumentError, "rescue_from(#{error_class}) requires a block" unless handler @errors.add(error_class, nil, handler) self end |