Class: Bourdain::Helpers::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/bourdain/helpers/registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



9
10
11
# File 'lib/bourdain/helpers/registry.rb', line 9

def initialize
  @config = Hash.new { |default, key| default[key] = Set.new }
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/bourdain/helpers/registry.rb', line 7

def config
  @config
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/bourdain/helpers/registry.rb', line 7

def name
  @name
end

Instance Method Details

#details(namespace) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/bourdain/helpers/registry.rb', line 43

def details namespace
  specs = specs(namespace)
  max_name_width  = specs.sort_by { |s| s[:name].to_s.length }.last[:name].length
  max_name_width += 2
  specs.map do |spec|
    "#{spec[:name].rjust(max_name_width)}: #{spec[:desc]}"
  end
end

#klass(namespace, name) ⇒ Object



31
32
33
34
35
# File 'lib/bourdain/helpers/registry.rb', line 31

def klass namespace, name
  @config[namespace].select do |klass|
    Bourdain::Helpers::UsageParser.parse(klass.raw_usage)[:name] == name
  end.shift
end

#map(namespace, &block) ⇒ Object



21
22
23
# File 'lib/bourdain/helpers/registry.rb', line 21

def map namespace, &block
  @config[namespace].map(&block)
end

#namespace(namespace) ⇒ Object



17
18
19
# File 'lib/bourdain/helpers/registry.rb', line 17

def namespace namespace
  @config[namespace].to_a
end

#register(namespace, klass) ⇒ Object



13
14
15
# File 'lib/bourdain/helpers/registry.rb', line 13

def register namespace, klass
  @config[namespace].add(klass)
end

#spec(namespace, name) ⇒ Object



37
38
39
40
41
# File 'lib/bourdain/helpers/registry.rb', line 37

def spec namespace, name
  specs(namespace).select do |spec|
    spec[:name] == name
  end.shift
end

#specs(namespace) ⇒ Object



25
26
27
28
29
# File 'lib/bourdain/helpers/registry.rb', line 25

def specs namespace
  @config[namespace].map do |klass|
    Bourdain::Helpers::UsageParser.parse klass.raw_usage
  end
end