Class: Virtus::Builder::HookContext

Inherits:
Object
  • Object
show all
Defined in:
lib/virtus/builder/hook_context.rb

Overview

Context used for building “included” and “extended” hooks

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(builder, config) ⇒ HookContext

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of HookContext.



11
12
13
14
# File 'lib/virtus/builder/hook_context.rb', line 11

def initialize(builder, config)
  @builder, @config = builder, config
  initialize_attribute_method
end

Instance Attribute Details

#attribute_methodObject (readonly)



8
9
10
# File 'lib/virtus/builder/hook_context.rb', line 8

def attribute_method
  @attribute_method
end

#builderObject (readonly)



8
9
10
# File 'lib/virtus/builder/hook_context.rb', line 8

def builder
  @builder
end

#configObject (readonly)



8
9
10
# File 'lib/virtus/builder/hook_context.rb', line 8

def config
  @config
end

Instance Method Details

#constructor?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


25
26
27
# File 'lib/virtus/builder/hook_context.rb', line 25

def constructor?
  config.constructor
end

#finalize?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


35
36
37
# File 'lib/virtus/builder/hook_context.rb', line 35

def finalize?
  config.finalize
end

#initialize_attribute_methodObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
41
42
43
44
45
46
# File 'lib/virtus/builder/hook_context.rb', line 40

def initialize_attribute_method
  method_options = builder.options

  @attribute_method = lambda do |name, type = nil, options = {}|
    super(name, type, method_options.merge(options))
  end
end

#mass_assignment?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


30
31
32
# File 'lib/virtus/builder/hook_context.rb', line 30

def mass_assignment?
  config.mass_assignment
end

#modulesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



17
18
19
20
21
22
# File 'lib/virtus/builder/hook_context.rb', line 17

def modules
  modules = builder.extensions
  modules << Model::Constructor    if constructor?
  modules << Model::MassAssignment if mass_assignment?
  modules
end