Module: Tins::Concern

Defined in:
lib/tins/concern.rb,
lib/tins/xt/concern.rb

Defined Under Namespace

Modules: ModuleMixin

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



3
4
5
# File 'lib/tins/concern.rb', line 3

def self.extended(base)
  base.instance_variable_set("@_dependencies", [])
end

Instance Method Details

#append_features(base) ⇒ Object



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

def append_features(base)
  if base.instance_variable_defined?("@_dependencies")
    base.instance_variable_get("@_dependencies") << self
    false
  else
    return false if base < self
    @_dependencies.each { |dep| base.send(:include, dep) }
    super
    base.extend const_get("ClassMethods") if const_defined?("ClassMethods")
    base.class_eval(&@_included_block) if instance_variable_defined?("@_included_block")
    Thread.current[:tin_concern_args] = nil
    true
  end
end

#class_methods(&block) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/tins/concern.rb', line 57

def class_methods(&block)
  modul = const_get(:ClassMethods) if const_defined?(:ClassMethods, false)
  unless modul
    modul = Module.new
    const_set(:ClassMethods, modul)
  end
  modul.module_eval(&block)
end

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



37
38
39
40
41
42
43
44
45
# File 'lib/tins/concern.rb', line 37

def included(base = nil, &block)
  if base.nil?
    instance_variable_defined?(:@_included_block) and
      raise StandardError, "included block already defined"
    @_included_block = block
  else
    super
  end
end

#prepend_features(base) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tins/concern.rb', line 22

def prepend_features(base)
  if base.instance_variable_defined?("@_dependencies")
    base.instance_variable_get("@_dependencies") << self
    false
  else
    return false if base < self
    @_dependencies.each { |dep| base.send(:include, dep) }
    super
    base.extend const_get("ClassMethods") if const_defined?("ClassMethods")
    base.class_eval(&@_prepended_block) if instance_variable_defined?("@_prepended_block")
    Thread.current[:tin_concern_args] = nil
    true
  end
end

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



47
48
49
50
51
52
53
54
55
# File 'lib/tins/concern.rb', line 47

def prepended(base = nil, &block)
  if base.nil?
    instance_variable_defined?(:@_prepended_block) and
      raise StandardError, "prepended block already defined"
    @_prepended_block = block
  else
    super
  end
end