Module: LazyCrud::ClassMethods

Includes:
Constants
Defined in:
lib/lazy_crud/class_methods.rb

Constant Summary

Constants included from Constants

LazyCrud::Constants::ACTIONS_WITH_HOOKS

Instance Method Summary collapse

Instance Method Details

#set_default_resourcesObject

determine default resource / pareent resource (if applicable) based on the naming convention e.g.: Parent::ModelController



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/lazy_crud/class_methods.rb', line 22

def set_default_resources
  name = self.name
  namespaced_names = name.split(/::|Controller/)

  model_name = namespaced_names.pop.try(:singularize)
  parent_name = namespaced_names.join('::').try(:singularize)

  if model_name.present?
    set_resource model_name.constantize
  else
    raise "#{model_name} based on #{name} does not exist."
  end

  if parent_name.present?
    parent_klass = parent_name.safe_constantize
    if parent_klass
      set_resource_parent parent_klass
    else
      logger.debug "[lazy_crud] #{parent_name} could not be found as a class / module."
    end
  end
end

#set_param_whitelist(*param_list) ⇒ Object

the list of parameters to allow through the strong parameter filter



46
47
48
# File 'lib/lazy_crud/class_methods.rb', line 46

def set_param_whitelist(*param_list)
  self.param_whitelist = param_list
end

#set_resource(klass) ⇒ Object

all REST actions will take place on an instance of this class



6
7
8
# File 'lib/lazy_crud/class_methods.rb', line 6

def set_resource(klass)
  self.resource_class = klass
end

#set_resource_parent(klass) ⇒ Object

for scoping the resource useful for nested routes, such as /event/:event_id/package/:package_id where Event would be the parent class and would scope the package



15
16
17
# File 'lib/lazy_crud/class_methods.rb', line 15

def set_resource_parent(klass)
  self.parent_class = klass
end