Class: Governor::Mapping
- Inherits:
-
Object
- Object
- Governor::Mapping
- Defined in:
- lib/governor/mapping.rb
Instance Attribute Summary collapse
-
#class_name ⇒ Object
readonly
Returns the value of attribute class_name.
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#path_names ⇒ Object
readonly
Returns the value of attribute path_names.
-
#plural ⇒ Object
(also: #resource)
readonly
Returns the value of attribute plural.
-
#singular ⇒ Object
readonly
Returns the value of attribute singular.
Instance Method Summary collapse
-
#humanize ⇒ Object
Presents a human-readable identifier of the resource type.
-
#initialize(resource, options = {}) ⇒ Mapping
constructor
A new instance of Mapping.
-
#to ⇒ Object
Provides the resource class.
Constructor Details
permalink #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, = {}) @plural = ([:as] ? "#{[:as]}_#{resource}" : resource).to_sym @singular = ([:singular] || @plural.to_s.singularize).to_sym @class_name = ([: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 = ([:path] || resource).to_s @path_prefix = [:path_prefix] @controller = [:controller] || 'governor/articles' end |
Instance Attribute Details
permalink #class_name ⇒ Object (readonly)
Returns the value of attribute class_name.
3 4 5 |
# File 'lib/governor/mapping.rb', line 3 def class_name @class_name end |
permalink #controller ⇒ Object (readonly)
Returns the value of attribute controller.
3 4 5 |
# File 'lib/governor/mapping.rb', line 3 def controller @controller end |
permalink #path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/governor/mapping.rb', line 3 def path @path end |
permalink #path_names ⇒ Object (readonly)
Returns the value of attribute path_names.
3 4 5 |
# File 'lib/governor/mapping.rb', line 3 def path_names @path_names end |
permalink #plural ⇒ Object (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 |
permalink #singular ⇒ Object (readonly)
Returns the value of attribute singular.
3 4 5 |
# File 'lib/governor/mapping.rb', line 3 def singular @singular end |
Instance Method Details
permalink #humanize ⇒ Object
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 |
permalink #to ⇒ Object
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 |