Class: Super::Controls

Inherits:
Object
  • Object
show all
Defined in:
lib/super/controls.rb

Overview

A wrapper around the per-controller Controls classes. This class often directly delegates to the per-controller classes, but it can also provide some default implementation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actual) ⇒ Controls

Returns a new instance of Controls.



6
7
8
# File 'lib/super/controls.rb', line 6

def initialize(actual)
  @actual = actual
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



10
11
12
# File 'lib/super/controls.rb', line 10

def actual
  @actual
end

Instance Method Details

#createAction

Returns:



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/super/controls.rb', line 185

def create
  if @actual.respond_to?(:create)
    return @actual.create
  end

  Super::Action.new(
    steps: [
      :create_resource,
    ],
    page: Super::Layout.new(
      mains: [
        Super::Panel.new(
          Super::Partial.new("resources_header"),
          Super::Partial.new("form")
        )
      ]
    )
  )
end

#destroyAction

Returns:



248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/super/controls.rb', line 248

def destroy
  if @actual.respond_to?(:destroy)
    return @actual.destroy
  end

  Super::Action.new(
    steps: [
      :load_resource,
    ],
    page: Super::Layout.new
  )
end

#display_schema(action:) ⇒ Schema

Configures the fields that are displayed on the index and show actions. This is a required method

Parameters:

Returns:



107
108
109
# File 'lib/super/controls.rb', line 107

def display_schema(action:)
  @actual.display_schema(action: action)
end

#editAction

Returns:



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/super/controls.rb', line 206

def edit
  if @actual.respond_to?(:edit)
    return @actual.edit
  end

  Super::Action.new(
    steps: [
      :load_resource,
    ],
    page: Super::Layout.new(
      mains: [
        Super::Panel.new(
          Super::Partial.new("resource_header"),
          Super::Partial.new("form")
        )
      ]
    )
  )
end

#form_schema(action:) ⇒ Schema

Configures the editable fields on the new and edit actions. This is a required method

Parameters:

Returns:



116
117
118
# File 'lib/super/controls.rb', line 116

def form_schema(action:)
  @actual.form_schema(action: action)
end

#indexAction

Returns:



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/super/controls.rb', line 121

def index
  if @actual.respond_to?(:index)
    return @actual.index
  end

  Super::Action.new(
    steps: [
      :load_resources,
      :paginate,
    ],
    page: Super::Layout.new(
      mains: [
        Super::Panel.new(
          Super::Partial.new("resources_header"),
          Super::Partial.new("index")
        )
      ]
    )
  )
end

#modelActiveRecord::Base

Specifies the model. This is a required method

Returns:

  • (ActiveRecord::Base)


26
27
28
# File 'lib/super/controls.rb', line 26

def model
  @actual.model
end

#newAction

Returns:



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/super/controls.rb', line 164

def new
  if @actual.respond_to?(:new)
    return @actual.new
  end

  Super::Action.new(
    steps: [
      :new_resource,
    ],
    page: Super::Layout.new(
      mains: [
        Super::Panel.new(
          Super::Partial.new("resources_header"),
          Super::Partial.new("form")
        )
      ]
    )
  )
end

#permitted_params(params, action:) ⇒ ActionController::Parameters

Configures which parameters could be written to the database. This is a required method

Parameters:

Returns:

  • (ActionController::Parameters)


98
99
100
# File 'lib/super/controls.rb', line 98

def permitted_params(params, action:)
  @actual.permitted_params(params, action: action)
end

#resource_actions(resource, params:, action:) ⇒ Array<Link>

Configures the actions linked to on the show page as well as each row of the table on the index page. This is an optional method

Parameters:

  • resource (ActiveRecord::Base)
  • params (ActionController::Parameters)
  • action (ActionInquirer)

Returns:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/super/controls.rb', line 58

def resource_actions(resource, params:, action:)
  actions =
    if @actual.respond_to?(:resource_actions)
      @actual.resource_actions(resource, params: params, action: action)
    else
      if action.show?
        [:edit, :destroy]
      elsif action.edit?
        [:show, :destroy]
      else
        [:show, :edit, :destroy]
      end
    end

  actions.map do |link|
    link = Link.resolve(link)

    link.call(resource, params: params)
  end
end

#resources_actions(params:, action:) ⇒ Array<Link>

Configures the actions linked to on the index page. This is an optional method

Parameters:

Returns:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/super/controls.rb', line 36

def resources_actions(params:, action:)
  actions =
    if @actual.respond_to?(:resources_actions)
      @actual.resources_actions(params: params, action: action)
    else
      [:new]
    end

  actions.map do |link|
    link = Link.resolve(link)

    link.call(params: params)
  end
end

#scope(action:) ⇒ ActiveRecord::Relation

Configures what database records are visible on load. This is an optional method, it defaults to “‘all`” methods

Parameters:

Returns:

  • (ActiveRecord::Relation)


84
85
86
87
88
89
90
# File 'lib/super/controls.rb', line 84

def scope(action:)
  if @actual.respond_to?(:scope)
    return @actual.scope(action: action)
  end

  model.all
end

#showAction

Returns:



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/super/controls.rb', line 143

def show
  if @actual.respond_to?(:show)
    return @actual.show
  end

  Super::Action.new(
    steps: [
      :load_resource,
    ],
    page: Super::Layout.new(
      mains: [
        Super::Panel.new(
          Super::Partial.new("resource_header"),
          Super::Partial.new("show")
        )
      ]
    )
  )
end

#titleString

This is an optional method

Returns:

  • (String)


15
16
17
18
19
20
21
# File 'lib/super/controls.rb', line 15

def title
  if @actual.respond_to?(:title)
    return @actual.title
  end

  model.name.pluralize
end

#updateAction

Returns:



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/super/controls.rb', line 227

def update
  if @actual.respond_to?(:update)
    return @actual.update
  end

  Super::Action.new(
    steps: [
      :load_resource,
    ],
    page: Super::Layout.new(
      mains: [
        Super::Panel.new(
          Super::Partial.new("resource_header"),
          Super::Partial.new("form")
        )
      ]
    )
  )
end