Sha256: 8a7718feabb58f8960fd103a9d5143d587f217398910bda83556c485605669cb

Contents?: true

Size: 851 Bytes

Versions: 3

Compression:

Stored size: 851 Bytes

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 = ActiveSupport::Dependencies.ref(@class_name)
      
      @path = (options[:path] || resource).to_s
      @path_prefix = options[:path_prefix]
      
      @controller = options[:controller] || 'governor/articles'
    end
    
    def fullpath
      "#{@path_prefix}/#{@path}".squeeze("/")
    end
    
    def to
      @ref.get
    end
    
    def humanize
      @singular.to_s.humanize
    end
    
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
governor-0.2.0 lib/governor/mapping.rb
governor-0.1.1 lib/governor/mapping.rb
governor-0.1.0 lib/governor/mapping.rb