Sha256: c8125c65072ee089a814ca29d147b3cbea6fb813988705f434645aefd9dfa1b3

Contents?: true

Size: 890 Bytes

Versions: 1

Compression:

Stored size: 890 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.
module Volt
  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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
volt-0.8.15 lib/volt/page/bindings/template_binding/grouped_controllers.rb