Module: Tins::Scope

Included in:
DynamicScope
Defined in:
lib/tins/dslkit.rb

Instance Method Summary collapse

Instance Method Details

#scope(name = :default) ⇒ Object



592
593
594
# File 'lib/tins/dslkit.rb', line 592

def scope(name = :default)
  scope_get(name).dup
end

#scope_block(scope_frame, name = :default) ⇒ Object



581
582
583
584
585
586
# File 'lib/tins/dslkit.rb', line 581

def scope_block(scope_frame, name = :default)
  scope_push(scope_frame, name)
  yield
ensure
  scope_pop(name)
end

#scope_get(name = :default) ⇒ Object



588
589
590
# File 'lib/tins/dslkit.rb', line 588

def scope_get(name = :default)
  Thread.current[name] ||= []
end

#scope_pop(name = :default) ⇒ Object



567
568
569
570
571
# File 'lib/tins/dslkit.rb', line 567

def scope_pop(name = :default)
  scope_get(name).pop
  scope_get(name).empty? and Thread.current[name] = nil
  self
end

#scope_push(scope_frame, name = :default) ⇒ Object



562
563
564
565
# File 'lib/tins/dslkit.rb', line 562

def scope_push(scope_frame, name = :default)
  scope_get(name).push scope_frame
  self
end

#scope_reverse(name = :default, &block) ⇒ Object



577
578
579
# File 'lib/tins/dslkit.rb', line 577

def scope_reverse(name = :default, &block)
  scope_get(name).reverse_each(&block)
end

#scope_top(name = :default) ⇒ Object



573
574
575
# File 'lib/tins/dslkit.rb', line 573

def scope_top(name = :default)
  scope_get(name).last
end