Module: Baltix::Source
- Defined in:
- lib/baltix/source.rb
Defined Under Namespace
Classes: Base, Fake, Gem, Gemfile, Rakefile
Constant Summary
collapse
- TYPES =
%w(Gem Gemfile Rakefile Fake Base).reduce({}) do |types, name|
autoload(:"#{name}", File.dirname(__FILE__) + "/source/#{name.downcase}")
types.merge(name.downcase.to_sym => "Baltix::Source::#{name}")
end
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Attribute Details
#rootdir ⇒ Object
Returns the value of attribute rootdir.
4
5
6
|
# File 'lib/baltix/source.rb', line 4
def rootdir
@rootdir
end
|
Class Method Details
.load_from(sources_in) ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/baltix/source.rb', line 37
def load_from sources_in
[ sources_in ].flatten.compact.map do |source_in|
type_code_in = source_in["type"].to_s.to_sym
type_code = TYPES.keys.include?(type_code_in) && type_code_in || :fake
require("baltix/source/#{type_code}")
TYPES[type_code].constantize.new(source_in)
end
end
|
.loaders ⇒ Object
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/baltix/source.rb', line 46
def loaders
@loaders ||=
TYPES.map do |type, mod|
if mod.constantize.constants.include?(:LOADERS)
mod.constantize.const_get(:LOADERS).values
else
type
end
end.flatten.uniq
end
|
.search_in(dir_in, options = {}) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/baltix/source.rb', line 13
def search_in dir_in, options = {}
dir = File.expand_path(dir_in)
sources_pre =
TYPES.map do |(name, const)|
kls = self.const_get(const)
kls.respond_to?(:search) && kls.search(dir, options) || []
end.flatten | [ self::Fake.new({ source_file: File.join(dir, '.fake') }.to_os) ]
sources_pre.group_by do |source|
source.rootdir
end.map do |_a, sources_in|
ina = sources_in.select {|s| TYPES.keys[-1] == s.class.to_s.split("::").last.downcase.to_sym }
TYPES.keys.reverse[1..-1].reduce(ina) do |res, kind|
selected =
sources_in.select do |s|
TYPES.keys[TYPES.keys.index(kind)] == s.class.to_s.split("::").last.downcase.to_sym
end
selected.any? && selected.map {|v| ([v] | res).reduce(&:+) } || res
end
end.flatten
end
|