Class: Bourdain::Helpers::Registry
- Inherits:
-
Object
- Object
- Bourdain::Helpers::Registry
- Defined in:
- lib/bourdain/helpers/registry.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #details(namespace) ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #klass(namespace, name) ⇒ Object
- #map(namespace, &block) ⇒ Object
- #namespace(namespace) ⇒ Object
- #register(namespace, klass) ⇒ Object
- #spec(namespace, name) ⇒ Object
- #specs(namespace) ⇒ Object
Constructor Details
#initialize ⇒ Registry
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
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/bourdain/helpers/registry.rb', line 7 def config @config end |
#name ⇒ Object (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 |