Module: Charyf::Utils

Defined in:
lib/charyf/utils/utils.rb,
lib/charyf/utils/machine.rb,
lib/charyf/utils/storage/provider.rb

Defined Under Namespace

Modules: StorageProvider Classes: InvalidConfiguration, InvalidDefinitionError, InvalidPath, Machine, NotImplemented

Class Method Summary collapse

Class Method Details

.find_root_with_flag(flag, root_path, default: nil, namespace: 'charyf') ⇒ Object

:nodoc:

Raises:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/charyf/utils/utils.rb', line 11

def self.find_root_with_flag(flag, root_path, default: nil, namespace: 'charyf') #:nodoc:
  root_path = Pathname.new(root_path)

  root_path = root_path.join(namespace) if namespace && File.directory?(root_path.join(namespace))

  while root_path && File.directory?(root_path) && !File.exist?(root_path.join(flag))
    parent = root_path.dirname
    root_path = parent != root_path && parent
  end

  root = File.exist?("#{root_path}/#{flag}") ? root_path : default
  raise InvalidPath.new("Could not find root path for #{self}") unless root

  Pathname.new File.realpath root
end

.require_recursive(path, condition: nil) ⇒ Object

Requires files before recursion into directory



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/charyf/utils/utils.rb', line 28

def self.require_recursive(path, condition: nil)
  unless File.directory? path
    require path if !condition || condition.call(path)
  end

  files = Dir[path.join('**')].select { |p| !File.directory?(p) }
  dirs = Dir[path.join('**')].select { |p| File.directory?(p) }

  (files + dirs).each do |item|
    require_recursive Pathname.new(item), condition: condition
  end
end