lib/rant/import/rubypackage.rb in rant-0.3.0 vs lib/rant/import/rubypackage.rb in rant-0.3.2

- old
+ new

@@ -1,25 +1,8 @@ require 'rant/rantlib' -=begin -class Rant::MethodRecorder - ACCEPT_ALL_BLOCK = lambda { true } - def intialize(&accept) - @ml = [] - @accept = &accept || ACCEPT_ALL_BLOCK - end - def method_missing(sym, *args) - if @accept.call(sym, args) - @ml << [sym, args] - else - super - end - end -end -=end - class Rant::RubyPackage class << self def rant_generate(app, ch, args, &block) if !args || args.empty? @@ -27,18 +10,18 @@ elsif args.size == 1 pkg_name = case args.first when String: args.first when Symbol: args.first.to_s else - app.abort("RubyDoc takes only one additional " + + app.abort("RubyPackage takes only one additional " + "argument, which should be a string or symbol.") end self.new(:app => app, :__caller__ => ch, :name => pkg_name, &block) else app.abort(app.pos_text(file, ln), - "RubyDoc takes only one additional argument, " + + "RubyPackage takes only one additional argument, " + "which should be a string or symbol.") end end end @@ -103,11 +86,15 @@ self.#{a} = [val0, *args].flatten end end def #{a}=(val) unless val.nil? || Array === val - val = [val] + if val.respond_to? :to_ary + val = val.to_ary + else + val = [val] + end end @data["#{a}"] = val end EOM } @@ -127,10 +114,13 @@ @zip_task = nil @package_task = nil name = opts[:name] @ch = opts[:__caller__] || Rant::Lib.parse_caller_elem(caller[0]) unless name + # TODO: pos_text + @app.warn_msg(@app.pos_text(@ch[:file], @ch[:ln]), + "No package name given, using directory name.") # use directory name as project name name = File.split(Dir.pwd)[1] # reset name if it contains a slash or a backslash name = nil if name =~ /\/|\\/ end @@ -147,10 +137,39 @@ else super end end + def validate_attrs(pkg_type = :general) + %w(name files).each { |a| + pkg_requires_attr a + } + case pkg_type + when :gem + %w(version summary).each { |a| + gem_requires_attr a + } + end + end + private :validate_attrs + + def gem_requires_attr(attr_name) + unless @data[attr_name] || @data["gem-#{attr_name}"] + @app.abort("RubyPackaged defined: " + + @app.pos_text(@ch[:file], @ch[:ln]), + "gem specification requires `#{attr_name}' attribute") + end + end + + def pkg_requires_attr(attr_name) + unless @data[attr_name] + @app.abort("RubyPackaged defined: " + + @app.pos_text(@ch[:file], @ch[:ln]), + "`#{attr_name}' attribute required") + end + end + def map_to_gemspec spec mapped_attrs = [] # Map attributes from data to the gem spec as explicitely # specified. EXPLICIT_GEM_MAPPING.each_pair { |attr, gem_attr| @@ -172,10 +191,11 @@ if attr =~ /^gem\-(.+)$/ spec.send("#$1=", val) end } end + private :map_to_gemspec def pkg_dir_task return if @pkg_dir_task if @dist_dir_task # not ideal but should work: If only the gem task will @@ -222,10 +242,11 @@ end # Create task for gem building. If tname is a true value, a # shortcut-task will be created. def gem_task(tname = :gem) + validate_attrs(:gem) # We first define the task to create the gem, and afterwards # the task to create the pkg directory to ensure that a # pending description is used to describe the gem task. pkg_name = gem_pkg_path if tname @@ -271,10 +292,11 @@ } pkg_dir_task end def tar_task(tname = :tar) + validate_attrs # Create tar task first to ensure that a pending description # is used for the tar task and not for the dist dir task. pkg_name = tar_pkg_path pkg_files = files if tname @@ -290,9 +312,10 @@ } dist_dir_task end def zip_task(tname = :zip) + validate_attrs # Create zip task first to ensure that a pending description # is used for the zip task and not for the dist dir task. pkg_name = zip_pkg_path pkg_files = files if tname