Module: TypicalSituation::Identity
- Included in:
- TypicalSituation
- Defined in:
- lib/typical_situation/identity.rb
Overview
These Identity methods must be defined for each implementation.
Instance Method Summary collapse
-
#collection ⇒ Object
The collection of model instances.
- #create_params ⇒ Object
-
#find_in_collection(_id) ⇒ Object
Find a model instance by ID.
- #include_root? ⇒ Boolean
- #location_url ⇒ Object
- #model_params ⇒ Object
-
#model_type ⇒ Object
Symbolized, underscored version of the model (class) to use.
- #permitted_create_params ⇒ Object
- #permitted_update_params ⇒ Object
- #plural_model_type ⇒ Object
- #update_params ⇒ Object
Instance Method Details
#collection ⇒ Object
The collection of model instances.
40 41 42 |
# File 'lib/typical_situation/identity.rb', line 40 def collection raise(NotImplementedError, "#collection must be defined in the TypicalSituation implementation.") end |
#create_params ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/typical_situation/identity.rb', line 15 def create_params if permitted_create_params.nil? || permitted_create_params.empty? return model_params.permit! end model_params.permit(permitted_create_params) end |
#find_in_collection(_id) ⇒ Object
Find a model instance by ID.
45 46 47 |
# File 'lib/typical_situation/identity.rb', line 45 def find_in_collection(_id) raise(NotImplementedError, "#find_in_collection must be defined in the TypicalSituation implementation.") end |
#include_root? ⇒ Boolean
49 50 51 |
# File 'lib/typical_situation/identity.rb', line 49 def include_root? true end |
#location_url ⇒ Object
57 58 59 60 61 62 |
# File 'lib/typical_situation/identity.rb', line 57 def location_url return if @resource.nil? || @resource.new_record? @resource.respond_to?(:to_url) ? @resource.to_url : polymorphic_url(@resource) end |
#model_params ⇒ Object
11 12 13 |
# File 'lib/typical_situation/identity.rb', line 11 def model_params params.require(model_type.to_sym) end |
#model_type ⇒ Object
Symbolized, underscored version of the model (class) to use.
7 8 9 |
# File 'lib/typical_situation/identity.rb', line 7 def model_type raise(NotImplementedError, "#model_type must be defined in the TypicalSituation implementation.") end |
#permitted_create_params ⇒ Object
31 32 33 |
# File 'lib/typical_situation/identity.rb', line 31 def permitted_create_params nil end |
#permitted_update_params ⇒ Object
35 36 37 |
# File 'lib/typical_situation/identity.rb', line 35 def permitted_update_params nil end |
#plural_model_type ⇒ Object
53 54 55 |
# File 'lib/typical_situation/identity.rb', line 53 def plural_model_type model_type.to_s.pluralize.intern end |
#update_params ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/typical_situation/identity.rb', line 23 def update_params if permitted_update_params.nil? || permitted_update_params.empty? return model_params.permit! end model_params.permit(permitted_update_params) end |