lib/mortar/project.rb in mortar-0.6.2 vs lib/mortar/project.rb in mortar-0.7.0

- old
+ new

@@ -55,10 +55,23 @@ pigscripts_path, "pigscripts", ".pig") @pigscripts end + + def controlscripts_path + File.join(@root_path, "controlscripts") + end + + def controlscripts + @controlscripts ||= ControlScripts.new( + controlscripts_path, + "controlscripts", + ".py", + :optional => true) + @controlscripts + end def tmp_path path = File.join(@root_path, "tmp") unless File.directory? path FileUtils.mkdir_p path @@ -73,14 +86,15 @@ class ProjectEntity include Enumerable - def initialize(path, name, filename_extension) + def initialize(path, name, filename_extension, optional=false) @path = path @name = name @filename_extension = filename_extension + @optional = optional @elements = elements end def method_missing(method, *args) method_name = method.to_s @@ -105,31 +119,38 @@ def element_name(element_path) File.basename(element_path, @filename_extension) end def elements - unless File.directory? @path - raise ProjectError, "Unable to find #{@name} directory in project" + if File.directory? @path + # get {script_name => full_path} + file_paths = Dir[File.join(@path, "**", "*#{@filename_extension}")] + file_paths_hsh = file_paths.collect{|element_path| [element_name(element_path), element(element_name(element_path), element_path)]}.flatten + return Hash[*file_paths_hsh] + else + raise ProjectError, "Unable to find #{@name} directory in project" if not @optional end - - # get {script_name => full_path} - file_paths = Dir[File.join(@path, "**", "*#{@filename_extension}")] - file_paths_hsh = file_paths.collect{|element_path| [element_name(element_path), element(element_name(element_path), element_path)]}.flatten - Hash[*file_paths_hsh] + return Hash[] end def element(path) raise NotImplementedError, "Implement in subclass" end end class PigScripts < ProjectEntity def element(name, path) - Script.new(name, path) + PigScript.new(name, path) end end + class ControlScripts < ProjectEntity + def element(name, path) + ControlScript.new(name, path) + end + end + class PythonUDFs < ProjectEntity def element(name, path) Script.new(name, path) end end @@ -152,9 +173,14 @@ end def to_s code end + end + + class ControlScript < Script + end + class PigScript < Script end end end