Module: Jeweler::Specification

Defined in:
lib/jeweler/specification.rb

Overview

Extend a Gem::Specification instance with this module to give it Jeweler super-cow powers.

files

a Rake::FileList of anything that is in git and not gitignored. You can include/exclude this default set, or override it entirely

extra_rdoc_files

a Rake::FileList including files like README*, ChangeLog*, and LICENSE*

executables

uses anything found in the bin/ directory.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.filelist_attribute(name) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/jeweler/specification.rb', line 12

def self.filelist_attribute(name)
  code = %{
    def #{name}
      if @#{name} && @#{name}.class != FileList
        @#{name} = FileList[@#{name}]
      end
      @#{name} ||= FileList[]
    end
    def #{name}=(value)
      @#{name} = FileList[value]
    end
  }

  module_eval code, __FILE__, __LINE__ - 9
end

Instance Method Details

#ruby_code(obj) ⇒ Object

Used by Specification#to_ruby to generate a ruby-respresentation of a Gem::Specification



84
85
86
87
88
89
# File 'lib/jeweler/specification.rb', line 84

def ruby_code(obj)
  case obj
  when Rake::FileList then obj.uniq.to_a.inspect
  else super
  end
end

#set_jeweler_defaults(base_dir, git_base_dir = nil) ⇒ Object

Assigns the Jeweler defaults to the Gem::Specification



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/jeweler/specification.rb', line 32

def set_jeweler_defaults(base_dir, git_base_dir = nil)
  base_dir = File.expand_path(base_dir)
  git_base_dir = if git_base_dir
                   File.expand_path(git_base_dir)
                 else
                   base_dir
                 end
  can_git = git_base_dir && base_dir.include?(git_base_dir) && File.directory?(File.join(git_base_dir, '.git'))

  Dir.chdir(git_base_dir) do
    repo = if can_git
             require 'git'
             Git.open(git_base_dir)
           end

    if blank?(files) && repo
      base_dir_with_trailing_separator = File.join(base_dir, '')

      ignored_files = repo.lib.ignored_files + ['.gitignore']
      self.files = (repo.ls_files(base_dir).keys - ignored_files).compact.map do |file|
        File.expand_path(file).sub(base_dir_with_trailing_separator, '')
      end
    end

    if blank?(executables) && repo
      self.executables = (repo.ls_files(File.join(base_dir, 'bin')).keys - repo.lib.ignored_files).map do |file|
        File.basename(file)
      end
    end

    if blank?(extensions)
      self.extensions = FileList['ext/**/{extconf,mkrf_conf}.rb']
    end

    if blank?(extra_rdoc_files)
      self.extra_rdoc_files = FileList['README*', 'ChangeLog*', 'LICENSE*', 'TODO']
    end

    if File.exist?('Gemfile')
      require 'bundler'
      bundler_runtime = Bundler.load
      bundler_dependencies_for(bundler_runtime, :default, :runtime).each do |dependency|
        add_dependency dependency.name, *dependency.requirement.as_list
      end
      bundler_dependencies_for(bundler_runtime, :development).each do |dependency|
        add_development_dependency dependency.name, *dependency.requirement.as_list
      end
    end
  end
end