Module: ResourcesController::InstanceMethods
- Defined in:
- lib/resources_controller.rb
Instance Method Summary collapse
-
#enclosing_collection_resources ⇒ Object
returns an array of the collection (non singleton) enclosing resources, this is used for generating routes.
-
#enclosing_resource ⇒ Object
returns the immediately enclosing resource.
-
#enclosing_resource_name ⇒ Object
returns the name of the immediately enclosing resource.
-
#enclosing_resources ⇒ Object
returns an array of the controller's enclosing (nested in) resources.
- #name_prefix ⇒ Object
-
#resource ⇒ Object
returns the controller's current resource.
-
#resource=(record) ⇒ Object
sets the controller's current resource, and decorates the object with a save hook, so we know if it's been saved.
-
#resource_class ⇒ Object
returns the controller's resource class.
-
#resource_name ⇒ Object
name of the singular resource.
-
#resource_saved? ⇒ Boolean
NOTE: This method is overly complicated and unnecessary.
-
#resource_service ⇒ Object
returns the resource service for the controller - this will be lazilly created to a ResourceService, or a SingletonResourceService (if :singleton => true).
- #resource_service=(service) ⇒ Object
-
#resource_specification ⇒ Object
returns the instance resource_specification.
-
#resources ⇒ Object
returns the controller's current resources collection.
-
#resources=(collection) ⇒ Object
sets the controller's current resource collection.
-
#resources_name ⇒ Object
name of the resource collection.
-
#save_resource ⇒ Object
NOTE: it's clearer to just keep track of record saves yourself, this is here for BC See the comment on #resource_saved?.
Instance Method Details
#enclosing_collection_resources ⇒ Object
returns an array of the collection (non singleton) enclosing resources, this is used for generating routes.
631 632 633 |
# File 'lib/resources_controller.rb', line 631 def enclosing_collection_resources @enclosing_collection_resources ||= [] end |
#enclosing_resource ⇒ Object
returns the immediately enclosing resource
605 606 607 |
# File 'lib/resources_controller.rb', line 605 def enclosing_resource enclosing_resources.last end |
#enclosing_resource_name ⇒ Object
returns the name of the immediately enclosing resource
610 611 612 |
# File 'lib/resources_controller.rb', line 610 def enclosing_resource_name @enclosing_resource_name end |
#enclosing_resources ⇒ Object
returns an array of the controller's enclosing (nested in) resources
626 627 628 |
# File 'lib/resources_controller.rb', line 626 def enclosing_resources @enclosing_resources ||= [] end |
#name_prefix ⇒ Object
564 565 566 |
# File 'lib/resources_controller.rb', line 564 def name_prefix @name_prefix ||= '' end |
#resource ⇒ Object
returns the controller's current resource.
584 585 586 |
# File 'lib/resources_controller.rb', line 584 def resource instance_variable_get("@#{resource_name}") end |
#resource=(record) ⇒ Object
sets the controller's current resource, and decorates the object with a save hook, so we know if it's been saved
590 591 592 |
# File 'lib/resources_controller.rb', line 590 def resource=(record) instance_variable_set("@#{resource_name}", record) end |
#resource_class ⇒ Object
returns the controller's resource class
579 580 581 |
# File 'lib/resources_controller.rb', line 579 def resource_class resource_specification.klass end |
#resource_name ⇒ Object
name of the singular resource
569 570 571 |
# File 'lib/resources_controller.rb', line 569 def resource_name resource_specification.name end |
#resource_saved? ⇒ Boolean
NOTE: This method is overly complicated and unnecessary. It's much clearer just to keep track of record saves yourself, this is here for BC. For an example of how it should be done look at the actions module in http://github.com/ianwhite/response_for_rc
Has the resource been saved successfully?, if no save has been attempted, save the record and return the result
This method uses the @resource_saved tracking var, or the model's state itself if that is not available (which means if you do resource.update, then this method will return the correct result)
645 646 647 648 649 |
# File 'lib/resources_controller.rb', line 645 def resource_saved? save_resource if @resource_saved.nil? && !resource.validation_attempted? @resource_saved = resource.saved? if @resource_saved.nil? @resource_saved end |
#resource_service ⇒ Object
returns the resource service for the controller - this will be lazilly created to a ResourceService, or a SingletonResourceService (if :singleton => true)
616 617 618 |
# File 'lib/resources_controller.rb', line 616 def resource_service @resource_service ||= resource_specification.singleton? ? SingletonResourceService.new(self) : ResourceService.new(self) end |
#resource_service=(service) ⇒ Object
560 561 562 |
# File 'lib/resources_controller.rb', line 560 def resource_service=(service) @resource_service = service end |
#resource_specification ⇒ Object
returns the instance resource_specification
621 622 623 |
# File 'lib/resources_controller.rb', line 621 def resource_specification self.class.resource_specification end |
#resources ⇒ Object
returns the controller's current resources collection
595 596 597 |
# File 'lib/resources_controller.rb', line 595 def resources instance_variable_get("@#{resources_name}") end |
#resources=(collection) ⇒ Object
sets the controller's current resource collection
600 601 602 |
# File 'lib/resources_controller.rb', line 600 def resources=(collection) instance_variable_set("@#{resources_name}", collection) end |
#resources_name ⇒ Object
name of the resource collection
574 575 576 |
# File 'lib/resources_controller.rb', line 574 def resources_name @resources_name ||= resource_specification.name.pluralize end |
#save_resource ⇒ Object
NOTE: it's clearer to just keep track of record saves yourself, this is here for BC See the comment on #resource_saved?
Save the resource, and keep track of the result
657 658 659 |
# File 'lib/resources_controller.rb', line 657 def save_resource @resource_saved = resource.save end |