Module: ExpressTemplates::Components::Capabilities::Resourceful

Included in:
Forms::ExpressForm, ResourcefulContainer
Defined in:
lib/express_templates/components/capabilities/resourceful.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/express_templates/components/capabilities/resourceful.rb', line 7

def self.included(base)
  base.class_eval do
    has_argument :id, "The name of the collection. A resourceful component will look for the resource based on the ID.", type: :symbol, optional: false
    has_option :collection, 'Provide an explicit collection as a resource.'
    has_option :collection_path, 'Provide an explicit path for the collection resource.', type: [:string, :proc]
    has_option :resource_class, 'Overrides namespaced resource_class for using resources from a different module or namespace.'
    has_option :resource_path, 'Overides the resource path which is otherwise inferred from the class name.', type: [:string, :proc]
    has_option :path_prefix, 'Rarely used.  Override inferred path_prefix for path helpers.'
    # note there is some duplication here.
    # resource_path can be specified as a proc which can specify a namespace
    # TODO: investigate which approach is better and deprecate if desirable
    has_option :namespace, 'Rarely used.  Overrides inferred namespace for resources.'
  end
end

Instance Method Details

#namespaceObject



22
23
24
# File 'lib/express_templates/components/capabilities/resourceful.rb', line 22

def namespace
  config[:namespace] || infer_namespace
end

#path_prefixObject



26
27
28
# File 'lib/express_templates/components/capabilities/resourceful.rb', line 26

def path_prefix
  config[:path_prefix] || infer_path_prefix
end

#resource_classObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/express_templates/components/capabilities/resourceful.rb', line 30

def resource_class
  resource_class = config[:resource_class] || _namespaced_resource_class
  if Object.const_defined?(resource_class)
    resource_class.constantize
  else
    message = [
      "Could not find the class `#{resource_class}`.",
      "You may need to define the option `:resource_class`.",
    ].join(" ")
    fail ArgumentError, message
  end
end