Module: GlueGun::DSL::Initialization

Defined in:
lib/glue_gun/dsl.rb

Instance Method Summary collapse

Instance Method Details

#initialize(attrs = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/glue_gun/dsl.rb', line 52

def initialize(attrs = {})
  attrs ||= {}
  attrs = attrs.symbolize_keys
  # Separate dependency configurations from normal attributes
  dependency_attributes = {}
  normal_attributes = {}

  attrs.each do |key, value|
    if self.class.dependency_definitions.key?(key)
      dependency_attributes[key] = value
    else
      normal_attributes[key] = value
    end
  end

  if attribute_definitions.keys.include?(:root_dir) && attribute_definitions.dig(:root_dir, :options,
                                                                                 :default).nil?
    normal_attributes.reverse_merge!(root_dir: detect_root_dir)
  end

  # Call super to allow ActiveModel to assign attributes
  super(normal_attributes)

  # Initialize dependencies after attributes have been set
  initialize_dependencies(dependency_attributes)

  @initialized = true
end