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
No related tags found
No related merge requests found
...@@ -4,13 +4,16 @@ module AweSim ...@@ -4,13 +4,16 @@ module AweSim
PROTECTED_NAMES = ["shared_apps", "cgi-bin", "tmp"] PROTECTED_NAMES = ["shared_apps", "cgi-bin", "tmp"]
# FIXME: still returns nil sometimes yuck
def self.at(path: path) 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 end
def self.all_at(path: path) def self.all_at(path: path)
Dir.glob("#{path}/**").sort.reduce([]) do |apps, appdir| 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 apps
end end
end end
...@@ -25,6 +28,19 @@ module AweSim ...@@ -25,6 +28,19 @@ module AweSim
dir.executable? && dir.readable? dir.executable? && dir.readable?
end 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) def initialize(workdir: nil)
# TODO: add gitdir and other properties # TODO: add gitdir and other properties
@workdir = Pathname.new(workdir.to_s) @workdir = Pathname.new(workdir.to_s)
......
...@@ -55,10 +55,8 @@ documentation: | ...@@ -55,10 +55,8 @@ documentation: |
add_manifest(@tmpdir.join("app_norx.yml")) add_manifest(@tmpdir.join("app_norx.yml"))
assert_valid_manifest app.manifest assert_valid_manifest app.manifest
# assert ! app.accessible?, "app should indicate its not accesible" assert ! app.accessible?, "app should indicate its not accesible"
# assert app.manifest.avail?, "manifest#avail? should return true" # better than exist? assert app.valid_dir?, "app is valid directory name"
# TODO: way to verify which manifest was read is to modify the parent yaml
end end
# TODO: cfs.yml, cfs/manifest.yml, and cfs rx: read manifest.yml # 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