Class: RailsModuleUnification::ResourceParts
- Inherits:
-
Object
- Object
- RailsModuleUnification::ResourceParts
- Defined in:
- lib/rails_module_unification/resource_parts.rb
Constant Summary collapse
- RESOURCE_SUFFIX_NAMES =
RailsModuleUnification::DependencyExtensions::RESOURCE_SUFFIX_NAMES
- QUALIFIED_NAME_SPLIT =
RailsModuleUnification::DependencyExtensions::QUALIFIED_NAME_SPLIT
Instance Attribute Summary collapse
-
#class_path ⇒ Object
readonly
Returns the value of attribute class_path.
-
#named_resource_type ⇒ Object
readonly
Returns the value of attribute named_resource_type.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#resource_name ⇒ Object
readonly
Returns the value of attribute resource_name.
-
#resource_type ⇒ Object
readonly
Returns the value of attribute resource_type.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(name) ⇒ ResourceParts
constructor
A new instance of ResourceParts.
Constructor Details
#initialize(name) ⇒ ResourceParts
Returns a new instance of ResourceParts.
31 32 33 |
# File 'lib/rails_module_unification/resource_parts.rb', line 31 def initialize(name) @qualified_name = name end |
Instance Attribute Details
#class_path ⇒ Object (readonly)
Returns the value of attribute class_path.
7 8 9 |
# File 'lib/rails_module_unification/resource_parts.rb', line 7 def class_path @class_path end |
#named_resource_type ⇒ Object (readonly)
Returns the value of attribute named_resource_type.
7 8 9 |
# File 'lib/rails_module_unification/resource_parts.rb', line 7 def named_resource_type @named_resource_type end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
7 8 9 |
# File 'lib/rails_module_unification/resource_parts.rb', line 7 def namespace @namespace end |
#resource_name ⇒ Object (readonly)
Returns the value of attribute resource_name.
7 8 9 |
# File 'lib/rails_module_unification/resource_parts.rb', line 7 def resource_name @resource_name end |
#resource_type ⇒ Object (readonly)
Returns the value of attribute resource_type.
7 8 9 |
# File 'lib/rails_module_unification/resource_parts.rb', line 7 def resource_type @resource_type end |
Class Method Details
.call(name) ⇒ Object
24 25 26 27 28 |
# File 'lib/rails_module_unification/resource_parts.rb', line 24 def call(name) resource = new(name) resource.call resource end |
.from_name(name) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rails_module_unification/resource_parts.rb', line 12 def from_name(name) resource = call(name) [ resource.namespace, resource.resource_name, resource.resource_type, resource.named_resource_type, resource.class_path ] end |
Instance Method Details
#call ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rails_module_unification/resource_parts.rb', line 35 def call # if this is not part of a resource, don't even bother return unless index_of_resource_type # Api, V2, Post, Operations, Update # => Operations @resource_type = qualified_parts[index_of_resource_type] # Api, V2, Post, Operations, Update # => Posts # # Posts, Controller # => Posts original_resource_name = qualified_parts[index_of_resource_type - 1] @resource_name = original_resource_name.pluralize # Posts_Controller # Post_Operations @named_resource_type = "#{original_resource_name}_#{@resource_type}" # Api, V2, Post, Operations, Update # => Api, V2 namespace_index = index_of_resource_type - 1 @namespace = namespace_index < 1 ? '' : qualified_parts.take(namespace_index) # Api, V2, Post, Operations, Update # => Update class_index = index_of_resource_type + 1 @class_path = class_index < 1 ? '' : qualified_parts.drop(class_index) end |