Sha256: 8d1c688d268871296ab42a68d1ee913ca4ddf59c519fa3c67e5e08d811026a51

Contents?: true

Size: 1.43 KB

Versions: 4

Compression:

Stored size: 1.43 KB

Contents

module Zena
  # This module is used to declare and manage the list of features used by Zena.
  module Use
    SUFFIX_NAME  = 'Methods'
    MODULE_NAMES = %w{Controller View Zafu User Site Skin}
    # "Controller" => "ControllerMethods"
    MODULE_NAME  = Hash[*MODULE_NAMES.map {|n| [n, "#{n}#{SUFFIX_NAME}"]}.flatten]

    class << self
      attr_accessor :modules

      # Declare a module (or list of modules) that should be used in Zena. The module should implement
      # sub-modules named ControllerMethods, ViewMethods or ZafuMethods in order to add features to
      # the controller, view or zafu compiler respectively.
      def module(*modules)
        create_module_hash

        modules.flatten.each do |mod|
          MODULE_NAME.each do |key, sub_module_name|
            begin
              self.modules[key] << mod.const_get(sub_module_name)
            rescue NameError
              # ignore
            end
          end
        end
      end

      def each_module_for(name)
        create_module_hash
        modules_for(name).each do |mod|
          yield(mod)
        end
      end

      def modules_for(name)
        create_module_hash
        self.modules[name] || []
      end

      private
        def create_module_hash
          if self.modules.nil?
            modules = (self.modules = {})
            MODULE_NAME.each do |key, value|
              modules[key] = []
            end
          end
        end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
zena-1.1.3 lib/zena/use.rb
zena-1.1.2 lib/zena/use.rb
zena-1.1.1 lib/zena/use.rb
zena-1.1.0 lib/zena/use.rb