Module: Brigit::Listable::ClassMethods

Defined in:
lib/brigit/listable.rb

Instance Method Summary collapse

Instance Method Details

#[](name) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/brigit/listable.rb', line 11

def [](name)
  matching = list.select { |klass| klass.name =~ /^#{Regexp.quote name}/io }
  return false unless matching.any?
  if matching.size > 1
    HighLine.say %|<%= color "Too many matches for `#{name}'", :red %>|
    return false
  end
  matching.first
end

#inherited(klass) ⇒ Object



21
22
23
# File 'lib/brigit/listable.rb', line 21

def inherited(klass)
  list << klass
end

#listObject



25
26
27
# File 'lib/brigit/listable.rb', line 25

def list
  @list ||= []
end

#listingObject



29
30
31
32
33
# File 'lib/brigit/listable.rb', line 29

def listing
  list.map do |l|
    block_given? ? yield(l.name) : l.name
  end.join(', ')
end

#nameObject



35
36
37
# File 'lib/brigit/listable.rb', line 35

def name
  to_s.sub(/^(?:.+::)?(.+?)[A-Z][a-z]+$/, '\1').downcase
end