Module: Godmin::Resources::ResourceService

Extended by:
ActiveSupport::Concern
Includes:
Associations, 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/associations.rb,
lib/godmin/resources/resource_service/batch_actions.rb

Defined Under Namespace

Modules: Associations, 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, #orderable_column?

Methods included from Filters

#apply_filters

Methods included from BatchActions

#batch_action, #batch_action?, #include_batch_action?, #include_batch_actions?

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#attrs_for_exportObject



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

def attrs_for_export
  self.class.attrs_for_export
end

#attrs_for_formObject



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

def attrs_for_form
  self.class.attrs_for_form
end

#attrs_for_indexObject



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

def attrs_for_index
  self.class.attrs_for_index
end

#attrs_for_showObject



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

def attrs_for_show
  self.class.attrs_for_show
end

#build_resource(params) ⇒ Object



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

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

#create_resource(resource) ⇒ Object



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

def create_resource(resource)
  resource.save
end

#destroy_resource(resource) ⇒ Object



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

def destroy_resource(resource)
  resource.destroy
end

#find_resource(id) ⇒ Object



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

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

#initialize(options = {}) ⇒ Object



22
23
24
# File 'lib/godmin/resources/resource_service.rb', line 22

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

#resource_classObject



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

def resource_class
  self.class.name.chomp("Service").constantize
end

#resources(params) ⇒ Object



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

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

#resources_relationObject



30
31
32
33
34
35
36
# File 'lib/godmin/resources/resource_service.rb', line 30

def resources_relation
  if options[:resource_parent].present?
    resource_class.where(options[:resource_parent].class.name.underscore => options[:resource_parent])
  else
    resource_class.all
  end
end

#update_resource(resource, params) ⇒ Object



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

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