Class: Jeweler::GemSpecHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/jeweler/gemspec.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec, base_dir = nil) {|spec| ... } ⇒ GemSpecHelper

Returns a new instance of GemSpecHelper.

Yields:



7
8
9
10
11
12
# File 'lib/jeweler/gemspec.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_dirObject

Returns the value of attribute base_dir.



5
6
7
# File 'lib/jeweler/gemspec.rb', line 5

def base_dir
  @base_dir
end

#specObject

Returns the value of attribute spec.



5
6
7
# File 'lib/jeweler/gemspec.rb', line 5

def spec
  @spec
end

Instance Method Details

#parseObject



35
36
37
38
# File 'lib/jeweler/gemspec.rb', line 35

def parse
  data = File.read(path)
  Thread.new { eval("$SAFE = 3\n#{data}", binding, path) }.join 
end

#pathObject



29
30
31
32
33
# File 'lib/jeweler/gemspec.rb', line 29

def path
  denormalized_path = File.join(@base_dir, "#{@spec.name}.gemspec")
  absolute_path = File.expand_path(denormalized_path)
  absolute_path.gsub(Dir.getwd + File::SEPARATOR, '') 
end

#valid?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
# File 'lib/jeweler/gemspec.rb', line 14

def valid?
  begin
    parse
    true
  rescue
    false
  end
end

#writeObject



23
24
25
26
27
# File 'lib/jeweler/gemspec.rb', line 23

def write
  File.open(path, 'w') do |f|
    f.write @spec.to_ruby
  end 
end