Class: Class::Category

Inherits:
Object
  • Object
show all
Defined in:
lib/categories.rb

Constant Summary collapse

VERSION =
'1.0.0'

Instance Method Summary collapse

Constructor Details

#initialize(mod, &block) ⇒ Category

:nodoc:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/categories.rb', line 6

def initialize(mod, &block)  # :nodoc:
  category_model = mod if mod.is_a? Module
  category_model.const_set("CATEGORY",self)
  category_model.instance_eval do
    def self.included(klass)  # :nodoc:
      category = const_get("CATEGORY")
      klass.instance_eval(&category.send(:before_include_proc))
      klass.instance_eval do
        extend  category.send(:for_class_module)
        include category.send(:for_instance_module)
      end
      klass.instance_eval(&category.send(:after_include_proc))
    end
  end
  self.instance_eval(&block)
end

Instance Method Details

#after_include(&block) ⇒ Object

This block is executed after the category is included in the host class or module.



29
30
31
# File 'lib/categories.rb', line 29

def after_include(&block)
  self.after_include_proc = block
end

#before_include(&block) ⇒ Object

This block is executed before the category is included in the host class or module.



24
25
26
# File 'lib/categories.rb', line 24

def before_include(&block)
  self.before_include_proc = block
end

#for_class(&block) ⇒ Object

This block defines all the class/module methods of the category.



34
35
36
# File 'lib/categories.rb', line 34

def for_class(&block)
  self.for_class_module = Module.new(&block)
end

#for_instance(&block) ⇒ Object

This block defines all the instance methods of the category.



39
40
41
# File 'lib/categories.rb', line 39

def for_instance(&block)
  self.for_instance_module = Module.new(&block)
end