Module: Cardio::Modfiles

Included in:
Cardio
Defined in:
card/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



29
30
31
32
33
# File 'card/lib/cardio/modfiles.rb', line 29

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 'card/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_path(&block) ⇒ Object



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

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

#gem_mod_spec?(spec) ⇒ True/False

Returns:

  • (True/False)


12
13
14
15
16
# File 'card/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 'card/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



35
36
37
38
39
# File 'card/lib/cardio/modfiles.rb', line 35

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