Module: RSpec::Generator::Require

Defined in:
lib/generator-spec/rspec/generator/require.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.libObject

Returns the value of attribute lib.



25
26
27
# File 'lib/generator-spec/rspec/generator/require.rb', line 25

def lib
  @lib
end

.root_dirObject

Returns the value of attribute root_dir.



25
26
27
# File 'lib/generator-spec/rspec/generator/require.rb', line 25

def root_dir
  @root_dir
end

Class Method Details

.debug?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/generator-spec/rspec/generator/require.rb', line 27

def debug?
  RSpec::Generator.debug?
end

.parse_generator_hash(hash) ⇒ Object



31
32
33
# File 'lib/generator-spec/rspec/generator/require.rb', line 31

def parse_generator_hash hash
  parse_generator_list hash.keys.first, hash.values.flatten
end

.parse_generator_list(name, generators) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/generator-spec/rspec/generator/require.rb', line 35

def parse_generator_list name, generators           
  if generators.empty?                       
    require_generator! name          
  else  
    generators.each do |generator_name|
      require_generator! name, generator_name
    end  
  end  
end

.require_all_generators(name = nil) ⇒ Object

Raises:

  • (Error)


45
46
47
48
49
50
51
52
53
54
# File 'lib/generator-spec/rspec/generator/require.rb', line 45

def require_all_generators name=nil
  raise Error, "lib must be set to lib directory for RSpec::Generator::Require" if !lib
  base_path = File.join(lib, 'generators')
  path = name ? File.join(base_path, name) : base_path
  path = File.expand_path path
  root = root_dir || ''
  path = File.join(root, path)                
  puts "require_all: #{path}" if debug?
  require_all path
end

.require_file_name(name, name_space = nil) ⇒ Object



65
66
67
68
69
# File 'lib/generator-spec/rspec/generator/require.rb', line 65

def require_file_name name, name_space=nil
  root = root_dir || ''
  file = File.join('generators', name.to_s, "#{name_space}", "#{name_space || name}_generator")
  File.join(root, file)
end

.require_generator!(name, generator = nil) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/generator-spec/rspec/generator/require.rb', line 56

def require_generator! name, generator=nil  
  require_all_generators(name) and return if generator == :all        

  file = (require_file_name name, generator)
  file.gsub! /^\//, ''
  puts "Loading generator: #{file}" if debug?
  require file
end