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
- .create_action_filters(on_all = nil, only = [], except = []) ⇒ Object
-
.find_root_with_flag(flag, root_path, default: nil, namespace: 'charyf') ⇒ Object
:nodoc:.
- .match_action_filters?(name, filters = {only: [], except: []}) ⇒ Boolean
-
.require_recursive(path, condition: nil) ⇒ Object
Requires files before recursion into directory.
Class Method Details
.create_action_filters(on_all = nil, only = [], except = []) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/charyf/utils/utils.rb', line 41 def self.create_action_filters(on_all = nil, only = [], except = []) if only && only != :all && !only.empty? && except && !except.empty? raise InvalidDefinitionError.new("Define only or except, don't define both"); end _only = except && except.empty? ? only.map(&:to_sym) : :all _only = :all if on_all == :all _except = except.map(&:to_sym) { only: _only, except: _except } end |
.find_root_with_flag(flag, root_path, default: nil, namespace: 'charyf') ⇒ Object
:nodoc:
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 |
.match_action_filters?(name, filters = {only: [], except: []}) ⇒ Boolean
57 58 59 60 61 |
# File 'lib/charyf/utils/utils.rb', line 57 def self.match_action_filters?(name, filters = {only: [], except: []} ) (filters[:only] == :all && !filters[:except].include?(name)) || ((filters[:only] != :all) && (filters[:only] || []).include?(name)) 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 |