Sha256: 93721b9157c28c45fd2c5e3a95077737c84d58cfa6ec2351b53513be970c6855

Contents?: true

Size: 1.19 KB

Versions: 22

Compression:

Stored size: 1.19 KB

Contents

require 'set'


module Bourdain
  module Helpers
    class Registry
      attr_reader :name, :config

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

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

      def namespace namespace
        @config[namespace].to_a
      end

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

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

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

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

      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
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
bourdain-1.6.3 lib/bourdain/helpers/registry.rb
bourdain-1.6.2 lib/bourdain/helpers/registry.rb
bourdain-1.6.1 lib/bourdain/helpers/registry.rb
bourdain-1.6.0 lib/bourdain/helpers/registry.rb
bourdain-1.5.1 lib/bourdain/helpers/registry.rb
bourdain-1.5.0 lib/bourdain/helpers/registry.rb
bourdain-1.4.1 lib/bourdain/helpers/registry.rb
bourdain-1.4.0 lib/bourdain/helpers/registry.rb
bourdain-1.3.3 lib/bourdain/helpers/registry.rb
bourdain-1.3.2 lib/bourdain/helpers/registry.rb
bourdain-1.3.1 lib/bourdain/helpers/registry.rb
bourdain-1.3.0 lib/bourdain/helpers/registry.rb
bourdain-1.2.22 lib/bourdain/helpers/registry.rb
bourdain-1.2.21 lib/bourdain/helpers/registry.rb
bourdain-1.2.20 lib/bourdain/helpers/registry.rb
bourdain-1.2.19 lib/bourdain/helpers/registry.rb
bourdain-1.2.18 lib/bourdain/helpers/registry.rb
bourdain-1.2.17 lib/bourdain/helpers/registry.rb
bourdain-1.2.16 lib/bourdain/helpers/registry.rb
bourdain-1.2.15 lib/bourdain/helpers/registry.rb