Sha256: 1148b01a56b951fd648713492cbb83af6559536165340b7a701578ab9ca9e72e

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

module Governor
  class Mapping
    attr_reader :singular, :plural, :path, :controller, :path_names, :class_name
    alias :resource :plural
    
    def initialize(resource, options = {})
      @plural   = (options[:as] ? "#{options[:as]}_#{resource}" : resource).to_sym
      @singular = (options[:singular] || @plural.to_s.singularize).to_sym
      
      @class_name = (options[:class_name] || resource.to_s.classify).to_s
      @ref = defined?(ActiveSupport::Dependencies::ClassCache) ?
        ActiveSupport::Dependencies::Reference.store(@class_name) :
        ActiveSupport::Dependencies.ref(@class_name)
      
      @path = (options[:path] || resource).to_s
      @path_prefix = options[:path_prefix]
      
      @controller = options[:controller] || 'governor/articles'
    end
    
    # Provides the resource class.
    def to
      if defined?(ActiveSupport::Dependencies::ClassCache)
        @ref.get @class_name
      else
        @ref.get
      end
    end
    
    # Presents a human-readable identifier of the resource type.
    def humanize
      @singular.to_s.humanize
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
governor-0.5.7 lib/governor/mapping.rb
governor-0.5.6 lib/governor/mapping.rb
governor-0.5.5 lib/governor/mapping.rb
governor-0.5.4 lib/governor/mapping.rb