Module: SnFoil::CRUD::SetupContext
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/snfoil/crud/setup_context.rb
Instance Method Summary collapse
- #adapter ⇒ Object
- #adapter?(object) ⇒ Boolean
- #model ⇒ Object
- #policy ⇒ Object
- #scope ⇒ Object
- #unwrap_object(object) ⇒ Object
- #wrap_object(object) ⇒ Object
Instance Method Details
#adapter ⇒ Object
88 89 90 |
# File 'lib/snfoil/crud/setup_context.rb', line 88 def adapter @adapter ||= SnFoil.adapter end |
#adapter?(object) ⇒ Boolean
82 83 84 85 86 |
# File 'lib/snfoil/crud/setup_context.rb', line 82 def adapter?(object) return false unless adapter object.instance_of? adapter end |
#model ⇒ Object
58 59 60 |
# File 'lib/snfoil/crud/setup_context.rb', line 58 def model self.class.snfoil_model end |
#policy ⇒ Object
62 63 64 |
# File 'lib/snfoil/crud/setup_context.rb', line 62 def policy self.class.snfoil_policy end |
#scope ⇒ Object
66 67 68 |
# File 'lib/snfoil/crud/setup_context.rb', line 66 def scope "#{policy.name}::Scope".safe_constantize.new(entity, wrap_object(model)) end |
#unwrap_object(object) ⇒ Object
76 77 78 79 80 |
# File 'lib/snfoil/crud/setup_context.rb', line 76 def unwrap_object(object) return object unless adapter adapter?(object) ? object.__getobj__ : object end |
#wrap_object(object) ⇒ Object
70 71 72 73 74 |
# File 'lib/snfoil/crud/setup_context.rb', line 70 def wrap_object(object) return object unless adapter adapter.new(object) end |