Sha256: 2e606a294f440397ffca2bfbee11bb55213e0304eb3e606d35e293b703efb585

Contents?: true

Size: 1.34 KB

Versions: 4

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

module ActiveElement
  # Stores various data for a controller, including various field definitions and authentication
  # configuration. Used throughout ActiveElement for generating dynamic content based on
  # controller configuration.
  class ControllerState
    attr_reader :permissions, :listable_fields, :viewable_fields, :editable_fields, :searchable_fields,
                :field_options
    attr_accessor :sign_in_path, :sign_in, :sign_in_method, :sign_out_path, :sign_out_method,
                  :deletable, :authorizor, :authenticator, :list_order, :search_required, :model

    def initialize(controller:)
      @controller = controller
      @permissions = []
      @authenticator = nil
      @authorizor = nil
      @deletable = false
      @listable_fields = []
      @viewable_fields = []
      @editable_fields = []
      @searchable_fields = []
      @field_options = {}
      @model = nil
    end

    def deletable?
      !!deletable
    end

    def viewable?
      viewable_fields.present? || controller.public_methods(false).include?(:show)
    end

    def editable?
      editable_fields.present? || controller.public_methods(false).include?(:edit)
    end

    def creatable?
      editable_fields.present? || controller.public_methods(false).include?(:new)
    end

    private

    attr_reader :controller
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
active_element-0.0.19 lib/active_element/controller_state.rb
active_element-0.0.18 lib/active_element/controller_state.rb
active_element-0.0.17 lib/active_element/controller_state.rb
active_element-0.0.16 lib/active_element/controller_state.rb