class Bricolage::FileSystem

Attributes

environment[R]
path[R]

Public Class Methods

for_job_path(job_path, env) click to toggle source
# File lib/bricolage/filesystem.rb, line 16
def FileSystem.for_job_path(job_path, env)
  home, subsys_id = parse_job_path(job_path)
  new(home, env).subsystem(subsys_id)
end
for_options(home, env) click to toggle source
# File lib/bricolage/filesystem.rb, line 12
def FileSystem.for_options(home, env)
  new(home_path(home), env)
end
home_path(opt_path = nil) click to toggle source
# File lib/bricolage/filesystem.rb, line 8
def FileSystem.home_path(opt_path = nil)
  Pathname(opt_path || ENV['BRICOLAGE_HOME'] || Dir.getwd)
end
new(path, env) click to toggle source
# File lib/bricolage/filesystem.rb, line 29
def initialize(path, env)
  @path = Pathname(path)
  @environment = env
  @subsystems = {}
end
parse_job_path(job_path) click to toggle source

job_path -> [home_path, subsys_id]

# File lib/bricolage/filesystem.rb, line 22
def FileSystem.parse_job_path(job_path)
  subsys_path = Pathname(job_path).realpath.parent
  return subsys_path.parent, subsys_path.basename
rescue SystemCallError => err
  raise ParameterError, "failed to access job file: #{err.message}"
end

Public Instance Methods

all_typed_pathes(type) click to toggle source

/.TYPE

# File lib/bricolage/filesystem.rb, line 145
def all_typed_pathes(type)
  subsystems.map {|subsys| subsys.typed_pathes(type) }.flatten
end
config_file_loader() click to toggle source
# File lib/bricolage/filesystem.rb, line 130
def config_file_loader
  ConfigLoader.new(home_path)
end
config_pathes(name) click to toggle source
# File lib/bricolage/filesystem.rb, line 126
def config_pathes(name)
  [ "config/#{name}", "config/#{@environment}/#{name}" ].map {|rel| root.relative(rel) }
end
exist?(name) click to toggle source
# File lib/bricolage/filesystem.rb, line 83
def exist?(name)
  relative(name).exist?
end
file(name) click to toggle source
# File lib/bricolage/filesystem.rb, line 87
def file(name)
  FileResource.new(relative(name))
end
glob(pattern) click to toggle source
# File lib/bricolage/filesystem.rb, line 140
def glob(pattern)
  Dir.glob("#{@path}/#{pattern}").map {|path| Pathname(path) }
end
home_path() click to toggle source
# File lib/bricolage/filesystem.rb, line 75
def home_path
  root.path
end
inspect() click to toggle source
# File lib/bricolage/filesystem.rb, line 46
def inspect
  "\#<#{self.class} #{@path}>"
end
job_dir() click to toggle source
# File lib/bricolage/filesystem.rb, line 79
def job_dir
  scoped? ? @path : nil
end
job_file(id) click to toggle source
# File lib/bricolage/filesystem.rb, line 134
def job_file(id)
  path = typed_name(id, 'job')
  return path if path.exist?
  glob("#{id}.*.job").first or path
end
parameter_file(name, type) click to toggle source
# File lib/bricolage/filesystem.rb, line 118
def parameter_file(name, type)
  name.count('/') == 0 ? typed_file(name, type) : root.file(name)
end
parameter_file_loader() click to toggle source
# File lib/bricolage/filesystem.rb, line 122
def parameter_file_loader
  ConfigLoader.new(home_path)
end
relative(name)
Alias for: relative_path
relative_path(name) click to toggle source
# File lib/bricolage/filesystem.rb, line 97
def relative_path(name)
  path = Pathname(name)
  if path.absolute?
    path
  else
    @path + path
  end
end
Also aliased as: relative
root() click to toggle source
# File lib/bricolage/filesystem.rb, line 50
def root
  self
end
root_relative(rel)
Alias for: root_relative_path
root_relative_path(rel) click to toggle source
# File lib/bricolage/filesystem.rb, line 91
def root_relative_path(rel)
  root.relative_path(rel)
end
Also aliased as: root_relative
scope() click to toggle source
# File lib/bricolage/filesystem.rb, line 39
def scope
  nil
end
scoped?() click to toggle source
# File lib/bricolage/filesystem.rb, line 35
def scoped?
  false
end
subdirectories() click to toggle source
# File lib/bricolage/filesystem.rb, line 71
def subdirectories
  @path.children(true).select {|path| path.directory? }
end
subsystem(id) click to toggle source
# File lib/bricolage/filesystem.rb, line 54
def subsystem(id)
  @subsystems[id.to_s] ||= begin
    unless root.relative(id).directory?
      raise ParameterError, "no such subsystem: #{id}"
    end
    ScopedFileSystem.new(root, id)
  end
end
subsystems() click to toggle source
# File lib/bricolage/filesystem.rb, line 63
def subsystems
  root.subdirectories
      .map {|path| path.basename.to_s }
      .select {|name| /\A\w+\z/ =~ name }
      .reject {|name| name == 'config' }
      .map {|name| subsystem(name) }
end
typed_file(name, type) click to toggle source

typed_file(“make_master”, “sql”) -> FileResource(“$prefix/make_master.sql”)

# File lib/bricolage/filesystem.rb, line 114
def typed_file(name, type)
  FileResource.new(typed_name(name, type))
end
typed_name(name, type) click to toggle source

typed_name(“make_master”, “sql”) -> Pathname(“$prefix/make_master.sql”)

# File lib/bricolage/filesystem.rb, line 109
def typed_name(name, type)
  relative(name.count('.') > 0 ? name : "#{name}.#{type}")
end
typed_pathes(type) click to toggle source
# File lib/bricolage/filesystem.rb, line 149
def typed_pathes(type)
  @path.children.select {|path| path.file? and path.extname.to_s == ".#{type}" }
end