Module: Godmin::Resources::ResourceService

Extended by:
ActiveSupport::Concern
Includes:
BatchActions, Filters, Ordering, Pagination, Scopes
Defined in:
lib/godmin/resources/resource_service.rb,
lib/godmin/resources/resource_service/scopes.rb,
lib/godmin/resources/resource_service/filters.rb,
lib/godmin/resources/resource_service/ordering.rb,
lib/godmin/resources/resource_service/pagination.rb,
lib/godmin/resources/resource_service/batch_actions.rb

Defined Under Namespace

Modules: BatchActions, ClassMethods, Filters, Ordering, Pagination, Scopes

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Scopes

#apply_scope, #scope, #scope=, #scope_count, #scoped_by?

Methods included from Pagination

#apply_pagination, #paginator, #per_page

Methods included from Ordering

#apply_order

Methods included from Filters

#apply_filters

Methods included from BatchActions

#batch_action, #batch_action?

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



18
19
20
# File 'lib/godmin/resources/resource_service.rb', line 18

def options
  @options
end

Instance Method Details

#attrs_for_exportObject



81
82
83
# File 'lib/godmin/resources/resource_service.rb', line 81

def attrs_for_export
  self.class.attrs_for_export
end

#attrs_for_formObject



77
78
79
# File 'lib/godmin/resources/resource_service.rb', line 77

def attrs_for_form
  self.class.attrs_for_form
end

#attrs_for_indexObject



69
70
71
# File 'lib/godmin/resources/resource_service.rb', line 69

def attrs_for_index
  self.class.attrs_for_index
end

#attrs_for_showObject



73
74
75
# File 'lib/godmin/resources/resource_service.rb', line 73

def attrs_for_show
  self.class.attrs_for_show
end

#build_resource(params) ⇒ Object



53
54
55
# File 'lib/godmin/resources/resource_service.rb', line 53

def build_resource(params)
  resources_relation.new(params)
end

#create_resource(resource) ⇒ Object



57
58
59
# File 'lib/godmin/resources/resource_service.rb', line 57

def create_resource(resource)
  resource.save
end

#destroy_resource(resource) ⇒ Object



65
66
67
# File 'lib/godmin/resources/resource_service.rb', line 65

def destroy_resource(resource)
  resource.destroy
end

#find_resource(id) ⇒ Object



49
50
51
# File 'lib/godmin/resources/resource_service.rb', line 49

def find_resource(id)
  resources_relation.find(id)
end

#initialize(options = {}) ⇒ Object



20
21
22
# File 'lib/godmin/resources/resource_service.rb', line 20

def initialize(options = {})
  @options = options
end

#resource_classObject

TODO: should this raise its own error?



25
26
27
# File 'lib/godmin/resources/resource_service.rb', line 25

def resource_class
  @options[:resource_class] || resource_class_name.constantize
end

#resource_class_nameObject



29
30
31
# File 'lib/godmin/resources/resource_service.rb', line 29

def resource_class_name
  self.class.name.demodulize.chomp("Service")
end

#resources(params) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/godmin/resources/resource_service.rb', line 37

def resources(params)
  apply_pagination(
    params[:page], apply_order(
      params[:order], apply_filters(
        params[:filter], apply_scope(
          params[:scope], resources_relation
        )
      )
    )
  )
end

#resources_relationObject



33
34
35
# File 'lib/godmin/resources/resource_service.rb', line 33

def resources_relation
  resource_class.all
end

#update_resource(resource, params) ⇒ Object



61
62
63
# File 'lib/godmin/resources/resource_service.rb', line 61

def update_resource(resource, params)
  resource.update(params)
end