module Card::View::Options::Visibility
manages showing and hiding optional view renders
Constants
- VIZ_SETTING
-
advanced write method
Public Instance Methods
Source
# File lib/card/view/options/visibility.rb, line 22 def explicit_show? view viz_hash[view&.to_sym] == :show end
Source
# File lib/card/view/options/visibility.rb, line 32 def hide *views viz views, :hide end
Source
# File lib/card/view/options/visibility.rb, line 42 def hide! *views viz views, :hide, true end
Source
# File lib/card/view/options/visibility.rb, line 14 def hide? view viz_hash[view&.to_sym] == :hide end
test methods
Source
# File lib/card/view/options/visibility.rb, line 67 def optional? @optional end
test whether view is optional (@optional is set in normalize_options @return [true/false]
Source
# File lib/card/view/options/visibility.rb, line 73 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
translate raw hide, show options (which can be strings, symbols, arrays, etc)
Source
# File lib/card/view/options/visibility.rb, line 28 def show *views viz views, :show end
write methods
Source
# File lib/card/view/options/visibility.rb, line 38 def show! *views viz views, :show, true end
force write methods
Source
# File lib/card/view/options/visibility.rb, line 18 def show? view !hide? view end
Source
# File lib/card/view/options/visibility.rb, line 59 def visible? view viz view, yield unless viz_hash[view] show? view end
Source
# File lib/card/view/options/visibility.rb, line 50 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
Source
# File lib/card/view/options/visibility.rb, line 8 def viz_hash @viz_hash ||= {} end
tracks show/hide value for each view with an explicit setting eg { toggle: :hide }
Private Instance Methods
Source
# File lib/card/view/options/visibility.rb, line 82 def hide_requested_view? optional? && hide?(requested_view) end
if true, process returns nil
Source
# File lib/card/view/options/visibility.rb, line 94 def normalized_visibility_options viz_hash.each_with_object({}) do |(key, val), hash| hash[val] ||= [] hash[val] << key end end
Source
# File lib/card/view/options/visibility.rb, line 87 def process_visibility_options options_hash %i[hide show].each do |setting| views = View.normalize_list(options_hash.delete(setting)).map(&:to_sym) viz views, setting, true end end
takes an options_hash and processes it to update viz_hash