Class: BlueprintsBoy::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/blueprints_boy/manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeManager

Returns a new instance of Manager.



5
6
7
8
# File 'lib/blueprints_boy/manager.rb', line 5

def initialize
  @blueprints = {}
  @registry = nil
end

Instance Attribute Details

#blueprintsObject (readonly)

Returns the value of attribute blueprints.



3
4
5
# File 'lib/blueprints_boy/manager.rb', line 3

def blueprints
  @blueprints
end

#registryObject (readonly)

Returns the value of attribute registry.



3
4
5
# File 'lib/blueprints_boy/manager.rb', line 3

def registry
  @registry
end

Instance Method Details

#add(blueprint) ⇒ Object



10
11
12
# File 'lib/blueprints_boy/manager.rb', line 10

def add(blueprint)
  @blueprints[blueprint.name] = blueprint
end

#build(environment, names, options = {}) ⇒ Object



20
21
22
23
24
25
# File 'lib/blueprints_boy/manager.rb', line 20

def build(environment, names, options = {})
  result = parse_names(names).collect do |name, attributes|
    build_blueprint(environment, name, attributes, options)
  end
  result.size > 1 ? result : result.first
end

#find(name) ⇒ Object Also known as: []



14
15
16
# File 'lib/blueprints_boy/manager.rb', line 14

def find(name)
  @blueprints[name] or raise BlueprintNotFound, "Blueprint :#{name} cannot be found"
end

#push_registry(blueprint_names = []) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/blueprints_boy/manager.rb', line 44

def push_registry(blueprint_names = [])
  @registry = Registry.new(blueprint_names, @registry)

  environment = Object.new
  environment.singleton_class.send(:include, BlueprintsBoy::Helper)
  prepare_env(environment)
  build(environment, @registry.names)
  @registry.store environment.blueprint_data
end

#setup(environment) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/blueprints_boy/manager.rb', line 27

def setup(environment)
  prepare_env(environment)
  push_registry
  @registry.restore.each { |name, value| environment.set name, value }

  DatabaseCleaner.start
rescue DatabaseCleaner::NoORMDetected
  # ignored
end

#teardownObject



37
38
39
40
41
42
# File 'lib/blueprints_boy/manager.rb', line 37

def teardown
  @registry = @registry.parent
  DatabaseCleaner.clean
rescue DatabaseCleaner::NoORMDetected
  # ignored
end