Sha256: 71184527b2502a2f5ef75b288bc555d1c74670d34793eb23e32ede45bf94eddc

Contents?: true

Size: 824 Bytes

Versions: 14

Compression:

Stored size: 824 Bytes

Contents

# Some template bindings share the controller with other template bindings based
# on a name.  This class keeps track of the number of templates using this controller
# and clears it once no one else is using it.  Use #get or #inc to add to the count.
# #clear removes 1 from the count.  When the count is 0, delete the controller.
class GroupedControllers
  @@controllers = {}

  def initialize(name)
    @name = name
  end

  def get
    return (controller = self.controller) && controller[0]
  end

  def set(controller)
    @@controllers[@name] = [controller, 1]
  end

  def inc
    controller[1] += 1
  end

  def clear
    controller = self.controller
    controller[1] -= 1
    if controller[1] == 0
      @@controllers.delete(@name)
    end
  end

  private
    def controller
      @@controllers[@name]
    end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
volt-0.8.14 lib/volt/page/bindings/template_binding/grouped_controllers.rb
volt-0.8.13 lib/volt/page/bindings/template_binding/grouped_controllers.rb
volt-0.8.11 lib/volt/page/bindings/template_binding/grouped_controllers.rb
volt-0.8.10 lib/volt/page/bindings/template_binding/grouped_controllers.rb
volt-0.8.9 lib/volt/page/bindings/template_binding/grouped_controllers.rb
volt-0.8.8 lib/volt/page/bindings/template_binding/grouped_controllers.rb
volt-0.8.7 lib/volt/page/bindings/template_binding/grouped_controllers.rb
volt-0.8.6 lib/volt/page/bindings/template_binding/grouped_controllers.rb
volt-0.8.5 lib/volt/page/bindings/template_binding/grouped_controllers.rb
volt-0.8.4 lib/volt/page/bindings/template_binding/grouped_controllers.rb
volt-0.8.3 lib/volt/page/bindings/template_binding/grouped_controllers.rb
volt-0.8.2 lib/volt/page/bindings/template_binding/grouped_controllers.rb
volt-0.8.1 lib/volt/page/bindings/template_binding/grouped_controllers.rb
volt-0.8.0 lib/volt/page/bindings/template_binding/grouped_controllers.rb