Class: Prependers::Prepender

Inherits:
Module
  • Object
show all
Defined in:
lib/prependers/prepender.rb

Constant Summary collapse

NAMESPACE_DEPRECATION =
"[DEPRECATION] Passing a namespace to `Prependers::Prepender#[]` is deprecated. Use the " \
"`:namespace` option instead."

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options_or_namespace = {}) ⇒ Prepender

Returns a new instance of Prepender.



15
16
17
18
19
20
21
22
# File 'lib/prependers/prepender.rb', line 15

def initialize(options_or_namespace = {})
  if options_or_namespace.is_a?(Module)
    warn NAMESPACE_DEPRECATION % { namespace: options_or_namespace }
    options_or_namespace = { namespace: options_or_namespace }
  end

  @options = options_or_namespace
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/prependers/prepender.rb', line 9

def options
  @options
end

Class Method Details

.[](options = {}) ⇒ Object



5
6
7
# File 'lib/prependers/prepender.rb', line 5

def self.[](options = {})
  new(options)
end

Instance Method Details

#included(base) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/prependers/prepender.rb', line 24

def included(base)
  if options.key?(:namespace)
    base.include Prependers::Annotate::Namespace.new(options[:namespace])
  end

  if options.key?(:verify)
    base.include Prependers::Annotate::Verify.new(options[:verify])
  end

  prependable = Prependers.prependable_for(base)

  prependable.prepend(base)

  if base.const_defined?('ClassMethods')
    prependable.singleton_class.prepend(base.const_get('ClassMethods'))
  end
end