tasks/gem/gem.rb in new-0.0.6 vs tasks/gem/gem.rb in new-0.0.7

- old
+ new

@@ -1,13 +1,15 @@ +require 'bundler' require 'rake' require 'yaml' class New::Task::Gem < New::Task include New::Interpolate include New::Version GLOB_ATTRIBUTES = [:files, :test_files, :extra_rdoc_files] + GEMFILE = File.expand_path(File.join(Dir.pwd, 'Gemfile')) OPTIONS = { gemspec: { summary: "A short summary of this gem's description. Displayed in `gem list -d`", files: ['**/*','**/.*'] } @@ -25,20 +27,19 @@ end private def set_version - # set version - self.version = project_options[:version] - # bump version - bump_version get_part + version = bump_version(project_options[:version], get_part).to_s # set new version to config - project_options[:version] = version.to_s + project_options[:version] = version end + # Check that any glob pattern attributes match existing files + # def validate_files GLOB_ATTRIBUTES.each do |file_attr| next if @gemspec[file_attr].nil? files = [] @@ -58,11 +59,11 @@ @gemspec[file_attr] = files.flatten end end def render_gemspec_options - string = [] + array = [] # set defaults @gemspec[:date] = Date.today.to_s @gemspec[:name] = project_options[:project_name] @gemspec[:version] = project_options[:version] @@ -84,13 +85,48 @@ val = case v when String then "'#{v}'" else v end - string << " s.#{k} = #{val}" + array << " s.#{k} = #{val}" end - project_options[:gemspec_string] = string.join("\n") + array += extract_gem_dependencies + + project_options[:gemspec_string] = array.join("\n") + end + + # Extract dependencies based on the Gemfile to be used in the gemspec + # + def extract_gem_dependencies + b = Bundler::Dsl.new + b.eval_gemfile(GEMFILE) + + array = [] + runtime = [] + development = [] + + # loop through the required gems and find default and development gems + b.dependencies.each do |g| + groups = g.groups + data = { + name: g.name, + requirements: g.requirements_list.map{ |r| "'#{r}'" }.join(',') + } + + runtime << data if groups.include? :default + development << data if groups.include? :development + end + + # create .gemspec friendly string of requirements + runtime.each do |r| + array << " s.add_runtime_dependency '#{r[:name]}', #{r[:requirements]}" + end + development.each do |r| + array << " s.add_development_dependency '#{r[:name]}', #{r[:requirements]}" + end + + return array end def write_gemspec # process gemspec interpolate File.join(File.dirname(__FILE__), '.gemspec.erb'), project_options