Class: Jeweler::GemSpecHelper
- Inherits:
-
Object
- Object
- Jeweler::GemSpecHelper
- Defined in:
- lib/jeweler/gemspec_helper.rb
Instance Attribute Summary collapse
-
#base_dir ⇒ Object
Returns the value of attribute base_dir.
-
#spec ⇒ Object
Returns the value of attribute spec.
Instance Method Summary collapse
- #gem_path ⇒ Object
-
#has_version? ⇒ Boolean
Checks whether it uses the version helper or the users defined version.
-
#initialize(spec, base_dir = nil) {|spec| ... } ⇒ GemSpecHelper
constructor
A new instance of GemSpecHelper.
- #normalize_files(array_attribute) ⇒ Object
- #parse ⇒ Object
- #path ⇒ Object
-
#prettyify_array(gemspec_ruby, array_name) ⇒ Object
Adds extra space when outputting an array.
- #to_ruby ⇒ Object
- #update_version(version) ⇒ Object
- #valid? ⇒ Boolean
- #write ⇒ Object
Constructor Details
#initialize(spec, base_dir = nil) {|spec| ... } ⇒ GemSpecHelper
Returns a new instance of GemSpecHelper.
5 6 7 8 9 10 |
# File 'lib/jeweler/gemspec_helper.rb', line 5 def initialize(spec, base_dir = nil) self.spec = spec self.base_dir = base_dir || '' yield spec if block_given? end |
Instance Attribute Details
#base_dir ⇒ Object
Returns the value of attribute base_dir.
3 4 5 |
# File 'lib/jeweler/gemspec_helper.rb', line 3 def base_dir @base_dir end |
#spec ⇒ Object
Returns the value of attribute spec.
3 4 5 |
# File 'lib/jeweler/gemspec_helper.rb', line 3 def spec @spec end |
Instance Method Details
#gem_path ⇒ Object
74 75 76 |
# File 'lib/jeweler/gemspec_helper.rb', line 74 def gem_path File.join(@base_dir, 'pkg', parse.file_name) end |
#has_version? ⇒ Boolean
Checks whether it uses the version helper or the users defined version.
83 84 85 |
# File 'lib/jeweler/gemspec_helper.rb', line 83 def has_version? !@spec.version.nil? end |
#normalize_files(array_attribute) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/jeweler/gemspec_helper.rb', line 55 def normalize_files(array_attribute) array = @spec.send(array_attribute) # only keep files, no directories, and sort array = array.select do |path| File.file? File.join(@base_dir, path) end.sort @spec.send("#{array_attribute}=", array) end |
#parse ⇒ Object
48 49 50 51 52 53 |
# File 'lib/jeweler/gemspec_helper.rb', line 48 def parse data = self.to_ruby parsed_gemspec = nil Thread.new { parsed_gemspec = eval("$SAFE = 3\n#{data}", binding, path) }.join parsed_gemspec end |
#path ⇒ Object
42 43 44 45 46 |
# File 'lib/jeweler/gemspec_helper.rb', line 42 def path denormalized_path = File.join(@base_dir, "#{@spec.name}.gemspec") absolute_path = File.(denormalized_path) absolute_path.gsub(Dir.getwd + File::SEPARATOR, '') end |
#prettyify_array(gemspec_ruby, array_name) ⇒ Object
Adds extra space when outputting an array. This helps create better version control diffs, because otherwise it is all on the same line.
66 67 68 69 70 71 72 |
# File 'lib/jeweler/gemspec_helper.rb', line 66 def prettyify_array(gemspec_ruby, array_name) gemspec_ruby.gsub(/s\.#{array_name.to_s} = \[.+?\]/) do |match| leadin, files = match[0..-2].split("[") leadin + "[\n #{files.gsub(%|", "|, %|",\n "|)}\n ]" end end |
#to_ruby ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jeweler/gemspec_helper.rb', line 27 def to_ruby normalize_files(:files) normalize_files(:extra_rdoc_files) gemspec_ruby = @spec.to_ruby gemspec_ruby = prettyify_array(gemspec_ruby, :files) gemspec_ruby = prettyify_array(gemspec_ruby, :extra_rdoc_files) gemspec_ruby = <<-END # Generated by jeweler # DO NOT EDIT THIS FILE DIRECTLY # Instead, edit Jeweler::Tasks in #{Rake.application.rakefile}, and run 'rake gemspec' #{gemspec_ruby} END end |
#update_version(version) ⇒ Object
78 79 80 |
# File 'lib/jeweler/gemspec_helper.rb', line 78 def update_version(version) @spec.version = version.to_s end |
#valid? ⇒ Boolean
12 13 14 15 16 17 18 19 |
# File 'lib/jeweler/gemspec_helper.rb', line 12 def valid? begin parse true rescue false end end |
#write ⇒ Object
21 22 23 24 25 |
# File 'lib/jeweler/gemspec_helper.rb', line 21 def write File.open(path, 'w') do |f| f.write self.to_ruby end end |