Class: Card::View

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

Defined Under Namespace

Modules: Cache, Fetch, Options, Stub, Visibility

Constant Summary

Constants included from Fetch

Fetch::DEPENDENT_CACHE_LEVEL

Constants included from Visibility

Visibility::VIZ_SETTING

Instance Attribute Summary collapse

Attributes included from Options

#normalized_options

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Cache::ClassMethods

cache, caching, caching?

Methods included from Options

all_keys, heir_keys, #items, #live_options, nest_keys, #normalize_editor, #slot_options

Methods included from Stub

#stub, #stub_hash, #stub_json, #validate_stub

Methods included from Cache

#cache_fetch, #cache_key, #caching, #caching?, #deep_root?, #hash_for_cache_key, #option_for_cache_key, #options_for_cache_key, #root

Methods included from Fetch

#cache_level, #cache_setting, #clean_enough_to_cache?, #dependent_cache_level, #dependent_cache_level_unvalidated, #dependent_cache_ok?, #dependent_cache_setting, #dependent_cacheable_permissible?, #fetch, #independent_cache_level, #independent_cache_ok?, #permission_task

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.



24
25
26
27
28
29
30
31
32
# File 'lib/card/view.rb', line 24

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) ⇒ Object



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

def self.canonicalize view
  return if view.blank? # error?
  view.to_viewname.key.to_sym
end

Instance Method Details

#ok_viewObject

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



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

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

#processObject

handle rendering, including optional visibility, permissions, and caching



35
36
37
38
39
40
# File 'lib/card/view.rb', line 35

def process
  process_live_options
  process_visibility_options
  return if optional? && hide?(requested_view)
  fetch { yield ok_view, foreign_live_options }
end

#requested_viewObject

the view to "attempt". Typically the same as @raw_view, but @raw_view is often overridden for the main view (top view of the main card on a page)



44
45
46
# File 'lib/card/view.rb', line 44

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