Module: AdminGate

Defined in:
docs/api/stubs/generated_app.rb

Overview

What spin run gen writes into gen/concerns.rb for a controller concern (ActiveSupport::Concern) with class_methods:

# app/controllers/concerns/admin_gate.rb
module AdminGate
  extend ActiveSupport::Concern

  included do
    before_action :require_admin
    helper_method :admin?
  end

  class_methods do
    def per_page = 20
  end

  def admin? = Current.user&.admin?
end

Each def of the class_methods block becomes a method of the concern, with the same parameters and body.

The application loads the concern itself from gen/concerns/controllers/concerns/admin_gate.rb (a model concern from gen/concerns/models/concerns/<name>.rb): the file as written, line for line, with the lines of its included do ... end and class_methods do ... end blocks left empty and a comment naming it as generated at the end. Those blocks take effect only where gen/concerns.rb splices them, so a block in them may call the including class’s methods without a receiver (scope :visible, -> { where(hidden: 0) }).

A model concern’s included body is spliced the same way into each model that includes it, between model_concern_insert_at (the count of the model’s own validates calls above the include) and model_concern_insert_done; its scopes, associations, validate and encrypts lines and its instance methods count, for gen/models, as written at the include:

class Post
  # Visible (include Visible at app/models/post.rb:4)
  model_concern_insert_at(1)
  validates :body, length: { maximum: 10000 }
  scope :visible, -> { where(hidden: 0) }
  model_concern_insert_done
end

Class Method Summary collapse

Class Method Details

.per_page ⇒ Integer

def per_page = 20 from the class_methods block.

Returns:



1088
# File 'docs/api/stubs/generated_app.rb', line 1088

def self.per_page = 20