Module: Fixtury
- Defined in:
- lib/fixtury.rb,
lib/fixtury/hooks.rb,
lib/fixtury/store.rb,
lib/fixtury/errors.rb,
lib/fixtury/schema.rb,
lib/fixtury/locator.rb,
lib/fixtury/railtie.rb,
lib/fixtury/version.rb,
lib/fixtury/reference.rb,
lib/fixtury/definition.rb,
lib/fixtury/dependency.rb,
lib/fixtury/schema_node.rb,
lib/fixtury/configuration.rb,
lib/fixtury/path_resolver.rb,
lib/fixtury/minitest_hooks.rb,
lib/fixtury/dependency_store.rb,
lib/fixtury/mutation_observer.rb,
lib/fixtury/definition_executor.rb,
lib/fixtury/locator_backend/common.rb,
lib/fixtury/locator_backend/memory.rb,
lib/fixtury/locator_backend/global_id.rb
Overview
Top level namespace of the gem. The accessors provided on the Fixtury namespace are meant to be shared across the entire application. The Fixtury::Schema instance is the primary interface for defining and accessing fixtures and can be accessed via Fixtury.schema.
Defined Under Namespace
Modules: Errors, LocatorBackend, MinitestHooks, MutationObserver, SchemaNode Classes: Configuration, Definition, DefinitionExecutor, Dependency, DependencyStore, Hooks, Locator, PathResolver, Railtie, Reference, Schema, Store
Constant Summary collapse
- LOG_LEVELS =
{ (LOG_LEVEL_NONE = :none) => 0, (LOG_LEVEL_INFO = :info) => 1, (LOG_LEVEL_DEBUG = :debug) => 2, (LOG_LEVEL_ALL = :all) => 3, }.freeze
- DEFAULT_LOG_LEVEL =
LOG_LEVEL_INFO
- VERSION =
"1.0.0"
Class Method Summary collapse
- .configuration {|@configuration| ... } ⇒ Object
- .configure(&block) ⇒ Object
-
.define(&block) ⇒ Object
Shortcut for opening the top level schema.
-
.hooks ⇒ Object
Global hooks accessor.
-
.load_all_fixtures ⇒ Object
Ensure all definitions are loaded and then load all known fixtures.
-
.load_all_schemas(mechanism = :require) ⇒ Object
Require each schema file to ensure that all definitions are loaded.
- .log(text = nil, level: LOG_LEVEL_DEBUG, name: nil, newline: true) ⇒ Object
-
.reset ⇒ Object
Remove all references from the active store and reset the dependency file.
-
.reset_if_changed ⇒ Object
Perform a reset if any of the tracked files have changed.
-
.schema ⇒ Object
The default top level schema.
-
.start ⇒ Object
Load all known fixture files configured in Configuration.
-
.store ⇒ Object
Default store for fixtures.
Class Method Details
.configuration {|@configuration| ... } ⇒ Object
42 43 44 45 46 |
# File 'lib/fixtury.rb', line 42 def self.configuration @configuration ||= ::Fixtury::Configuration.new yield @configuration if block_given? @configuration end |
.configure(&block) ⇒ Object
48 49 50 |
# File 'lib/fixtury.rb', line 48 def self.configure(&block) self.configuration(&block) end |
.define(&block) ⇒ Object
Shortcut for opening the top level schema.
54 55 56 57 |
# File 'lib/fixtury.rb', line 54 def self.define(&block) schema.define(&block) schema end |
.hooks ⇒ Object
Global hooks accessor. Fixtury will call these hooks at various points in the lifecycle of a fixture or setup.
60 61 62 |
# File 'lib/fixtury.rb', line 60 def self.hooks @hooks ||= ::Fixtury::Hooks.new end |
.load_all_fixtures ⇒ Object
Ensure all definitions are loaded and then load all known fixtures.
96 97 98 99 |
# File 'lib/fixtury.rb', line 96 def self.load_all_fixtures(...) load_all_schemas(...) store.load_all end |
.load_all_schemas(mechanism = :require) ⇒ Object
Require each schema file to ensure that all definitions are loaded.
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/fixtury.rb', line 83 def self.load_all_schemas(mechanism = :require) configuration.fixture_files.each do |filepath| if mechanism == :require require filepath elsif mechanism == :load load filepath else raise ArgumentError, "unknown load mechanism: #{mechanism}" end end end |
.log(text = nil, level: LOG_LEVEL_DEBUG, name: nil, newline: true) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/fixtury.rb', line 118 def self.log(text = nil, level: LOG_LEVEL_DEBUG, name: nil, newline: true) desired_level = LOG_LEVELS.fetch(configuration.log_level) { DEFAULT_LOG_LEVEL } return if desired_level == LOG_LEVEL_NONE = LOG_LEVELS.fetch(level) { LOG_LEVEL_DEBUG } return unless desired_level >= msg = +"[fixtury" msg << "|#{name}" if name msg << "]" msg << " #{text}" if text msg << " #{yield}" if block_given? msg << "\n" if newline # TODO: logger print msg msg end |
.reset ⇒ Object
Remove all references from the active store and reset the dependency file.
102 103 104 105 |
# File 'lib/fixtury.rb', line 102 def self.reset configuration.reset store.reset end |
.reset_if_changed ⇒ Object
Perform a reset if any of the tracked files have changed.
108 109 110 111 112 113 114 115 116 |
# File 'lib/fixtury.rb', line 108 def self.reset_if_changed changes = configuration.changes if changes log("changes found, resetting | #{changes}", level: LOG_LEVEL_INFO) reset else log("no changes, skipping reset", level: LOG_LEVEL_INFO) end end |
.schema ⇒ Object
The default top level schema. Fixtury::Schema instances can be completely self-contained but most usage would be through this shared definition.
66 67 68 |
# File 'lib/fixtury.rb', line 66 def self.schema @schema ||= ::Fixtury::Schema.new end |
.start ⇒ Object
Load all known fixture files configured in Configuration. Reset the store references if a dependency file has changed.
77 78 79 80 |
# File 'lib/fixtury.rb', line 77 def self.start load_all_schemas reset_if_changed end |