class Governor::Mapping

Attributes

class_name[R]
controller[R]
path[R]
path_names[R]
plural[R]
resource[R]
singular[R]

Public Class Methods

new(resource, options = {}) click to toggle source
# File lib/governor/mapping.rb, line 6
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

Public Instance Methods

humanize() click to toggle source

Presents a human-readable identifier of the resource type.

# File lib/governor/mapping.rb, line 31
def humanize
  @singular.to_s.humanize
end
to() click to toggle source

Provides the resource class.

# File lib/governor/mapping.rb, line 22
def to
  if defined?(ActiveSupport::Dependencies::ClassCache)
    @ref.get @class_name
  else
    @ref.get
  end
end