Class: CypressOnRails::SmartFactoryWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/cypress_on_rails/smart_factory_wrapper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files:, factory:, always_reload: false, kernel: Kernel, file_system: File, dir_system: Dir) ⇒ SmartFactoryWrapper

Returns a new instance of SmartFactoryWrapper.



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cypress_on_rails/smart_factory_wrapper.rb', line 38

def initialize(files:, factory:, always_reload: false,
               kernel: Kernel, file_system: File, dir_system: Dir)
  self.files = files
  self.factory = factory
  factory.definition_file_paths = []
  self.always_reload = always_reload
  @kernel = kernel
  @file_system = file_system
  @latest_mtime = nil
  @dir_system = dir_system
end

Instance Attribute Details

#always_reloadObject

Returns the value of attribute always_reload.



36
37
38
# File 'lib/cypress_on_rails/smart_factory_wrapper.rb', line 36

def always_reload
  @always_reload
end

#factoryArray

Returns:

  • (Array)


35
36
37
# File 'lib/cypress_on_rails/smart_factory_wrapper.rb', line 35

def factory
  @factory
end

Class Method Details

.build(*args) ⇒ Object



22
23
24
# File 'lib/cypress_on_rails/smart_factory_wrapper.rb', line 22

def self.build(*args)
  instance.build(*args)
end

.build_list(*args) ⇒ Object



26
27
28
# File 'lib/cypress_on_rails/smart_factory_wrapper.rb', line 26

def self.build_list(*args)
  instance.build_list(*args)
end

.configure(files:, factory:, always_reload: true) ⇒ Object



10
11
12
# File 'lib/cypress_on_rails/smart_factory_wrapper.rb', line 10

def self.configure(files:, factory:, always_reload: true)
  @instance = new(files: files, factory: factory, always_reload: always_reload)
end

.create(*args) ⇒ Object



14
15
16
# File 'lib/cypress_on_rails/smart_factory_wrapper.rb', line 14

def self.create(*args)
  instance.create(*args)
end

.create_list(*args) ⇒ Object



18
19
20
# File 'lib/cypress_on_rails/smart_factory_wrapper.rb', line 18

def self.create_list(*args)
  instance.create_list(*args)
end

.instanceObject



6
7
8
# File 'lib/cypress_on_rails/smart_factory_wrapper.rb', line 6

def self.instance
  @instance ||= new(files: [], factory: SimpleRailsFactory)
end

.reloadObject



30
31
32
# File 'lib/cypress_on_rails/smart_factory_wrapper.rb', line 30

def self.reload
  instance.reload
end

Instance Method Details

#build(*options) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/cypress_on_rails/smart_factory_wrapper.rb', line 66

def build(*options)
  auto_reload
  factory_name = options.shift
  if options.last.is_a?(Hash)
    args = options.pop
  else
    args = {}
  end
  factory.build(factory_name, *options.map(&:to_sym), args.symbolize_keys)
end

#build_list(*args) ⇒ Object



77
78
79
80
# File 'lib/cypress_on_rails/smart_factory_wrapper.rb', line 77

def build_list(*args)
  auto_reload
  factory.build_list(*args)
end

#create(*options) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/cypress_on_rails/smart_factory_wrapper.rb', line 50

def create(*options)
  auto_reload
  factory_name = options.shift
  if options.last.is_a?(Hash)
    args = options.pop
  else
    args = {}
  end
  factory.create(factory_name,*options.map(&:to_sym),args.symbolize_keys)
end

#create_list(*args) ⇒ Object



61
62
63
64
# File 'lib/cypress_on_rails/smart_factory_wrapper.rb', line 61

def create_list(*args)
  auto_reload
  factory.create_list(*args)
end

#reloadObject



82
83
84
85
86
87
88
89
90
# File 'lib/cypress_on_rails/smart_factory_wrapper.rb', line 82

def reload
  @latest_mtime = current_latest_mtime
  logger.info 'Loading Factories'
  factory.reload
  files.each do |file|
    logger.debug "-- Loading: #{file}"
    @kernel.load(file)
  end 
end