Class: Stationed::CrudTag
- Inherits:
-
Object
- Object
- Stationed::CrudTag
- Defined in:
- lib/stationed/crud_tag.rb
Overview
Base class for CRUD-style tags
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
-
#initialize(context, method, resource, options = {}) ⇒ CrudTag
constructor
A new instance of CrudTag.
- #new ⇒ Object
- #show ⇒ Object
Constructor Details
#initialize(context, method, resource, options = {}) ⇒ CrudTag
Returns a new instance of CrudTag.
6 7 8 9 10 11 12 |
# File 'lib/stationed/crud_tag.rb', line 6 def initialize(context, method, resource, = {}) @context = context @method = method @resource = resource @model = Array(resource).last @options = end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
4 5 6 |
# File 'lib/stationed/crud_tag.rb', line 4 def context @context end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
4 5 6 |
# File 'lib/stationed/crud_tag.rb', line 4 def method @method end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
4 5 6 |
# File 'lib/stationed/crud_tag.rb', line 4 def model @model end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
4 5 6 |
# File 'lib/stationed/crud_tag.rb', line 4 def resource @resource end |
Instance Method Details
#destroy ⇒ Object
31 32 33 |
# File 'lib/stationed/crud_tag.rb', line 31 def destroy context.send method, label(:destroy), [*resource], .merge(data: { method: :delete }) end |
#edit ⇒ Object
27 28 29 |
# File 'lib/stationed/crud_tag.rb', line 27 def edit context.send method, label(:edit), [:edit, *resource], end |
#index ⇒ Object
14 15 16 |
# File 'lib/stationed/crud_tag.rb', line 14 def index context.send method, label(:index), model, end |
#new ⇒ Object
18 19 20 21 |
# File 'lib/stationed/crud_tag.rb', line 18 def new *nested_parts, _ = Array(resource) context.send method, label(:new), [:new, *nested_parts, model_name.singular], end |
#show ⇒ Object
23 24 25 |
# File 'lib/stationed/crud_tag.rb', line 23 def show context.send method, label(:show), [*resource], end |