Class: Drawers::ResourceParts
- Inherits:
-
Object
- Object
- Drawers::ResourceParts
- Defined in:
- lib/drawers/resource_parts.rb
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.
28 29 30 |
# File 'lib/drawers/resource_parts.rb', line 28 def initialize(name) @qualified_name = name end |
Instance Attribute Details
#class_path ⇒ Object (readonly)
Returns the value of attribute class_path.
4 5 6 |
# File 'lib/drawers/resource_parts.rb', line 4 def class_path @class_path end |
#named_resource_type ⇒ Object (readonly)
Returns the value of attribute named_resource_type.
4 5 6 |
# File 'lib/drawers/resource_parts.rb', line 4 def named_resource_type @named_resource_type end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
4 5 6 |
# File 'lib/drawers/resource_parts.rb', line 4 def namespace @namespace end |
#resource_name ⇒ Object (readonly)
Returns the value of attribute resource_name.
4 5 6 |
# File 'lib/drawers/resource_parts.rb', line 4 def resource_name @resource_name end |
#resource_type ⇒ Object (readonly)
Returns the value of attribute resource_type.
4 5 6 |
# File 'lib/drawers/resource_parts.rb', line 4 def resource_type @resource_type end |
Class Method Details
.call(name) ⇒ Object
21 22 23 24 25 |
# File 'lib/drawers/resource_parts.rb', line 21 def call(name) resource = new(name) resource.call resource end |
.from_name(name) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/drawers/resource_parts.rb', line 9 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
32 33 34 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 |
# File 'lib/drawers/resource_parts.rb', line 32 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 |