Class: Bueller::GemSpecHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/bueller/gemspec_helper.rb

Defined Under Namespace

Classes: NoGemspecFound, VersionMissing

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_dir = nil) ⇒ GemSpecHelper

Returns a new instance of GemSpecHelper.



12
13
14
# File 'lib/bueller/gemspec_helper.rb', line 12

def initialize(base_dir = nil)
  self.base_dir = base_dir || ''
end

Instance Attribute Details

#base_dirObject

Returns the value of attribute base_dir.



6
7
8
# File 'lib/bueller/gemspec_helper.rb', line 6

def base_dir
  @base_dir
end

#errorsObject

Returns the value of attribute errors.



6
7
8
# File 'lib/bueller/gemspec_helper.rb', line 6

def errors
  @errors
end

#specObject

Returns the value of attribute spec.



6
7
8
# File 'lib/bueller/gemspec_helper.rb', line 6

def spec
  @spec
end

#spec_sourceObject

Returns the value of attribute spec_source.



6
7
8
# File 'lib/bueller/gemspec_helper.rb', line 6

def spec_source
  @spec_source
end

Instance Method Details

#gem_pathObject



53
54
55
# File 'lib/bueller/gemspec_helper.rb', line 53

def gem_path
  File.join(base_dir, 'pkg', spec.file_name)
end

#has_version?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/bueller/gemspec_helper.rb', line 62

def has_version?
  !spec.version.nil?
end

#pathObject

Raises:



33
34
35
36
37
38
39
# File 'lib/bueller/gemspec_helper.rb', line 33

def path
  return @path unless @path.nil?
  denormalized_path = Dir.glob(File.join(base_dir, '*.gemspec')).first
  raise NoGemspecFound, "No gemspec found in #{base_dir}" if denormalized_path.nil?
  absolute_path = File.expand_path(denormalized_path)
  @path = absolute_path.gsub(Dir.getwd + File::SEPARATOR, '') 
end

#project_nameObject



70
71
72
# File 'lib/bueller/gemspec_helper.rb', line 70

def project_name
  spec.name
end

#reload_specObject



45
46
47
# File 'lib/bueller/gemspec_helper.rb', line 45

def reload_spec
  @spec = nil
end

#set_dateObject



57
58
59
60
# File 'lib/bueller/gemspec_helper.rb', line 57

def set_date
  spec_source.sub! /\.date\s*=\s*.*/, %Q{.date = "#{Time.now.strftime('%Y-%m-%d')}"}
  reload_spec
end

#valid?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
# File 'lib/bueller/gemspec_helper.rb', line 16

def valid?
  begin
    spec.validate
  rescue => e
    errors << "gemspec is invalid: #{e}"
    return false
  end

  true
end

#versionObject



66
67
68
# File 'lib/bueller/gemspec_helper.rb', line 66

def version
  spec.version
end

#writeObject



27
28
29
30
31
# File 'lib/bueller/gemspec_helper.rb', line 27

def write
  File.open(path, 'w') do |f|
    f.puts spec_source
  end 
end