Class: GemBuilderLib
- Inherits:
-
Object
- Object
- GemBuilderLib
- Defined in:
- lib/gembuilderlib.rb,
lib/gembuilder/version.rb
Constant Summary collapse
- OBJEXT =
".#{Config::CONFIG["OBJEXT"]}"
- VERSION =
'1.2.2'
Class Method Summary collapse
-
.[](gem, conservative = false) ⇒ Object
Helper that will do it all.
Instance Method Summary collapse
- #build_extensions ⇒ Object
- #build_gem ⇒ Object
- #cleanup ⇒ Object
- #fix_gemspec(conservative = false) ⇒ Object
- #format ⇒ Object
-
#initialize(gem) ⇒ GemBuilderLib
constructor
A new instance of GemBuilderLib.
- #installer ⇒ Object
- #platform ⇒ Object
- #spec ⇒ Object
- #tmpdir ⇒ Object
- #unpack_gem ⇒ Object
Constructor Details
#initialize(gem) ⇒ GemBuilderLib
Returns a new instance of GemBuilderLib.
24 25 26 27 28 |
# File 'lib/gembuilderlib.rb', line 24 def initialize(gem) @gem_name = gem @installer = Gem::Installer.new(@gem_name) @format = Gem::Format.from_file_by_path(@gem_name) end |
Class Method Details
.[](gem, conservative = false) ⇒ Object
Helper that will do it all
15 16 17 18 19 20 21 22 |
# File 'lib/gembuilderlib.rb', line 15 def self.[](gem,conservative=false) gem_builder = GemBuilderLib.new(gem) gem_builder.unpack_gem gem_builder.build_extensions gem_builder.fix_gemspec(conservative) gem_builder.build_gem gem_builder.cleanup end |
Instance Method Details
#build_extensions ⇒ Object
52 53 54 |
# File 'lib/gembuilderlib.rb', line 52 def build_extensions installer.build_extensions end |
#build_gem ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/gembuilderlib.rb', line 76 def build_gem start_dir = Dir.pwd Dir.chdir(tmpdir) do gb = Gem::Builder.new(spec) gb.build FileUtils.mv Dir.glob("*.gem"), start_dir end end |
#cleanup ⇒ Object
85 86 87 |
# File 'lib/gembuilderlib.rb', line 85 def cleanup FileUtils.rm_rf(tmpdir) end |
#fix_gemspec(conservative = false) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/gembuilderlib.rb', line 63 def fix_gemspec(conservative = false) files = [] Find.find(tmpdir) do |fname| next if fname == tmpdir next if !conservative && File.extname(fname) == OBJEXT files << fname.sub(Regexp.quote(tmpdir + "/"), '') end spec.extensions = [] spec.files += (files - format.spec.files) spec.platform = platform end |
#format ⇒ Object
38 39 40 |
# File 'lib/gembuilderlib.rb', line 38 def format @format ||= Gem::Format.from_file_by_path(@gem_name) end |
#installer ⇒ Object
34 35 36 |
# File 'lib/gembuilderlib.rb', line 34 def installer @installer ||= Gem::Installer.new(@gem_name) end |
#platform ⇒ Object
56 57 58 59 60 61 |
# File 'lib/gembuilderlib.rb', line 56 def platform # I used to use this to clean up gem names under # darwin, not sure it was a good idea though # Config::CONFIG['arch'].sub(/[\.0-9]*$/, '') Config::CONFIG['arch'] end |
#spec ⇒ Object
42 43 44 |
# File 'lib/gembuilderlib.rb', line 42 def spec @spec ||= format.spec end |
#tmpdir ⇒ Object
30 31 32 |
# File 'lib/gembuilderlib.rb', line 30 def tmpdir @tmpdir ||= File.join(Dir.tmpdir, "gembuilder") end |
#unpack_gem ⇒ Object
46 47 48 49 50 |
# File 'lib/gembuilderlib.rb', line 46 def unpack_gem FileUtils.rm_r(tmpdir) rescue nil FileUtils.mkdir_p(tmpdir) rescue nil installer.unpack(tmpdir) end |