Sha256: ee5231a7ea834aaf57ab1b41532ec6473e7ebe8cf5ccae9ac32a1691be666c0f

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module SimpleDecorator
  module Header
    extend ActiveSupport::Concern

    included do
      class_attribute :header_attributes
      class_attribute :header_link_attributes
      class_attribute :header_actions
      class_attribute :link_path
    end

    module ClassMethods
      def attr_header(*attributes)
        options = attributes.extract_options!

        self.header_attributes = set attributes
        self.header_link_attributes = set options.fetch(:link, attributes.first)
        self.header_actions = set options[:list_actions]
        self.link_path = options.fetch(:link_path, :edit_resource_path)
      end

      def link?(field)
        headers? && header_link_attributes.include?(field)
      end

      def list_action?(action)
        list_actions? && header_actions.include?(action)
      end

      def headers?
        header_attributes.present?
      end

      def list_actions?
        header_actions.present?
      end

      def set(params)
        Set.new Array(params).map(&:to_sym)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unico-training-7.8.0 lib/simple_decorator/header.rb