Class: RKit::Decoration::Collection

Inherits:
CollectionDelegator show all
Includes:
Base
Defined in:
lib/r_kit/decoration/base/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Base

#decorate, #decorated?, #initialize, #raw, #view

Methods inherited from CollectionDelegator

#method_missing

Methods included from Enumerable

#decorate, #decorated?, #to_grid

Methods inherited from SimpleDelegator

#===, getobj_attr_reader

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CollectionDelegator

Instance Attribute Details

#safe_modeObject

Returns the value of attribute safe_mode.



5
6
7
# File 'lib/r_kit/decoration/base/collection.rb', line 5

def safe_mode
  @safe_mode
end

Instance Method Details

#each(&block) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/r_kit/decoration/base/collection.rb', line 11

def each &block
  collection.each do |object|
    if safe_mode && object.dont_respond_to?(:decorate)
      block.call object
    else
      block.call object.decorate(view_context: view)
    end
  end
end

#safeObject



7
# File 'lib/r_kit/decoration/base/collection.rb', line 7

def safe() tap{ @safe_mode = true } end

#unsafeObject



8
# File 'lib/r_kit/decoration/base/collection.rb', line 8

def unsafe() tap{ @safe_mode = false } end