Module: RademadeAdmin::Hideable

Defined in:
lib/rademade_admin/hideable.rb

Constant Summary collapse

STATUS_HIDDEN =
0
STATUS_SHOWN =
1

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *arguments) ⇒ Object



7
8
9
10
11
12
# File 'lib/rademade_admin/hideable.rb', line 7

def method_missing(name, *arguments)
  if %w(status status=).include? name
    raise NotImplementedError.new "Implement '#{name}' method"
  end
  super
end

Instance Method Details

#hideObject



28
29
30
# File 'lib/rademade_admin/hideable.rb', line 28

def hide
  send(:status=, STATUS_HIDDEN)
end

#showObject



24
25
26
# File 'lib/rademade_admin/hideable.rb', line 24

def show
  send(:status=, STATUS_SHOWN)
end

#shown?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
# File 'lib/rademade_admin/hideable.rb', line 14

def shown?
  item_status = send(:status)
  if item_status.is_a? Fixnum
    item_status == STATUS_SHOWN
  else
    # for boolean values
    item_status
  end
end

#toggleObject



32
33
34
# File 'lib/rademade_admin/hideable.rb', line 32

def toggle
  shown? ? hide : show
end