Sha256: 12c79a5ddb774234182ac299293f7092998256999292c08a688035bbfacf0980

Contents?: true

Size: 828 Bytes

Versions: 6

Compression:

Stored size: 828 Bytes

Contents

module AppScrollsScrolls
  module Scrolls
    @@categories = {}
    @@list = {}
    
    def self.add(scroll)
      AppScrollsScrolls::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

6 entries across 6 versions & 1 rubygems

Version Path
appscrolls-0.8.3 lib/appscrolls/scrolls.rb
appscrolls-0.8.2 lib/appscrolls/scrolls.rb
appscrolls-0.8.1 lib/appscrolls/scrolls.rb
appscrolls-0.8.0 lib/appscrolls/scrolls.rb
appscrolls-0.7.1 lib/appscrolls/scrolls.rb
appscrolls-0.7.0 lib/appscrolls/scrolls.rb