Class: Fixtury::Schema
- Inherits:
-
Object
- Object
- Fixtury::Schema
- Includes:
- SchemaNode
- Defined in:
- lib/fixtury/schema.rb
Overview
A Fixtury::SchemaNode implementation that represents a top-level schema or a namespace within a schema.
Constant Summary
Constants included from SchemaNode
Fixtury::SchemaNode::VALID_NODE_NAME
Instance Method Summary collapse
-
#acts_like_fixtury_schema? ⇒ Boolean
Object#acts_like? adherence.
-
#define(&block) ⇒ Fixtury::Schema
Open up self for child definitions.
-
#fixture(relative_name, **options, &block) ⇒ Fixtury::Definition
Create a fixture definition at the given relative name.
-
#initialize(name: "", **options) ⇒ Schema
constructor
a new top-level schema.
-
#namespace(relative_name, **options, &block) ⇒ Fixtury::Schema
Create a child schema at the given relative name.
- #reset ⇒ Object
-
#schema_node_type ⇒ String
Returns “schema” if top-level, otherwise returns “namespace”.
Methods included from SchemaNode
#acts_like_fixtury_schema_node?, #add_child, #apply_options!, #first_ancestor?, #get, #get!, #inspect, #isolation_key, #structure
Constructor Details
#initialize(name: "", **options) ⇒ Schema
a new top-level schema.
12 13 14 |
# File 'lib/fixtury/schema.rb', line 12 def initialize(name: "", **) super(name: name, **) end |
Instance Method Details
#acts_like_fixtury_schema? ⇒ Boolean
Object#acts_like? adherence.
21 22 23 |
# File 'lib/fixtury/schema.rb', line 21 def acts_like_fixtury_schema? true end |
#define(&block) ⇒ Fixtury::Schema
Open up self for child definitions.
28 29 30 31 |
# File 'lib/fixtury/schema.rb', line 28 def define(&block) instance_eval(&block) self end |
#fixture(relative_name, **options, &block) ⇒ Fixtury::Definition
Create a fixture definition at the given relative name. If the name is already used, a Fixtury::Errors::AlreadyDefinedError will be raised.
68 69 70 71 72 73 74 75 |
# File 'lib/fixtury/schema.rb', line 68 def fixture(relative_name, **, &block) ::Fixtury::Definition.new( name: relative_name, parent: self, **, &block ) end |
#namespace(relative_name, **options, &block) ⇒ Fixtury::Schema
Create a child schema at the given relative name. If a child by the name already exists it will be reopened as long as it’s a fixtury schema.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fixtury/schema.rb', line 47 def namespace(relative_name, **, &block) child = get("./#{relative_name}") if child && !child.acts_like?(:fixtury_schema) raise Errors::AlreadyDefinedError, child.pathname end child ||= self.class.new(name: relative_name, parent: self) child.() child.instance_eval(&block) if block_given? child end |
#reset ⇒ Object
16 17 18 |
# File 'lib/fixtury/schema.rb', line 16 def reset children.clear end |
#schema_node_type ⇒ String
Returns “schema” if top-level, otherwise returns “namespace”.
35 36 37 |
# File 'lib/fixtury/schema.rb', line 35 def schema_node_type first_ancestor? ? "schema" : "namespace" end |