Module: HOALife::Concern

Included in:
Resources::HasNestedObject, Resources::HasNestedResources, Resources::Persistable
Defined in:
lib/hoalife/concern.rb

Overview

Defined Under Namespace

Classes: MultipleIncludedBlocks

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

:nodoc:



12
13
14
# File 'lib/hoalife/concern.rb', line 12

def self.extended(base) #:nodoc:
  base.instance_variable_set(:@_dependencies, [])
end

Instance Method Details

#append_features(base) ⇒ Object

:nodoc:



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/hoalife/concern.rb', line 16

def append_features(base) #:nodoc:
  if base.instance_variable_defined?(:@_dependencies)
    base.instance_variable_get(:@_dependencies) << self
    false
  else
    return false if base < self

    @_dependencies.each { |dep| base.include(dep) }
    super
    base.extend const_get(:ClassMethods) if const_defined?(:ClassMethods)
    base.class_eval(&@_included_block) if instance_variable_defined?(:@_included_block)
  end
end

#class_methods(&class_methods_module_definition) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/hoalife/concern.rb', line 44

def class_methods(&class_methods_module_definition)
  mod = const_defined?(:ClassMethods, false) ?
    const_get(:ClassMethods) :
    const_set(:ClassMethods, Module.new)

  mod.module_eval(&class_methods_module_definition)
end

#included(base = nil, &block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/hoalife/concern.rb', line 30

def included(base = nil, &block)
  if base.nil?
    if instance_variable_defined?(:@_included_block)
      if @_included_block.source_location != block.source_location
        raise MultipleIncludedBlocks
      end
    else
      @_included_block = block
    end
  else
    super
  end
end