Class: Card::View

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

Defined Under Namespace

Modules: Cache, CacheAction, Options, Stub, Visibility

Constant Summary

Constants included from CacheAction

CacheAction::ACTIVE_CACHE_LEVEL

Constants included from Visibility

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 CacheAction

#active_cache_action, #active_cache_action_from_setting, #active_cache_ok?, #active_cache_permissible?, #cache_action, #cache_on?, #cache_setting, #cache_status, #clean_enough_to_cache?, #free_cache_action, #free_cache_ok?, #log_cache_action, #off_cache_action, #permission_task

Methods included from Options

add_option

Methods included from Options::KeyLists

#accessible_keys, #all_keys, #heir_keys, #reset_key_lists, #ruler_keys

Methods included from Options::VooApi

define_getter, define_setter, included, #items, #normalize_cache, #normalize_editor, #slot_options

Methods included from Stub

escape, #stub, #stub_hash, #stub_json, unescape

Methods included from Cache

#array_for_cache_key, #cache_active?, #cache_fetch, #cache_key, #cache_render, #caching, #fetch, #hash_for_cache_key, #option_for_cache_key, #option_value_to_string, #options_for_cache_key, #register_cache_key

Methods included from Visibility

#hide, #hide!, #hide?, #optional?, #process_visibility, #process_visibility_options, #show, #show!, #show?, #visible?, #viz, #viz_hash, #viz_view_list

Constructor Details

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

Returns a new instance of View.

Parameters:

  • format (Card::Format)
  • view (Symbol)
  • raw_options (Hash) (defaults to: {})
  • parent (Card::View) (defaults to: nil)

    (optional)



27
28
29
30
31
32
33
34
35
# File 'lib/card/view.rb', line 27

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.



16
17
18
# File 'lib/card/view.rb', line 16

def card
  @card
end

#formatObject (readonly)

Returns the value of attribute format.



16
17
18
# File 'lib/card/view.rb', line 16

def format
  @format
end

#parentObject (readonly)

Returns the value of attribute parent.



16
17
18
# File 'lib/card/view.rb', line 16

def parent
  @parent
end

Class Method Details

.canonicalize(view) ⇒ Symbol

Returns:

  • (Symbol)


19
20
21
# File 'lib/card/view.rb', line 19

def self.canonicalize view
  view.present? ? view.to_sym : nil # error for no view?
end

Instance Method Details

#deep_root?true/false

neither view nor format has a parent

Returns:

  • (true/false)


72
73
74
# File 'lib/card/view.rb', line 72

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

#next_ancestorCard::View

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

Returns:



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

def next_ancestor
  parent || (format.parent && 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



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

def ok_view
  @ok_view ||= format.ok_view requested_view,
                              normalized_options[:skip_perms]
end

#processrendered view or a stub

handle rendering, including optional visibility, permissions, and caching

Returns:

  • (rendered view or a stub)


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

def process
  process_live_options
  return if optional? && hide?(requested_view)
  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



48
49
50
# File 'lib/card/view.rb', line 48

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

#rootCard::View

Returns:



61
62
63
# File 'lib/card/view.rb', line 61

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

#root?true/false

Returns:

  • (true/false)


66
67
68
# File 'lib/card/view.rb', line 66

def root?
  !parent
end