Sha256: fb05558bbd88721ba29de10eaf091df001c32d0941c99e853153b8ce57f3dc32

Contents?: true

Size: 816 Bytes

Versions: 3

Compression:

Stored size: 816 Bytes

Contents

module RailsWizard
  module Scrolls
    @@categories = {}
    @@list = {}
    
    def self.add(scroll)
      RailsWizard::Scrolls.const_set ActiveSupport::Inflector.camelize(scroll.key), scroll
      @@list[scroll.key] = scroll
      (@@categories[scroll.category.to_s] ||= []) << scroll.key
      @@categories[scroll.category.to_s].uniq!
      scroll
    end

    def self.[](key)
      @@list[key.to_s]
    end

    def self.list
      @@list.keys.sort
    end

    def self.list_classes
      @@list.values.sort_by{|c| c.key}
    end

    def self.categories
      @@categories.keys.sort
    end

    def self.for(category)
      (@@categories[category.to_s] || []).sort
    end

    def self.remove_from_category(category, scroll)
      (@@categories[category.to_s] ||= []).delete(scroll.key)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ey_rails_wizard-0.6.0 lib/rails_wizard/scrolls.rb
ey_rails_wizard-0.5.0 lib/rails_wizard/scrolls.rb
ey_rails_wizard-0.4.0 lib/rails_wizard/scrolls.rb