Class: Clitopic::Topic::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/clitopic/topic/base.rb

Direct Known Subclasses

Command::ClitoTopic, Help

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}, force = false) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/clitopic/topic/base.rb', line 10

def initialize(opts={}, force=false)
  opts = {hidden: false}.merge(opts)
  if !opts.has_key?(:name)
    raise ArgumentError.new("missing Topic name")
  end
  @description = opts[:description]
  @short_description = opts[:short_description]
  @name = opts[:name]
  @hidden = opts[:hidden]
  @banner = opts[:banner]
end

Class Attribute Details

.instanceObject

Returns the value of attribute instance.



62
63
64
# File 'lib/clitopic/topic/base.rb', line 62

def instance
  @instance
end

Instance Attribute Details

Returns the value of attribute banner.



8
9
10
# File 'lib/clitopic/topic/base.rb', line 8

def banner
  @banner
end

#description(arg = nil) ⇒ Object

Returns the value of attribute description.



8
9
10
# File 'lib/clitopic/topic/base.rb', line 8

def description
  @description
end

#hidden(arg = false) ⇒ Object Also known as: hidden?

Returns the value of attribute hidden.



8
9
10
# File 'lib/clitopic/topic/base.rb', line 8

def hidden
  @hidden
end

#name(arg = nil) ⇒ Object

Returns the value of attribute name.



8
9
10
# File 'lib/clitopic/topic/base.rb', line 8

def name
  @name
end

#short_descriptionObject

Returns the value of attribute short_description.



8
9
10
# File 'lib/clitopic/topic/base.rb', line 8

def short_description
  @short_description
end

Class Method Details

.option(name, *args, &blk) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/clitopic/topic/base.rb', line 63

def option(name, *args, &blk)
  opt = Clitopic::Utils.parse_option(name, *args, &blk)
  if !opt[:default].nil?
    options[name] = opt[:default]
  end
  topic_options << opt
end

.optionsObject



58
59
60
# File 'lib/clitopic/topic/base.rb', line 58

def options
  @options ||= {}
end

.register(opts = {}, force = false) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/clitopic/topic/base.rb', line 75

def register(opts={}, force=false)
  topic = self.new(opts, force)
  if Topics.topics.has_key?(topic.name) && !force
    raise TopicAlreadyExists.new ("Topic: #{topic.name} already exists: #{Topics[topic.name].class.name}")
  else
    if self.class != Clitopic::Topic::Base
      @instance = topic
    end
    Topics[topic.name] = topic
  end
end

.topic_optionsObject



71
72
73
# File 'lib/clitopic/topic/base.rb', line 71

def topic_options
  @topic_options ||= []
end

Instance Method Details

#commandsObject



22
23
24
# File 'lib/clitopic/topic/base.rb', line 22

def commands
  @commands ||= {}
end

#topic_optionsObject



48
49
50
# File 'lib/clitopic/topic/base.rb', line 48

def topic_options
  self.class.topic_options
end