Module: Card::View::Options::Visibility

Included in:
Card::View::Options
Defined in:
card/lib/card/view/options/visibility.rb

Overview

manages showing and hiding optional view renders

Constant Summary collapse

VIZ_SETTING =

advanced write method

{ show: :show, true => :show,
hide: :hide, false => :hide, nil => :hide }.freeze

Instance Method Summary collapse

Instance Method Details

#hide(*views) ⇒ Object



28
29
30
# File 'card/lib/card/view/options/visibility.rb', line 28

def hide *views
  viz views, :hide
end

#hide!(*views) ⇒ Object



38
39
40
# File 'card/lib/card/view/options/visibility.rb', line 38

def hide! *views
  viz views, :hide, true
end

#hide?(view) ⇒ Boolean

test methods

Returns:

  • (Boolean)


14
15
16
# File 'card/lib/card/view/options/visibility.rb', line 14

def hide? view
  viz_hash[view&.to_sym] == :hide
end

#optional?true/false

test whether view is optional (@optional is set in normalize_options

Returns:

  • (true/false)


63
64
65
# File 'card/lib/card/view/options/visibility.rb', line 63

def optional?
  @optional
end

#process_visibilityObject

translate raw hide, show options (which can be strings, symbols, arrays, etc)



69
70
71
72
73
# File 'card/lib/card/view/options/visibility.rb', line 69

def process_visibility
  viz_hash.reverse_merge! parent.viz_hash if parent
  process_visibility_options live_options
  viz requested_view, @optional if @optional && !viz_hash[requested_view]
end

#show(*views) ⇒ Object

write methods



24
25
26
# File 'card/lib/card/view/options/visibility.rb', line 24

def show *views
  viz views, :show
end

#show!(*views) ⇒ Object

force write methods



34
35
36
# File 'card/lib/card/view/options/visibility.rb', line 34

def show! *views
  viz views, :show, true
end

#show?(view) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'card/lib/card/view/options/visibility.rb', line 18

def show? view
  !hide? view
end

#visible?(view) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
# File 'card/lib/card/view/options/visibility.rb', line 55

def visible? view
  viz view, yield unless viz_hash[view]
  show? view
end

#viz(views, setting, force = false) ⇒ Object



46
47
48
49
50
51
52
53
# File 'card/lib/card/view/options/visibility.rb', line 46

def viz views, setting, force=false
  Array.wrap(views).flatten.each do |view|
    view = view.to_sym
    next if !force && viz_hash[view]

    viz_hash[view] = VIZ_SETTING[setting]
  end
end

#viz_hashObject

tracks show/hide value for each view with an explicit setting eg { toggle: :hide }



8
9
10
# File 'card/lib/card/view/options/visibility.rb', line 8

def viz_hash
  @viz_hash ||= {}
end