Module: Resources::GrapeHelpers

Defined in:
lib/resources/grape_helpers.rb

Instance Method Summary collapse

Instance Method Details

#destroy_resource(&block) ⇒ Object



40
41
42
43
# File 'lib/resources/grape_helpers.rb', line 40

def destroy_resource &block
  @destroy_resource = resource.destroy
  block_given? ? block.call(resource) : resource
end

#resourceObject



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

def resource
  @resource ||= resource_manager.resource
end

#resource_configurationObject



10
11
12
# File 'lib/resources/grape_helpers.rb', line 10

def resource_configuration
  @resource_configuration
end

#resource_for(name = nil, *args) ⇒ Object



4
5
6
7
8
# File 'lib/resources/grape_helpers.rb', line 4

def resource_for name = nil, *args
  options = Resources::Config.to_hash.deep_merge(args.extract_options!)
  @resource_configuration = Resources::Configuration.new(options)
  @resource_configuration.resource_class_name = name
end

#resource_managerObject



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

def resource_manager
  @resource_manager ||= Resources::Manager.new(self, request)
end

#resource_saved?Boolean



30
31
32
# File 'lib/resources/grape_helpers.rb', line 30

def resource_saved?
  @resource_saved
end

#resourcesObject



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

def resources
  @resources ||= resource_manager.resources
end

#resources_searchObject



14
15
16
# File 'lib/resources/grape_helpers.rb', line 14

def resources_search
  @resources_search ||= resource_manager.resources_search
end

#save_resource(&block) ⇒ Object



34
35
36
37
38
# File 'lib/resources/grape_helpers.rb', line 34

def save_resource &block
  resource.assign_attributes(resource_manager.params_resource)
  @resource_saved = resource.save
  block_given? ? block.call(resource) : resource
end