Class: Ace::Support::Config::Models::ConfigTemplates

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/support/config/models/config_templates.rb

Class Method Summary collapse

Class Method Details

.all_gemsObject



12
13
14
# File 'lib/ace/support/config/models/config_templates.rb', line 12

def all_gems
  gem_info.keys.sort
end

.build_gem_infoObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ace/support/config/models/config_templates.rb', line 36

def build_gem_info
  gems = {}

  parent_dir = File.expand_path("../../../../../../../", __FILE__)
  Dir.glob("#{parent_dir}/ace-*").each do |dir|
    next unless File.directory?(dir)

    gem_name = File.basename(dir)
    gems[gem_name] = {source: :local, path: dir} if has_example_dir?(dir)
  end

  begin
    Gem::Specification.each do |spec|
      next unless spec.name.start_with?("ace-")

      gem_path = spec.gem_dir
      next unless has_example_dir?(gem_path)

      if gems.key?(spec.name)
        gems[spec.name][:source] = :both
        gems[spec.name][:gem_path] = gem_path
      else
        gems[spec.name] = {source: :gem, path: gem_path}
      end
    end
  rescue StandardError
    # Fall back to local gems only when RubyGems traversal is unavailable.
  end

  gems
end

.docs_file_for(gem_name) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/ace/support/config/models/config_templates.rb', line 68

def docs_file_for(gem_name)
  info = gem_info[gem_name]
  return nil unless info

  path = (info[:source] == :gem) ? info[:path] : (info[:path] || info[:gem_path])
  File.join(path, "docs", "config.md")
end

.example_dir_for(gem_name) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/ace/support/config/models/config_templates.rb', line 20

def example_dir_for(gem_name)
  info = gem_info[gem_name]
  return nil unless info

  path = (info[:source] == :gem) ? info[:path] : (info[:path] || info[:gem_path])
  resolve_defaults_dir(path)
end

.gem_exists?(gem_name) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/ace/support/config/models/config_templates.rb', line 16

def gem_exists?(gem_name)
  gem_info.key?(gem_name)
end

.gem_infoObject



28
29
30
# File 'lib/ace/support/config/models/config_templates.rb', line 28

def gem_info
  @gem_info ||= build_gem_info
end

.reset!Object



32
33
34
# File 'lib/ace/support/config/models/config_templates.rb', line 32

def reset!
  @gem_info = nil
end