Class: Gem::Release::Cmds::Base

Inherits:
Struct
  • Object
show all
Extended by:
Helper::String
Includes:
Helper, Helper::Hash, Helper::String, Registry
Defined in:
lib/gem/release/cmds/base.rb

Direct Known Subclasses

Bootstrap, Bump, Gemspec, Github, Release, Tag

Constant Summary collapse

WIDTH =
70
DEFAULTS =
{
  color:   true,
  pretend: false,
  quiet:   false
}.freeze

Constants included from Helper::Hash

Helper::Hash::MERGER

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helper::String

camelize, underscore, wrap

Methods included from Helper

#abort, #cmd, #gem_cmd, #run

Methods included from Helper::Hash

#deep_merge, #except, #only, #symbolize_keys

Methods included from Registry

included

Constructor Details

#initialize(context, args, opts) ⇒ Base

Returns a new instance of Base.


80
81
82
83
# File 'lib/gem/release/cmds/base.rb', line 80

def initialize(context, args, opts)
  opts = defaults.merge(opts)
  super
end

Instance Attribute Details

#argsObject

Returns the value of attribute args

Returns:

  • (Object)

    the current value of args


9
10
11
# File 'lib/gem/release/cmds/base.rb', line 9

def args
  @args
end

#contextObject

Returns the value of attribute context

Returns:

  • (Object)

    the current value of context


9
10
11
# File 'lib/gem/release/cmds/base.rb', line 9

def context
  @context
end

#gemObject (readonly)

Returns the value of attribute gem


78
79
80
# File 'lib/gem/release/cmds/base.rb', line 78

def gem
  @gem
end

#optsObject

Returns the value of attribute opts

Returns:

  • (Object)

    the current value of opts


9
10
11
# File 'lib/gem/release/cmds/base.rb', line 9

def opts
  @opts
end

Class Method Details

.arg(name, summary) ⇒ Object


19
20
21
# File 'lib/gem/release/cmds/base.rb', line 19

def arg(name, summary)
  args << [name, summary]
end

.argsObject


23
24
25
# File 'lib/gem/release/cmds/base.rb', line 23

def args
  @args ||= []
end

.default(opt) ⇒ Object


41
42
43
# File 'lib/gem/release/cmds/base.rb', line 41

def default(opt)
  Base::DEFAULTS[opt] || self::DEFAULTS[opt]
end

.descr(opt) ⇒ Object


35
36
37
38
39
# File 'lib/gem/release/cmds/base.rb', line 35

def descr(opt)
  descr = self::DESCR[opt]
  descr = "#{descr} (default: #{default(opt)})" if default(opt)
  descr
end

.description(description = nil) ⇒ Object


55
56
57
# File 'lib/gem/release/cmds/base.rb', line 55

def description(description = nil)
  description ? @description = wrap(description, WIDTH) : @description
end

.inherited(cmd) ⇒ Object


15
16
17
# File 'lib/gem/release/cmds/base.rb', line 15

def inherited(cmd)
  cmd.register underscore(cmd.name.split('::').last)
end

.opt(*args, &block) ⇒ Object


27
28
29
# File 'lib/gem/release/cmds/base.rb', line 27

def opt(*args, &block)
  opts << [args, block]
end

.optsObject


31
32
33
# File 'lib/gem/release/cmds/base.rb', line 31

def opts
  @opts ||= superclass != self.class && superclass.respond_to?(:opts) ? superclass.opts.dup : []
end

.summary(summary = nil) ⇒ Object


51
52
53
# File 'lib/gem/release/cmds/base.rb', line 51

def summary(summary = nil)
  summary ? @summary = wrap(summary, WIDTH) : @summary || '[summary]'
end

.usage(usage = nil) ⇒ Object


45
46
47
# File 'lib/gem/release/cmds/base.rb', line 45

def usage(usage = nil)
  usage ? @usage = usage : @usage || '[usage]'
end

Instance Method Details

#configObject


111
112
113
# File 'lib/gem/release/cmds/base.rb', line 111

def config
  context.config.for(registry_key)
end

#defaultsObject


115
116
117
# File 'lib/gem/release/cmds/base.rb', line 115

def defaults
  self.class.const_defined?(:DEFAULTS) ? self.class::DEFAULTS : {}
end

#in_dirsObject


85
86
87
88
89
90
# File 'lib/gem/release/cmds/base.rb', line 85

def in_dirs
  context.in_dirs(args, opts) do |name|
    @gem = Context::Gem.new(name)
    yield
  end
end

#in_gem_dirsObject


92
93
94
95
96
97
# File 'lib/gem/release/cmds/base.rb', line 92

def in_gem_dirs
  context.in_gem_dirs(args, opts) do |name|
    @gem = Context::Gem.new(name)
    yield
  end
end

#pretend?Boolean

Returns:

  • (Boolean)

99
100
101
# File 'lib/gem/release/cmds/base.rb', line 99

def pretend?
  !!opts[:pretend]
end

#quiet?Boolean

Returns:

  • (Boolean)

103
104
105
# File 'lib/gem/release/cmds/base.rb', line 103

def quiet?
  opts[:quiet] || opts[:silent]
end