Module: Resources::GrapeHelpers
- Defined in:
- lib/resources/grape_helpers.rb
Instance Method Summary collapse
- #destroy_resource(&block) ⇒ Object
- #resource ⇒ Object
- #resource_configuration ⇒ Object
- #resource_for(name = nil, *args) ⇒ Object
- #resource_manager ⇒ Object
- #resource_saved? ⇒ Boolean
- #resources ⇒ Object
- #resources_search ⇒ Object
- #save_resource(&block) ⇒ Object
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 |
#resource ⇒ Object
22 23 24 |
# File 'lib/resources/grape_helpers.rb', line 22 def resource @resource ||= resource_manager.resource end |
#resource_configuration ⇒ Object
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 = Resources::Config.to_hash.deep_merge(args.) @resource_configuration = Resources::Configuration.new() @resource_configuration.resource_class_name = name end |
#resource_manager ⇒ Object
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 |
#resources ⇒ Object
18 19 20 |
# File 'lib/resources/grape_helpers.rb', line 18 def resources @resources ||= resource_manager.resources end |
#resources_search ⇒ Object
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 |