Sha256: f0e76e8d6d2641d1554b78ad441509582778c962a0521bfb39d5f709f5e079cb

Contents?: true

Size: 1 KB

Versions: 33

Compression:

Stored size: 1 KB

Contents

module ExpressAdmin
  module Commands
    def self.included(base)
      base.class_eval do
        include InstanceMethods
        extend ClassMethods

        class_attribute :commands
        self.commands = []
      end
    end

    module ClassMethods

      def exposes_command(command)
        exposes_commands command
      end

      def exposes_commands(*commands)
        self.commands += commands
      end
    end

    module InstanceMethods
      # If not using, AASM, override this for disallowing commands
      def unavailable_commands
        []
      end

      def available_commands
        if respond_to?(:aasm)
          commands & aasm_event_triggers
        else
          commands - unavailable_commands
        end
      end

      protected
        def aasm_event_triggers
          aasm.events.map(&:name).map(&:to_s).map {|s| "#{s}!"}.map(&:to_sym)
        end
    end
  end
end

ActiveRecord::Base.include(ExpressAdmin::Commands)

class Symbol
  def debang
    to_s.gsub(/\!\Z/, '').to_sym
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
express_admin-1.7.21 lib/express_admin/commands.rb
express_admin-1.7.20 lib/express_admin/commands.rb
express_admin-1.7.19 lib/express_admin/commands.rb
express_admin-1.7.18 lib/express_admin/commands.rb
express_admin-1.7.17 lib/express_admin/commands.rb
express_admin-1.7.16 lib/express_admin/commands.rb
express_admin-1.7.16.pre1 lib/express_admin/commands.rb
express_admin-1.7.15 lib/express_admin/commands.rb
express_admin-1.7.14 lib/express_admin/commands.rb
express_admin-1.7.13 lib/express_admin/commands.rb
express_admin-1.7.12 lib/express_admin/commands.rb
express_admin-1.7.11 lib/express_admin/commands.rb
express_admin-1.7.10 lib/express_admin/commands.rb
express_admin-1.7.9 lib/express_admin/commands.rb
express_admin-1.7.8 lib/express_admin/commands.rb
express_admin-1.7.7 lib/express_admin/commands.rb
express_admin-1.7.5 lib/express_admin/commands.rb
express_admin-1.7.4 lib/express_admin/commands.rb
express_admin-1.7.3 lib/express_admin/commands.rb
express_admin-1.7.2 lib/express_admin/commands.rb