Module: Cardio::Modfiles

Included in:
Cardio
Defined in:
lib/cardio/modfiles.rb

Overview

methods for handling simple and gem mod paths/files

Instance Method Summary collapse

Instance Method Details

#each_gem_mod_pathObject



31
32
33
34
35
# File 'lib/cardio/modfiles.rb', line 31

def each_gem_mod_path
  gem_mod_specs.each_value do |spec|
    yield spec.full_gem_path
  end
end

#each_mod_path(&block) ⇒ Object



18
19
20
21
# File 'lib/cardio/modfiles.rb', line 18

def each_mod_path &block
  each_simple_mod_path(&block)
  each_gem_mod_path(&block)
end

#each_simple_mod_pathObject



23
24
25
26
27
28
29
# File 'lib/cardio/modfiles.rb', line 23

def each_simple_mod_path
  paths["mod"].each do |mods_path|
    Dir.glob("#{mods_path}/*").each do |single_mod_path|
      yield single_mod_path
    end
  end
end

#gem_mod_spec?(spec) ⇒ True/False

Returns:

  • (True/False)


12
13
14
15
16
# File 'lib/cardio/modfiles.rb', line 12

def gem_mod_spec? spec
  return unless spec

  spec.name.match?(/^card-mod-/) || spec.["card-mod"].present?
end

#gem_mod_specsHash

Returns in the form{ modname(String) => Gem::Specification }.

Returns:

  • (Hash)

    in the form{ modname(String) => Gem::Specification }



5
6
7
8
9
# File 'lib/cardio/modfiles.rb', line 5

def gem_mod_specs
  Bundler.definition.specs.each_with_object({}) do |gem_spec, h|
    h[gem_spec.name] = gem_spec if gem_mod_spec? gem_spec
  end
end

#mod_migration_paths(dir) ⇒ Object



37
38
39
40
41
# File 'lib/cardio/modfiles.rb', line 37

def mod_migration_paths dir
  [].tap do |list|
    Cardio::Mod.dirs.each("db/#{dir}") { |path| list.concat Dir.glob path }
  end
end