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, #validate_active_cache_action

Methods included from Options

add_option

Methods included from Options::KeyLists

#accessible_keys, #all_keys, #carditect_keys, #heir_keys, #reset_key_lists

Methods included from Options::VooApi

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

Methods included from Stub

escape, #invalid_stub, #reject_foreign_options_in_stub!, #stub, #stub_hash, #stub_json, unescape, #validate_stub!, #with_override

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)



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

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

#unsupported_viewObject

Returns the value of attribute unsupported_view.



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

def unsupported_view
  @unsupported_view
end

Class Method Details

.canonicalize(view) ⇒ Symbol

Returns:

  • (Symbol)


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

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)


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

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

#next_ancestorCard::View

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

Returns:



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

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



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

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)


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

def process
  process_live_options
  return if optional? && hide?(requested_view)
  fetch { yield ok_view, foreign_live_options }
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



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

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

#rootCard::View

Returns:



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

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

#root?true/false

Returns:

  • (true/false)


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

def root?
  !parent
end