Class: Governor::Mapping

Inherits:
Object
  • Object
show all
Defined in:
lib/governor/mapping.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, options = {}) ⇒ Mapping

Returns a new instance of Mapping.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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

Instance Attribute Details

#class_nameObject (readonly)

Returns the value of attribute class_name.



3
4
5
# File 'lib/governor/mapping.rb', line 3

def class_name
  @class_name
end

#controllerObject (readonly)

Returns the value of attribute controller.



3
4
5
# File 'lib/governor/mapping.rb', line 3

def controller
  @controller
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/governor/mapping.rb', line 3

def path
  @path
end

#path_namesObject (readonly)

Returns the value of attribute path_names.



3
4
5
# File 'lib/governor/mapping.rb', line 3

def path_names
  @path_names
end

#pluralObject (readonly) Also known as: resource

Returns the value of attribute plural.



3
4
5
# File 'lib/governor/mapping.rb', line 3

def plural
  @plural
end

#singularObject (readonly)

Returns the value of attribute singular.



3
4
5
# File 'lib/governor/mapping.rb', line 3

def singular
  @singular
end

Instance Method Details

#humanizeObject

Presents a human-readable identifier of the resource type.



31
32
33
# File 'lib/governor/mapping.rb', line 31

def humanize
  @singular.to_s.humanize
end

#toObject

Provides the resource class.



22
23
24
25
26
27
28
# File 'lib/governor/mapping.rb', line 22

def to
  if defined?(ActiveSupport::Dependencies::ClassCache)
    @ref.get @class_name
  else
    @ref.get
  end
end