Class: FeduxOrgStdlib::FixturesManagement::FixturesManager

Inherits:
Object
  • Object
show all
Defined in:
lib/fedux_org_stdlib/fixtures_management/fixtures_manager.rb

Overview

Fixture manager

Instance Method Summary collapse

Constructor Details

#initialize(creator: Fixture, null_klass: NoFixture) ⇒ FixturesManager

Returns a new instance of FixturesManager.



12
13
14
15
16
# File 'lib/fedux_org_stdlib/fixtures_management/fixtures_manager.rb', line 12

def initialize(creator: Fixture, null_klass: NoFixture)
  @fixtures   = Set.new
  @creator    = creator
  @null_klass = null_klass
end

Instance Method Details

#add(path) ⇒ Object

Add fixture



30
31
32
# File 'lib/fedux_org_stdlib/fixtures_management/fixtures_manager.rb', line 30

def add(path)
  fixtures << creator.new(path)
end

#find(name) ⇒ Object

Find fixture



35
36
37
38
39
# File 'lib/fedux_org_stdlib/fixtures_management/fixtures_manager.rb', line 35

def find(name)
  name = name.to_sym

  fixtures.find(null_klass.new(name)) { |f| f.name == name }
end

#load_fixtures(path) ⇒ Object

Load fixtures found at path



19
20
21
22
23
24
25
26
27
# File 'lib/fedux_org_stdlib/fixtures_management/fixtures_manager.rb', line 19

def load_fixtures(path)
  path = Pathname.new(path)

  path.entries.each do |f|
    next if f.to_s[/^\.\.?/]

    add f.expand_path(path)
  end
end

#to_sObject

String representation



42
43
44
45
# File 'lib/fedux_org_stdlib/fixtures_management/fixtures_manager.rb', line 42

def to_s
  data = frontend_components.sort.reduce([]) { |a, e| a << { name: e.name, path: e.path } }
  List.new(data).to_s
end