Module: Concern

Included in:
Mangadex::Internal::WithAttributes
Defined in:
lib/extensions.rb

Defined Under Namespace

Classes: MultipleIncludedBlocks, MultiplePrependBlocks

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

:nodoc:



141
142
143
# File 'lib/extensions.rb', line 141

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

Instance Method Details

#append_features(base) ⇒ Object

:nodoc:



145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/extensions.rb', line 145

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



199
200
201
202
203
204
205
# File 'lib/extensions.rb', line 199

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



171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/extensions.rb', line 171

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

#prepend_features(base) ⇒ Object

:nodoc:



158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/extensions.rb', line 158

def prepend_features(base) # :nodoc:
  if base.instance_variable_defined?(:@_dependencies)
    base.instance_variable_get(:@_dependencies).unshift self
    false
  else
    return false if base < self
    @_dependencies.each { |dep| base.prepend(dep) }
    super
    base.singleton_class.prepend const_get(:ClassMethods) if const_defined?(:ClassMethods)
    base.class_eval(&@_prepended_block) if instance_variable_defined?(:@_prepended_block)
  end
end

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



185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/extensions.rb', line 185

def prepended(base = nil, &block)
  if base.nil?
    if instance_variable_defined?(:@_prepended_block)
      if @_prepended_block.source_location != block.source_location
        raise MultiplePrependBlocks
      end
    else
      @_prepended_block = block
    end
  else
    super
  end
end