Class: Fixtury::Definition

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
SchemaNode
Defined in:
lib/fixtury/definition.rb

Overview

A class that contains the definition of a fixture. It also maintains a list of it’s dependencies to allow for analysis of the fixture graph.

Constant Summary

Constants included from SchemaNode

SchemaNode::VALID_NODE_NAME

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SchemaNode

#acts_like_fixtury_schema_node?, #add_child, #apply_options!, #first_ancestor?, #get, #get!, #inspect, #isolation_key, #schema_node_type, #structure

Constructor Details

#initialize(deps: [], **opts, &block) ⇒ Definition

Initializes a new Definition object.

Parameters:

  • deps (Array) (defaults to: [])

    An array of dependencies.

  • opts (Hash)

    Additional options for the Definition.

  • block (Proc)

    A block of code to be executed.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fixtury/definition.rb', line 15

def initialize(deps: [], **opts, &block)
  super(**opts)

  @dependencies = Array(deps).each_with_object({}) do |d, deps|
    parsed_deps = Dependency.from(parent, d)
    parsed_deps.each do |dep|
      existing = deps[dep.accessor]
      raise ArgumentError, "Accessor #{dep.accessor} is already declared by #{existing.search}" if existing

      deps[dep.accessor] = dep
    end
  end

  @callable = block
end

Instance Attribute Details

#callableObject (readonly)

Returns the value of attribute callable.



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

def callable
  @callable
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



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

def dependencies
  @dependencies
end

Instance Method Details

#acts_like_fixtury_definition?Boolean

Indicates whether the Definition acts like a Fixtury definition.

Returns:

  • (Boolean)

    ‘true` if it acts like a Fixtury definition, `false` otherwise.



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

def acts_like_fixtury_definition?
  true
end