Module: TypicalSituation::ClassMethods
- Defined in:
- lib/typical_situation.rb
Instance Method Summary collapse
- #typical_crud(model_type_symbol) ⇒ Object
- #typical_rest(model_type_symbol) ⇒ Object
-
#typical_situation(model_type_symbol, only: nil) ⇒ Object
Syntactic sugar for defining model_type.
Instance Method Details
#typical_crud(model_type_symbol) ⇒ Object
59 60 61 |
# File 'lib/typical_situation.rb', line 59 def typical_crud(model_type_symbol) typical_situation(model_type_symbol, only: i[create show update destroy]) end |
#typical_rest(model_type_symbol) ⇒ Object
55 56 57 |
# File 'lib/typical_situation.rb', line 55 def typical_rest(model_type_symbol) typical_situation(model_type_symbol, only: nil) end |
#typical_situation(model_type_symbol, only: nil) ⇒ Object
Syntactic sugar for defining model_type
Example:
class PostsController < ApplicationController
include TypicalSituation
typical_situation :post
end
This is equivalent to:
def model_type
:post
end
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/typical_situation.rb', line 39 def typical_situation(model_type_symbol, only: nil) define_method :model_type do model_type_symbol end if only only.each do |action| if TypicalSituation::Actions.method_defined?(action) define_method(action, TypicalSituation::Actions.instance_method(action)) end end else include TypicalSituation::Actions end end |