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
-
#initialize(spec, base_dir = nil) {|spec| ... } ⇒ GemSpecHelper
constructor
A new instance of GemSpecHelper.
- #normalize_files(array_name) ⇒ Object
- #parse ⇒ Object
- #path ⇒ Object
- #prettyify_array(gemspec_ruby, array_name) ⇒ Object
- #update_version(version) ⇒ Object
- #valid? ⇒ Boolean
- #write ⇒ Object
Constructor Details
#initialize(spec, base_dir = nil) {|spec| ... } ⇒ GemSpecHelper
Returns a new instance of GemSpecHelper.
7 8 9 10 11 12 |
# File 'lib/jeweler/gemspec_helper.rb', line 7 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.
5 6 7 |
# File 'lib/jeweler/gemspec_helper.rb', line 5 def base_dir @base_dir end |
#spec ⇒ Object
Returns the value of attribute spec.
5 6 7 |
# File 'lib/jeweler/gemspec_helper.rb', line 5 def spec @spec end |
Instance Method Details
#gem_path ⇒ Object
70 71 72 |
# File 'lib/jeweler/gemspec_helper.rb', line 70 def gem_path File.join(@base_dir, 'pkg', parse.file_name) end |
#normalize_files(array_name) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/jeweler/gemspec_helper.rb', line 53 def normalize_files(array_name) array = @spec.send(array_name) # only keep files, no directories, and sort array = array.select do |path| File.file? File.join(@base_dir, path) end.sort @spec.send("#{array_name}=", array) end |
#parse ⇒ Object
46 47 48 49 50 51 |
# File 'lib/jeweler/gemspec_helper.rb', line 46 def parse data = File.read(path) parsed_gemspec = nil Thread.new { parsed_gemspec = eval("$SAFE = 3\n#{data}", binding, path) }.join parsed_gemspec end |
#path ⇒ Object
40 41 42 43 44 |
# File 'lib/jeweler/gemspec_helper.rb', line 40 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
63 64 65 66 67 68 |
# File 'lib/jeweler/gemspec_helper.rb', line 63 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.split(",").join(",\n ")}\n ]" end end |
#update_version(version) ⇒ Object
74 75 76 |
# File 'lib/jeweler/gemspec_helper.rb', line 74 def update_version(version) @spec.version = version.to_s end |
#valid? ⇒ Boolean
14 15 16 17 18 19 20 21 |
# File 'lib/jeweler/gemspec_helper.rb', line 14 def valid? begin parse true rescue false end end |
#write ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/jeweler/gemspec_helper.rb', line 23 def write normalize_files(:files) normalize_files(:files) normalize_files(:extra_rdoc_files) File.open(path, 'w') do |f| gemspec_ruby = @spec.to_ruby gemspec_ruby = prettyify_array(gemspec_ruby, :files) gemspec_ruby = prettyify_array(gemspec_ruby, :test_files) gemspec_ruby = prettyify_array(gemspec_ruby, :extra_rdoc_files) f.puts "# Generated by jeweler" f.puts "# DO NOT EDIT THIS FILE" f.puts "# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`" f.write gemspec_ruby end end |