Class: Card::View

Inherits:
Object
  • Object
show all
Extended by:
Cache::ClassMethods
Includes:
Cache, Classy, Options, Permission
Defined in:
lib/card/view.rb,
lib/card/view/cache.rb,
lib/card/view/classy.rb,
lib/card/view/options.rb,
lib/card/view/cache/stub.rb,
lib/card/view/permission.rb,
lib/card/view/options/voo_api.rb,
lib/card/view/options/key_lists.rb,
lib/card/view/cache/cache_action.rb,
lib/card/view/options/visibility.rb

Overview

Card::View manages view options, view caching, and view permissions.

View objects, which are instantiated whenever a view is rendered, are available as in views and other format methods. The view objects can be accessed using ‘#voo`. We sometimes feebly pretend VOO is an acronym for “view option object,” but really we just needed a way not to confuse these Card::View options with the countless references to viewnames that naturally arise when rendering views within views within views.

When view A renders view B within the same format object, A’s voo is the parent of B’s voo. When card C nests card D, a new (sub)format object is initialized. C is then the parent format of D, but D has its own root voo.

So a lineage might look something like this:

‘F1V1 -> F1V2 -> F1V3 -> F2V1 -> F2V2 -> F3V1 …`

Defined Under Namespace

Modules: Cache, Classy, Options, Permission

Constant Summary

Constants included from Permission

Permission::CRUD

Constants included from Options::Visibility

Options::Visibility::VIZ_SETTING

Instance Attribute Summary collapse

Attributes included from Options::VooApi

#normalized_options

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Cache::ClassMethods

cache, caching, caching?

Methods included from Permission

#view_perms

Methods included from Classy

#add_extra_classes, #class_down, #class_up, #classy, #deep_extra_classes, #extra_classes, #remove_extra_classes, #with_class_up, #without_upped_class

Methods included from Options

add_option

Methods included from Options::KeyLists

#accessible_keys, #all_keys, #heir_keys, #reset_key_lists, #shark_keys, #slot_keys

Methods included from Options::Visibility

#explicit_show?, #hide, #hide!, #hide?, #optional?, #process_visibility, #show, #show!, #show?, #visible?, #viz, #viz_hash

Methods included from Options::VooApi

define_getter, define_setter, included, #items, #normalize_cache, #normalize_edit, #normalize_input_type, #normalize_special_options!, #normalize_wrap, #slot_options, #special_option_value

Constructor Details

#initialize(format, view, raw_options = {}, parent = nil) ⇒ View

Returns a new instance of View.

Parameters:

  • format (Card::Format)
  • view (Symbol)

    viewname. Note: Card::View is initialized without a view when ‘voo` is called outside of a render, eg `subformat(cardname).method_with_voo_reference`.

  • raw_options (Hash) (defaults to: {})
  • parent (Card::View) (defaults to: nil)

    (optional)



56
57
58
59
60
61
62
63
64
# File 'lib/card/view.rb', line 56

def initialize format, view, raw_options={}, parent=nil
  @format = format
  @raw_view = view
  @raw_options = raw_options
  @parent = parent

  @card = @format.card
  normalize_options
end

Instance Attribute Details

#cardObject (readonly)

Returns the value of attribute card.



29
30
31
# File 'lib/card/view.rb', line 29

def card
  @card
end

#formatObject (readonly)

Returns the value of attribute format.



29
30
31
# File 'lib/card/view.rb', line 29

def format
  @format
end

#interiorObject

Returns the value of attribute interior.



30
31
32
# File 'lib/card/view.rb', line 30

def interior
  @interior
end

#parentObject (readonly)

Returns the value of attribute parent.



29
30
31
# File 'lib/card/view.rb', line 29

def parent
  @parent
end

Class Method Details

.normalize(view) ⇒ Symbol

Returns viewname as Symbol.

Returns:

  • (Symbol)

    viewname as Symbol



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

def normalize view
  view.present? ? view.to_sym : nil
end

.normalize_list(val) ⇒ Array

Returns list of viewnames as Symbols.

Returns:

  • (Array)

    list of viewnames as Symbols



39
40
41
42
43
44
45
46
47
# File 'lib/card/view.rb', line 39

def normalize_list val
  case val
  when NilClass then []
  when Array    then val
  when String   then val.split(/[\s,]+/)
  when Symbol   then [val]
  else raise Card::Error, "bad show/hide argument: #{val}"
  end
end

Instance Method Details

#deep_rootObject

the root voo of the root format



99
100
101
# File 'lib/card/view.rb', line 99

def deep_root
  format.root.voo
end

#deep_root?true/false

neither view nor format has a parent

Returns:

  • (true/false)


105
106
107
# File 'lib/card/view.rb', line 105

def deep_root?
  !parent && !format.parent
end

#depthObject



109
110
111
# File 'lib/card/view.rb', line 109

def depth
  @depth ||= parent ? (parent.depth + 1) : 0
end

#next_ancestor(across_format = true) ⇒ Card::View

next voo object found tracing ancestry through parent voos and/or parent formats

Returns:



115
116
117
# File 'lib/card/view.rb', line 115

def next_ancestor across_format=true
  parent || (across_format && next_format_ancestor) || nil
end

#next_format_ancestorObject

voo object of format’s parent



120
121
122
# File 'lib/card/view.rb', line 120

def next_format_ancestor
  format.parent&.voo
end

#ok_viewSymbol

the final view. can be different from @requested_view when there are issues with permissions, recursions, unknown cards, etc.

Returns:

  • (Symbol)

    view name



84
85
86
# File 'lib/card/view.rb', line 84

def ok_view
  @ok_view ||= format.monitor_depth { altered_view || requested_view }
end

#processrendered view or a stub

handle rendering, including optional visibility, permissions, and caching

Returns:

  • (rendered view or a stub)


68
69
70
71
72
# File 'lib/card/view.rb', line 68

def process
  return if process_live_options == :hide

  fetch { yield ok_view }
end

#requested_viewSymbol

the view to “attempt”. Typically the same as @raw_view, but @raw_view can be overridden, eg for the main view (top view of the main card on a page)

Returns:

  • (Symbol)

    view name



77
78
79
# File 'lib/card/view.rb', line 77

def requested_view
  @requested_view ||= View.normalize live_options[:view]
end

#rootCard::View

Returns:



89
90
91
# File 'lib/card/view.rb', line 89

def root
  @root = parent ? parent.root : self
end

#root?true/false

Returns:

  • (true/false)


94
95
96
# File 'lib/card/view.rb', line 94

def root?
  !parent
end