Class: Stationed::CrudTag

Inherits:
Object
  • Object
show all
Defined in:
lib/stationed/crud_tag.rb

Overview

Base class for CRUD-style tags

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @context  = context
  @method   = method
  @resource = resource
  @model    = Array(resource).last
  @options  = options
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



4
5
6
# File 'lib/stationed/crud_tag.rb', line 4

def context
  @context
end

#methodObject (readonly)

Returns the value of attribute method.



4
5
6
# File 'lib/stationed/crud_tag.rb', line 4

def method
  @method
end

#modelObject (readonly)

Returns the value of attribute model.



4
5
6
# File 'lib/stationed/crud_tag.rb', line 4

def model
  @model
end

#resourceObject (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

#destroyObject



31
32
33
# File 'lib/stationed/crud_tag.rb', line 31

def destroy
  context.send method, label(:destroy), [*resource], options.merge(data: { method: :delete })
end

#editObject



27
28
29
# File 'lib/stationed/crud_tag.rb', line 27

def edit
  context.send method, label(:edit), [:edit, *resource], options
end

#indexObject



14
15
16
# File 'lib/stationed/crud_tag.rb', line 14

def index
  context.send method, label(:index), model, options
end

#newObject



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], options
end

#showObject



23
24
25
# File 'lib/stationed/crud_tag.rb', line 23

def show
  context.send method, label(:show), [*resource], options
end