Skip to content
Snippets Groups Projects
Commit f3ba399a authored by Eric Franz's avatar Eric Franz
Browse files

make app creation more object oriented

split up validation of Apps into three separate concerns:

1. is it a valid dir name?
2. does the user have rx to it?
3. is there a manifest for it the user can read?

for the factory methods return all apps where 1 and 2 or 1 and 3 are true
parent 176a654b
No related branches found
Tags v0.10.1
No related merge requests found
......@@ -4,13 +4,16 @@ module AweSim
PROTECTED_NAMES = ["shared_apps", "cgi-bin", "tmp"]
# FIXME: still returns nil sometimes yuck
def self.at(path: path)
self.new(workdir: path) if self.valid_app_dir?(path)
app = self.new(workdir: path)
app if app.valid_dir? && (app.accessible? || app.manifest.exist?)
end
def self.all_at(path: path)
Dir.glob("#{path}/**").sort.reduce([]) do |apps, appdir|
apps << self.new(workdir: appdir) if self.valid_app_dir?(appdir)
app = self.at(path: appdir)
apps << app unless app.nil?
apps
end
end
......@@ -25,6 +28,19 @@ module AweSim
dir.executable? && dir.readable?
end
# FIXME: should we be making clear which methods of App
# require accessible? true i.e. rx access to
def accessible?
workdir.executable? && workdir.readable?
end
alias_method :rx?, :accessible?
def valid_dir?
(workdir.directory? &&
! self.class::PROTECTED_NAMES.include?(workdir.basename.to_s) &&
workdir.extname != ".git")
end
def initialize(workdir: nil)
# TODO: add gitdir and other properties
@workdir = Pathname.new(workdir.to_s)
......
......@@ -55,10 +55,8 @@ documentation: |
add_manifest(@tmpdir.join("app_norx.yml"))
assert_valid_manifest app.manifest
# assert ! app.accessible?, "app should indicate its not accesible"
# assert app.manifest.avail?, "manifest#avail? should return true" # better than exist?
# TODO: way to verify which manifest was read is to modify the parent yaml
assert ! app.accessible?, "app should indicate its not accesible"
assert app.valid_dir?, "app is valid directory name"
end
# TODO: cfs.yml, cfs/manifest.yml, and cfs rx: read manifest.yml
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment