Class: Hoe

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/hoe.rb,
lib/hoe/git.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Clean, Compiler, Cov, Debug, Deps, Flay, Flog, GemPreludeSucks, Gemcutter, Git, Inline, Newb, Package, Publish, Racc, Rdoc, Signing, Test

Constant Summary collapse

VERSION =

duh

"4.6.1"
RUBY_DEBUG =

Used to add extra flags to RUBY_FLAGS.

RUBY_FLAGS =

Used to specify flags to ruby [has smart default].

ENV["RUBY_FLAGS"] || default_ruby_flags
URLS_TO_META_MAP =

Map from the commonly used url names to gemspec’s metadata keys See guides.rubygems.org/specification-reference/#metadata

{
  "bugs" => "bug_tracker_uri",
  "clog" => "changelog_uri",
  "code" => "source_code_uri",
  "doco" => "documentation_uri",
  "docs" => "documentation_uri",
  "home" => "homepage_uri",
  "mail" => "mailing_list_uri",
  "wiki" => "wiki_uri",

  "changelog"     => "changelog_uri",
  "changes"       => "changelog_uri",
  "documentation" => "documentation_uri",
  "history"       => "changelog_uri",
  "issues"        => "bug_tracker_uri",
  "rdoc"          => "documentation_uri",
  "tickets"       => "bug_tracker_uri",
}
DEFAULT_CONFIG =

Default configuration values for .hoerc. Plugins should populate this on load.

{
  "exclude" => /\/tmp\/|CVS|\.svn|\.git|TAGS|extconf.h|\.bundle$|\.o$|\.log$/,
}
WINDOZE =

True if you’re a masochistic developer. Used for building commands.

RbConfig::CONFIG["host_os"] =~ /mswin|mingw/
@@plugins =
[:clean, :debug, :deps, :flay, :flog, :newb, :package,
:publish, :gemcutter, :signing, :test]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, version = nil) ⇒ Hoe

Create a newly initialized hoe spec.



655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
# File 'lib/hoe.rb', line 655

def initialize name, version = nil # :nodoc:
  self.name                 = name
  self.version              = version

  self.author               = []
  self.changes              = nil
  self.description          = nil
  self.description_sections = %w[description features/problems]
  self.description_rdoc_hack = true
  self.email                = []
  self.extra_deps           = []
  self.extra_dev_deps       = []
  self.extra_rdoc_files     = []
  self.licenses             = []
  self.post_install_message = nil
  self.group_name           = name.downcase
  self.spec                 = nil
  self.spec_extras          = {}
  self.summary              = nil
  self.summary_sentences    = 1
  self.test_globs           = ["test/**/{test,spec}_*.rb",
                               "test/**/*_{test,spec}.rb"]

  manifest = read_manifest

  if manifest then
    self.readme_file  = manifest.grep(/^README\./).first
    self.history_file = manifest.grep(/^History\./).first
  end

  self.history_file ||= Dir.glob("History.{rdoc,txt,md}").first || "History.txt"
  self.readme_file  ||= Dir.glob("README.{rdoc,txt,md}").first || "README.txt"

  # delayed to set readme_file first
  self.rdoc_options = ["--main", readme_file]

  abort "Hoe.new {...} removed. Switch to Hoe.spec." if block_given?
end

Instance Attribute Details

#authorObject

MANDATORY: The author(s) of the package. (can be array)

Use the #developer method to fill in both author and email cleanly.



151
152
153
# File 'lib/hoe.rb', line 151

def author
  @author
end

#bindirObject

Optional: The name of the executables directory. [default: bin]



248
249
250
# File 'lib/hoe.rb', line 248

def bindir
  @bindir
end

#changesObject

Optional: A description of the release’s latest changes. Auto-populates to the top entry of History.txt.



157
158
159
# File 'lib/hoe.rb', line 157

def changes
  @changes
end

#descriptionObject

Optional: A description of the project. Auto-populates from the first paragraph of the DESCRIPTION section of README.txt.

See also: Hoe#summary and Hoe.paragraphs_of.



165
166
167
# File 'lib/hoe.rb', line 165

def description
  @description
end

#description_rdoc_hackObject

Optional: Add a (hopefully hidden) H2 to the description to force rubygems.org to properly render the description as rdoc. Defaults to true.



178
179
180
# File 'lib/hoe.rb', line 178

def description_rdoc_hack
  @description_rdoc_hack
end

#description_sectionsObject

Optional: What sections from the readme to use for auto-description. Defaults to %w(description).



171
172
173
# File 'lib/hoe.rb', line 171

def description_sections
  @description_sections
end

#emailObject

MANDATORY: The author’s email address(es). (can be array)

Use the #developer method to fill in both author and email cleanly.



185
186
187
# File 'lib/hoe.rb', line 185

def email
  @email
end

#extra_depsObject

Optional: An array of rubygem dependencies.

extra_deps << ['blah', '~> 1.0']


192
193
194
# File 'lib/hoe.rb', line 192

def extra_deps
  @extra_deps
end

#extra_dev_depsObject

Optional: An array of rubygem developer dependencies.



197
198
199
# File 'lib/hoe.rb', line 197

def extra_dev_deps
  @extra_dev_deps
end

#extra_rdoc_filesObject

Optional: Extra files you want to add to RDoc.

.txt files are automatically included (excluding the obvious).



209
210
211
# File 'lib/hoe.rb', line 209

def extra_rdoc_files
  @extra_rdoc_files
end

#group_nameObject

Optional: The name of the group authoring the project. [default: name.downcase]



243
244
245
# File 'lib/hoe.rb', line 243

def group_name
  @group_name
end

#history_fileObject

Optional: The filename for the project history. [default: History.txt]



214
215
216
# File 'lib/hoe.rb', line 214

def history_file
  @history_file
end

#homepageObject

Optional: The homepage of the project. Auto-populates to the home key of the urls read from the README.txt



255
256
257
# File 'lib/hoe.rb', line 255

def homepage
  @homepage
end

#licensesObject

Optional: An array containing the license(s) under which this gem is released.

Warns and defaults to “MIT” if not set.



221
222
223
# File 'lib/hoe.rb', line 221

def licenses
  @licenses
end

#nameObject

MANDATORY: The name of the release.

Set via Hoe.spec.



228
229
230
# File 'lib/hoe.rb', line 228

def name
  @name
end

#post_install_messageObject

Optional: A post-install message to be displayed when gem is installed.



233
234
235
# File 'lib/hoe.rb', line 233

def post_install_message
  @post_install_message
end

#rdoc_optionsObject

Optional: rdoc arguments to be used when generating rdoc.



202
203
204
# File 'lib/hoe.rb', line 202

def rdoc_options
  @rdoc_options
end

#readme_fileObject

Optional: The filename for the project readme. [default: README.txt]



238
239
240
# File 'lib/hoe.rb', line 238

def readme_file
  @readme_file
end

#specObject

The Gem::Specification.



260
261
262
# File 'lib/hoe.rb', line 260

def spec
  @spec
end

#spec_extrasObject

Optional: A hash of extra values to set in the gemspec. Value may be a proc.

spec_extras[:required_rubygems_version] = '>= 1.3.2'

(tho, see #pluggable! if that’s all you want to do)



269
270
271
# File 'lib/hoe.rb', line 269

def spec_extras
  @spec_extras
end

#summaryObject

Optional: A short summary of the project. Auto-populates from the first sentence of the description.

See also: Hoe#description and Hoe.paragraphs_of.



277
278
279
# File 'lib/hoe.rb', line 277

def summary
  @summary
end

#summary_sentencesObject

Optional: Number of sentences from description for summary. Defaults to 1.



282
283
284
# File 'lib/hoe.rb', line 282

def summary_sentences
  @summary_sentences
end

#test_globsObject

Optional: An array of test file patterns [default: test/**/test_*.rb]



287
288
289
# File 'lib/hoe.rb', line 287

def test_globs
  @test_globs
end

#urlsObject

Optional: The urls of the project. This can be an array or (preferably) a hash. Auto-populates to the urls read from the beginning of README.txt.

See parse_urls for more details



296
297
298
# File 'lib/hoe.rb', line 296

def urls
  @urls
end

#versionObject

MANDATORY: The version. Don’t hardcode! use a constant in the project.



301
302
303
# File 'lib/hoe.rb', line 301

def version
  @version
end

Class Method Details

.add_include_dirs(*dirs) ⇒ Object

Add extra dirs to both $: and RUBY_FLAGS (for test runs and rakefile deps)



316
317
318
319
320
321
322
# File 'lib/hoe.rb', line 316

def self.add_include_dirs(*dirs)
  dirs = dirs.flatten
  include_dirs.concat dirs
  $:.unshift(*dirs)
  s = File::PATH_SEPARATOR
  RUBY_FLAGS.sub!(/-I/, "-I#{dirs.join(s)}#{s}")
end

.bad_pluginsObject

Returns plugins that could not be loaded by Hoe.load_plugins.



327
328
329
# File 'lib/hoe.rb', line 327

def self.bad_plugins
  @bad_plugins
end

.load_plugins(plugins = Hoe.plugins) ⇒ Object

Find and load all plugin files.

It is called at the end of hoe.rb



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/hoe.rb', line 336

def self.load_plugins plugins = Hoe.plugins
  @found  ||= {}
  @loaded ||= {}
  @files  ||= Gem.find_files "hoe/*.rb"

  @files.reverse.each do |path| # reverse so first one wins
    @found[File.basename(path, ".rb").intern] = path
  end

  :keep_doing_this while @found.map { |name, plugin|
    next unless plugins.include? name
    next if @loaded[name]
    begin
      warn "loading #{plugin}" if $DEBUG
      @loaded[name] = require plugin
    rescue LoadError => e
      warn "error loading #{plugin.inspect}: #{e.message}. skipping..."
    end
  }.any?

  bad_plugins = plugins - @loaded.keys
  bad_plugins.each do |bad_plugin|
    plugins.delete bad_plugin
  end

  @bad_plugins.concat bad_plugins
  @bad_plugins.uniq!

  return @loaded, @found
end

.normalize_names(project) ⇒ Object

Normalize a project name into the project, file, klass and test names that follow Ruby package naming guidelines.

Project names are lowercase with _ separating package parts and - separating extension parts.

File names are lowercase with _ separating pacagke parts and / separating extension parts. net-http-persistent becomes net/http/persistent.

Klass names are CamelCase with

separating extension parts.

Test klass names are same as Klass with Test prepended to each part.



381
382
383
384
385
386
387
388
389
# File 'lib/hoe.rb', line 381

def self.normalize_names project # :nodoc:
  project    = project.gsub(/([A-Z])/, '_\1').downcase.sub(/^_/, "")
  klass      = project.gsub(/(?:^|_)([a-z])/) { $1.upcase }
  klass      = klass.  gsub(/(?:^|-)([a-z])/) { "::#{$1.upcase}" }
  test_klass = klass.  gsub(/(^|::)([A-Z])/) { "#{$1}Test#{$2}" }
  file_name  = project.gsub(/-/, "/")

  return project, file_name, klass, test_klass
end

.plugin(*plugins) ⇒ Object

Activates plugins. If a plugin cannot be loaded it will be ignored.

Plugins may also be activated through a plugins array in ~/.hoerc. This should only be used for plugins that aren’t critical to your project and plugins that you want to use on other projects.



399
400
401
402
# File 'lib/hoe.rb', line 399

def self.plugin *plugins
  self.plugins.concat plugins
  self.plugins.uniq!
end

.pluginsObject

The list of active plugins.



407
408
409
# File 'lib/hoe.rb', line 407

def self.plugins
  @@plugins
end

.spec(name, &block) ⇒ Object

Execute the Hoe DSL to define your project’s Hoe specification (which interally creates a gem specification). All hoe attributes and methods are available within block. Eg:

Hoe.spec name do
  # ... project specific data ...
end


420
421
422
423
424
425
426
427
428
# File 'lib/hoe.rb', line 420

def self.spec name, &block
  Hoe.load_plugins

  spec = self.new name
  spec.activate_plugins
  spec.instance_eval(&block)
  spec.post_initialize
  spec # TODO: remove?
end

Instance Method Details

#activate_plugin_depsObject

Run all activate_*_deps methods for plugins



469
470
471
472
473
474
475
# File 'lib/hoe.rb', line 469

def activate_plugin_deps
  Hoe.plugins.each do |plugin|
    msg = "activate_#{plugin}_deps"
    warn msg if $DEBUG
    send msg if self.respond_to? msg
  end
end

#activate_pluginsObject

Activate plugin modules and add them to the current instance.



433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# File 'lib/hoe.rb', line 433

def activate_plugins
  with_config do |config, _|
    config_plugins = config["plugins"]
    break unless config_plugins
    Hoe.plugins.concat config_plugins.map(&:intern)
  end

  Hoe.load_plugins Hoe.plugins

  names = Hoe.constants.map(&:to_s)
  names.reject! { |n| n =~ /^[A-Z_]+$/ }

  names.each do |name|
    underscored = name.gsub(/(?<!^)(?=[A-Z])/, "_").downcase.intern
    next unless Hoe.plugins.include? underscored
    warn "extend #{name}" if $DEBUG
    self.extend Hoe.const_get(name)
  end

  initialize_plugins
end

#add_dependenciesObject

Add standard and user defined dependencies to the spec.



505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
# File 'lib/hoe.rb', line 505

def add_dependencies
  self.extra_deps     = normalize_deps extra_deps
  self.extra_dev_deps = normalize_deps extra_dev_deps

  case name
  when "hoe" then
    # do nothing? these deps are already in the hoe spec in the Rakefile
  else
    version = VERSION.split(/\./).first(2).join(".")
    dependency "hoe", "~> #{version}", :development
  end

  seen = {}

  extra_deps.each do |dep|
    next if seen[dep.first]
    seen[dep.first] = true

    spec.add_dependency(*dep)
  end

  extra_dev_deps.each do |dep|
    next if seen[dep.first]
    seen[dep.first] = true

    spec.add_development_dependency(*dep)
  end
end

#attr_accessorObject

Optional: Extra directories to use (eg for test runs). See Hoe.add_include_dirs.



311
# File 'lib/hoe.rb', line 311

mc.send :attr_accessor, :include_dirs

#check_for_versionObject

:nodoc:



601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
# File 'lib/hoe.rb', line 601

def check_for_version # :nodoc:
  return if self.version

  version    = nil
  version_re = /VERSION += +([\"\'])([\d][\w\.]+)\1/

  spec.files.each do |file|
    next unless File.exist? file
    version = File.read_utf(file)[version_re, 2] rescue nil
    break if version
  end

  spec.version = self.version = version if version

  unless self.version then
    spec.version = self.version = "0.borked"
    warn "** Add 'VERSION = \"x.y.z\"' to your code,"
    warn "   add a version to your hoe spec,"
    warn "   or fix your Manifest.txt"
  end
end

#define_specObject

Define the Gem::Specification.



544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
# File 'lib/hoe.rb', line 544

def define_spec
  self.spec = Gem::Specification.new do |s|
    dirs = Dir["lib"]

    manifest = read_manifest

    abort [
           "Manifest is missing or couldn't be read.",
           "The Manifest is kind of a big deal.",
           "Maybe you're using a gem packaged by a linux project.",
           "It seems like they enjoy breaking other people's code.",
           ].join "\n" unless manifest

    s.name                 = name
    s.version              = version if version
    s.summary              = summary
    s.email                = email
    s.homepage             = homepage || urls["home"] || urls.values.first

    s.description          = description
    s.files                = manifest
    s.bindir               = bindir || "bin"
    s.executables          = s.files.grep(/^#{s.bindir}/) { |f| File.basename(f) }
    s.require_paths        = dirs unless dirs.empty?
    s.rdoc_options         = rdoc_options
    s.post_install_message = post_install_message
    s.             = (urls.keys & URLS_TO_META_MAP.keys).map { |name|
      [URLS_TO_META_MAP[name], urls[name]]
    }.to_h if urls

    missing "Manifest.txt" if s.files.empty?

    case author
    when Array
      s.authors = author
    else
      s.author  = author
    end

    s.extra_rdoc_files += s.files.grep(/\.(txt|rdoc|md)$/)
    s.extra_rdoc_files.reject! { |f| f =~ %r%^(test|spec|vendor|template|data|tmp)/% }
    s.extra_rdoc_files += @extra_rdoc_files
  end

  check_for_version

  if licenses.empty?
    warn "Defaulting gemspec to MIT license."
    warn "Call license in hoe spec to change."
    license "MIT"
  end

  spec.licenses = licenses

  run_spec_extras
end

#dependency(name, version, type = :runtime) ⇒ Object

Add a dependency declaration to your spec. Pass :dev to type for developer dependencies.



489
490
491
492
493
494
495
496
497
498
499
500
# File 'lib/hoe.rb', line 489

def dependency name, version, type = :runtime
  raise "Unknown dependency type: #{type}" unless
    [:runtime, :dev, :development, :developer].include? type

  ary = if type == :runtime then
          extra_deps
        else
          extra_dev_deps
        end

  ary << [name, version]
end

#dependency_targetObject

Returns the proper dependency list for the thingy.



537
538
539
# File 'lib/hoe.rb', line 537

def dependency_target
  self.name == "hoe" ? extra_deps : extra_dev_deps
end

#developer(name, email) ⇒ Object

Convenience method to set add to both the author and email fields.



638
639
640
641
# File 'lib/hoe.rb', line 638

def developer name, email
  self.author << name
  self.email  << email
end

#have_gem?(name) ⇒ Boolean

Returns true if the gem name is installed.

Returns:



646
647
648
649
650
# File 'lib/hoe.rb', line 646

def have_gem? name
  Gem::Specification.find_by_name name.to_s
rescue Gem::LoadError
  false
end

#initialize_pluginsObject

Run all initialize_* methods for plugins



458
459
460
461
462
463
464
# File 'lib/hoe.rb', line 458

def initialize_plugins
  Hoe.plugins.each do |plugin|
    msg = "initialize_#{plugin}"
    warn msg if $DEBUG
    send msg if self.respond_to? msg
  end
end

#intuit_values(input) ⇒ Object

Intuit values from the readme and history files.



697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
# File 'lib/hoe.rb', line 697

def intuit_values input
  readme = input
             .lines
             .chunk { |l| l[/^(?:=+|#+)/] || "" }
             .map(&:last)
             .each_slice(2)
             .select { |k, v| k && v }
             .to_h { |k, v|
               kp = k.join.strip.chomp(":").sub(/(?:=+|#+)\s*/, '').downcase

               # keep key in value, but title case it
               v.prepend k.join.downcase.gsub(/\b[a-z]/, &:upcase)

               [kp, v.join.strip]
             }

  unless readme.empty? then
    desc     = readme.values_at(*description_sections).compact.join("\n\n")
    desc     = desc.lines.drop(2).join # drop first header (eg description)
    desc    += "\n\n==== To Install:\n" if description_rdoc_hack &&
      desc !~ /^==+ [A-Z]/
    summ     = desc.split(/\.\s+/).first(summary_sentences).join(". ")

    self.urls        ||= parse_urls(readme.values.first.lines.drop(1).join)
    self.description ||= desc
    self.summary     ||= summ
  else
    missing readme_file
  end

  self.changes ||= begin
                     h = File.read_utf(history_file)
                     h.split(/^(={2,}|\#{2,})/)[1..2].join.strip
                   rescue
                     missing history_file
                     ""
                   end
end

#license(name) ⇒ Object

Specify a license for your gem.

Call it multiple times if you are releasing under multiple licenses.


481
482
483
# File 'lib/hoe.rb', line 481

def license name
  self.licenses << name.to_s
end

#load_plugin_tasksObject

Load activated plugins by calling their define tasks method.



764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
# File 'lib/hoe.rb', line 764

def load_plugin_tasks
  bad = []

  $plugin_max = self.class.plugins.map { |s| s.to_s.size }.max

  self.class.plugins.each do |plugin|
    warn "define: #{plugin}" if $DEBUG

    old_tasks = Rake::Task.tasks.dup

    begin
      send "define_#{plugin}_tasks"
    rescue NoMethodError
      warn "warning: couldn't activate the #{plugin} plugin, skipping"

      bad << plugin
      next
    end

    (Rake::Task.tasks - old_tasks).each do |task|
      task.plugin = plugin
    end
  end
  @@plugins -= bad
end

#maybe_load_yaml(path) ⇒ Object

:nodoc:



966
967
968
969
970
971
972
973
974
975
976
# File 'lib/hoe.rb', line 966

def maybe_load_yaml path # :nodoc:
  if File.exist? path then
    if YAML.respond_to? :safe_load_file then
      YAML.safe_load_file path, permitted_classes: [Regexp, Symbol]
    else
      YAML.load_file path
    end
  else
    {}
  end
end

#missing(name) ⇒ Object

Raise about a file that is missing data or unparsable for intuiting values.



793
794
795
796
797
# File 'lib/hoe.rb', line 793

def missing name
  raise \
    "** #{name} is missing or in the wrong format for auto-intuiting." \
    "   run `sow blah` and look at its text files"
end

#normalize_deps(deps) ⇒ Object

Normalize the dependencies.



802
803
804
805
806
807
808
809
810
# File 'lib/hoe.rb', line 802

def normalize_deps deps
  deps = Array(deps)

  deps.each do |o|
    abort "ERROR: Add '~> x.y' to the '#{o}' dependency." if String === o
  end

  deps
end

#paragraphs_of(path, *paragraphs) ⇒ Object

Reads a file at path and spits out an array of the paragraphs specified.

changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
summary, *description = p.paragraphs_of('README.txt', 3, 3..8)


818
819
820
# File 'lib/hoe.rb', line 818

def paragraphs_of path, *paragraphs
  File.read_utf(path).delete("\r").split(/\n\n+/).values_at(*paragraphs)
end

#parse_urls(text) ⇒ Object

Parse the urls section of the readme file. Returns a hash or an array depending on the format of the section.

label1 :: url1
label2 :: url2
label3 :: url3

vs:

* url1
* url2
* url3

The hash format is preferred as it will be used to populate gem metadata. The array format will work, but will warn that you should update the readme.



754
755
756
757
758
759
# File 'lib/hoe.rb', line 754

def parse_urls text
  keys  = Regexp.union Hoe::URLS_TO_META_MAP.keys
  kv_re = /^\s*(#{keys})\s*::\s*<?([^>\s]+)>?/

  text.scan(kv_re).to_h
end

#pluggable!Object

Tell the world you’re a pluggable package (ie you require rubygems 1.3.1+)

This uses require_rubygems_version. Last one wins. Make sure you account for that.



828
829
830
831
# File 'lib/hoe.rb', line 828

def pluggable!
  abort "update rubygems to >= 1.3.1" unless  Gem.respond_to? :find_files
  require_rubygems_version ">= 1.3.1"
end

#plugin?(name) ⇒ Boolean

Is a plugin activated? Used for guarding missing plugins in your hoe spec:

Hoe.spec "blah" do
  if plugin? :enhancement then
    self.enhancement = true # or whatever...
  end
end

Returns:



843
844
845
# File 'lib/hoe.rb', line 843

def plugin? name
  self.class.plugins.include? name
end

#post_initializeObject

Finalize configuration



850
851
852
853
854
855
856
857
858
859
# File 'lib/hoe.rb', line 850

def post_initialize
  activate_plugin_deps
  unless skip_intuit_values?
    intuit_values File.read_utf readme_file if readme_file
  end
  validate_fields
  define_spec
  load_plugin_tasks
  add_dependencies
end

#read_manifestObject

Reads Manifest.txt and returns an Array of lines in the manifest.

Returns nil if no manifest was found.



866
867
868
# File 'lib/hoe.rb', line 866

def read_manifest
  File.read_utf("Manifest.txt").split(/\r?\n\r?/) rescue nil
end

#require_ruby_version(*versions) ⇒ Object

Declare that your gem requires a specific ruby version. Last one wins.



882
883
884
# File 'lib/hoe.rb', line 882

def require_ruby_version *versions
  spec_extras[:required_ruby_version] = versions
end

#require_rubygems_version(*versions) ⇒ Object Also known as: required_rubygems_version

Declare that your gem requires a specific rubygems version. Last one wins.



873
874
875
# File 'lib/hoe.rb', line 873

def require_rubygems_version *versions
  spec_extras[:required_rubygems_version] = versions
end

#ruby20!Object

Declare that this gem requires ruby to be in the 2.0+ family.



889
890
891
# File 'lib/hoe.rb', line 889

def ruby20!
  require_ruby_version "~> 2.0"
end

#ruby21!Object

Declare that this gem requires ruby to be in the 2.1+ family.



896
897
898
# File 'lib/hoe.rb', line 896

def ruby21!
  require_ruby_version "~> 2.1"
end

#ruby22!Object

Declare that this gem requires ruby to be in the 2.2+ family.



903
904
905
# File 'lib/hoe.rb', line 903

def ruby22!
  require_ruby_version "~> 2.2"
end

#ruby23!Object

Declare that this gem requires ruby to be in the 2.3+ family.



910
911
912
# File 'lib/hoe.rb', line 910

def ruby23!
  require_ruby_version "~> 2.3"
end

#run_spec_extrasObject

:nodoc:



623
624
625
626
627
628
629
630
631
632
633
# File 'lib/hoe.rb', line 623

def run_spec_extras # :nodoc:
  # Do any extra stuff the user wants
  self.spec_extras.each do |msg, val|
    case val
    when Proc
      val.call spec.send(msg)
    else
      spec.send "#{msg}=", val
    end
  end
end

#skip_intuit_values?Boolean

:nodoc:

Returns:



942
943
944
# File 'lib/hoe.rb', line 942

def skip_intuit_values? # :nodoc:
  %w[summary description homepage].all? { |field| send field }
end

#timebomb(n, m, finis = nil, start = nil) ⇒ Object

Provide a linear degrading value from n to m over start to finis dates. If not provided, start and finis will default to 1/1 and 12/31 of the current year.



922
923
924
925
926
927
928
929
930
# File 'lib/hoe.rb', line 922

def timebomb n, m, finis = nil, start = nil
  require "time"
  finis = Time.parse(finis || "#{Time.now.year}-12-31")
  start = Time.parse(start || "#{Time.now.year}-01-01")
  rest  = (finis - Time.now)
  full  = (finis - start)

  [((n - m) * rest / full).to_i + m, m].max
end

#validate_fieldsObject

Verify that mandatory fields are set.



935
936
937
938
939
940
# File 'lib/hoe.rb', line 935

def validate_fields
  %w[email author].each do |field|
    value = self.send(field)
    abort "Hoe #{field} value not set. aborting" if value.nil? or value.empty?
  end
end

#with_config {|config, rc| ... } ⇒ Object

Loads ~/.hoerc, merges it with a .hoerc in the current pwd (if any) and yields the configuration and its path

Yields:

  • (config, rc)


950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
# File 'lib/hoe.rb', line 950

def with_config
  config = Hoe::DEFAULT_CONFIG

  rc = File.expand_path("~/.hoerc")
  homeconfig = maybe_load_yaml rc

  config = config.merge homeconfig

  localrc = File.join Dir.pwd, ".hoerc"
  localconfig = maybe_load_yaml(localrc)

  config = config.merge localconfig

  yield config, rc
end