File: hideable.rb

package info (click to toggle)
ruby-rails-admin 0.8.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,492 kB
  • ctags: 1,292
  • sloc: ruby: 5,341; makefile: 3
file content (28 lines) | stat: -rw-r--r-- 606 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module RailsAdmin
  module Config
    # Defines a visibility configuration
    module Hideable
      # Visibility defaults to true.
      def self.included(klass)
        klass.register_instance_option :visible? do
          !root.try :excluded?
        end
      end

      # Reader whether object is hidden.
      def hidden?
        !visible
      end

      # Writer to hide object.
      def hide(&block)
        visible block ? proc { false == (instance_eval(&block)) } : false
      end

      # Writer to show field.
      def show(&block)
        visible block || true
      end
    end
  end
end