Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Licenses #32

Closed
wants to merge 2 commits into from

2 participants

Mike Dalessio Ryan Davis
Mike Dalessio

Adding convenience method and attribute for declaring licenses. This might reasonably encourage people to declare licenses in their gemspec for use in, e.g. rubygems.org

See https://github.com/rubygems/rubygems.org/pull/458/files for some related work.

Ryan Davis
Owner

Hrm... what version of rubygems supports licenses? I guess I haven't paid attention to that one.

Ryan Davis
Owner

Done! Thanks!

Ryan Davis zenspider closed this September 14, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
6  History.txt
... ...
@@ -1,3 +1,9 @@
  1
+=== Unreleased
  2
+
  3
+* 1 minor enhancement:
  4
+
  5
+  * New Hoe#licenses attribute and Hoe#license helper method, for declaring gem's license(s).
  6
+
1 7
 === 3.0.8 / 2012-08-20
2 8
 
3 9
 * 1 bug fix:
16  lib/hoe.rb
@@ -183,6 +183,11 @@ class Hoe
183 183
   attr_accessor :history_file
184 184
 
185 185
   ##
  186
+  # Optional: An array containing the license(s) under which this gem is released.
  187
+
  188
+  attr_accessor :licenses
  189
+
  190
+  ##
186 191
   # *MANDATORY*: The name of the release.
187 192
   #
188 193
   # Set via Hoe.spec.
@@ -423,6 +428,14 @@ def activate_plugin_deps
423 428
   end
424 429
 
425 430
   ##
  431
+  #  Specify a license for your gem.
  432
+  #  Call it multiple times if you are releasing under multiple licenses.
  433
+  #
  434
+  def license name
  435
+    self.licenses << name
  436
+  end
  437
+
  438
+  ##
426 439
   # Add a dependency declaration to your spec. Pass :dev to
427 440
   # +type+ for developer dependencies.
428 441
 
@@ -550,6 +563,8 @@ def define_spec
550 563
       end
551 564
     end
552 565
 
  566
+    spec.licenses = licenses unless licenses.empty?
  567
+
553 568
     # Do any extra stuff the user wants
554 569
     spec_extras.each do |msg, val|
555 570
       case val
@@ -593,6 +608,7 @@ def initialize name, version = nil # :nodoc:
593 608
     self.extra_deps           = []
594 609
     self.extra_dev_deps       = []
595 610
     self.extra_rdoc_files     = []
  611
+    self.licenses             = []
596 612
     self.post_install_message = nil
597 613
     self.rubyforge_name       = name.downcase
598 614
     self.spec                 = nil
2  template/Rakefile.erb
@@ -17,6 +17,8 @@ Hoe.spec '<%= project %>' do
17 17
   # developer('<%= XIF %>', '<%= XIF %>@example.com')
18 18
 
19 19
   # self.rubyforge_name = '<%= project %>x' # if different than '<%= project %>'
  20
+
  21
+  # license 'MIT' # this should match the license in the README
20 22
 end
21 23
 
22 24
 # vim: syntax=ruby
48  test/test_hoe.rb
@@ -319,6 +319,54 @@ def test_possibly_better
319 319
     # flunk "not yet"
320 320
   end
321 321
 
  322
+  def test_no_license
  323
+    hoe = Hoe.spec("blah") do
  324
+      self.version = '1.2.3'
  325
+      developer 'author', 'email'
  326
+    end
  327
+
  328
+    spec = hoe.spec
  329
+
  330
+    assert spec.licenses.empty?
  331
+  end
  332
+
  333
+  def test_license
  334
+    hoe = Hoe.spec("blah") do
  335
+      self.version = '1.2.3'
  336
+      developer 'author', 'email'
  337
+      license 'MIT'
  338
+    end
  339
+
  340
+    spec = hoe.spec
  341
+
  342
+    assert_equal %w(MIT), spec.licenses
  343
+  end
  344
+
  345
+  def test_multiple_calls_to_license
  346
+    hoe = Hoe.spec("blah") do
  347
+      self.version = '1.2.3'
  348
+      developer 'author', 'email'
  349
+      license 'MIT'
  350
+      license 'GPL-2'
  351
+    end
  352
+
  353
+    spec = hoe.spec
  354
+
  355
+    assert_equal %w(MIT GPL-2), spec.licenses
  356
+  end
  357
+
  358
+  def test_setting_licenses
  359
+    hoe = Hoe.spec("blah") do
  360
+      self.version = '1.2.3'
  361
+      developer 'author', 'email'
  362
+      self.licenses = ['MIT', 'GPL-2']
  363
+    end
  364
+
  365
+    spec = hoe.spec
  366
+
  367
+    assert_equal %w(MIT GPL-2), spec.licenses
  368
+  end
  369
+
322 370
   def test_plugins
323 371
     before = Hoe.plugins.dup
324 372
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.