Class: FlossFunding::Inclusion

Inherits:
Object
  • Object
show all
Includes:
FileFinder
Defined in:
lib/floss_funding/inclusion.rb

Overview

Represents the runtime inclusion context for a given inclusion of FlossFunding.
Encapsulates discovery (Namespace, Library), activation state, and the
ActivationEvent generated from an include site.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FileFinder

#find_file_upwards, #find_last_file_upwards, root_level=, root_level?

Constructor Details

#initialize(base, custom_namespace, including_path, options = {}) ⇒ Inclusion

Build an Inclusion and register its activation event.

Parameters:

  • base (Module)

    the including module

  • custom_namespace (String, nil)
  • including_path (String, nil)
  • options (Hash) (defaults to: {})

    additional options (e.g., :config_path)

Options Hash (options):

  • :silent (#call) — default: nil

Raises:



50
51
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/floss_funding/inclusion.rb', line 50

def initialize(base, custom_namespace, including_path, options = {})
  @options = options.dup
  @base = base
  @including_path = including_path
  @silent = @options.delete(:silent)
  @config_path = @options.delete(:config_path)
  # Assign early so validation sees the actual provided value
  @custom_namespace = custom_namespace

  validate_inputs!

  @name =
    if custom_namespace.is_a?(String) && !custom_namespace.empty?
      @custom_namespace = custom_namespace
    else
      @base_name = base.name
    end

  ### NAMESPACE (not frozen!) ###
  @namespace = FlossFunding::Namespace.new(@name, base)
  @activation_key = @namespace.activation_key
  @state = @namespace.state

  reason = discover_library_root_path
  raise ::FlossFunding::Error, "Missing library root path due to: #{reason}" unless @library_root_path

  if @config_path
    discover_config_path
  else
    discover_config_path_from_library_root
  end

  # Derive config data from @config_path by parsing .floss_funding.yml.
  data_from_config_file
  validate_config_data

  @library_name = @config_data["library_name"].first

  ### CONFIGURATION (frozen object!) ###
  @configuration = FlossFunding::Configuration.new(@config_data)

  ### LIBRARY (frozen object!) ###
  @library = ::FlossFunding::Library.new(
    @library_name,
    @namespace,
    @custom_namespace,
    @base_name,
    @including_path,
    @library_root_path,
    @config_path,
    @namespace.env_var_name,
    @configuration,
    @silent,
  )

  ### ACTIVATION EVENT (frozen object!) ###
  @event = ::FlossFunding::ActivationEvent.new(
    @library,
    @activation_key,
    @state,
    @silent,
  )

  FlossFunding.add_or_update_namespace_with_event(@namespace, @event)
  FlossFunding.initiate_begging(@event)
end

Instance Attribute Details

#activation_keyString (readonly)

Returns:

  • (String)


29
30
31
# File 'lib/floss_funding/inclusion.rb', line 29

def activation_key
  @activation_key
end

#baseModule (readonly)

Returns:

  • (Module)


11
12
13
# File 'lib/floss_funding/inclusion.rb', line 11

def base
  @base
end

#config_dataHash (readonly)

Returns:

  • (Hash)


39
40
41
# File 'lib/floss_funding/inclusion.rb', line 39

def config_data
  @config_data
end

#config_pathString? (readonly)

Returns:

  • (String, nil)


37
38
39
# File 'lib/floss_funding/inclusion.rb', line 37

def config_path
  @config_path
end

#configurationFlossFunding::Configuration (readonly)



41
42
43
# File 'lib/floss_funding/inclusion.rb', line 41

def configuration
  @configuration
end

#custom_namespaceString? (readonly)

Returns:

  • (String, nil)


19
20
21
# File 'lib/floss_funding/inclusion.rb', line 19

def custom_namespace
  @custom_namespace
end

#eventFlossFunding::ActivationEvent (readonly)



33
34
35
# File 'lib/floss_funding/inclusion.rb', line 33

def event
  @event
end

#including_pathString (readonly)

Returns:

  • (String)


13
14
15
# File 'lib/floss_funding/inclusion.rb', line 13

def including_path
  @including_path
end

#libraryFlossFunding::Library (readonly)



27
28
29
# File 'lib/floss_funding/inclusion.rb', line 27

def library
  @library
end

#library_nameString (readonly)

Returns:

  • (String)


17
18
19
# File 'lib/floss_funding/inclusion.rb', line 17

def library_name
  @library_name
end

#library_root_pathString (readonly)

Returns:

  • (String)


15
16
17
# File 'lib/floss_funding/inclusion.rb', line 15

def library_root_path
  @library_root_path
end

#nameString (readonly)

Returns:

  • (String)


23
24
25
# File 'lib/floss_funding/inclusion.rb', line 23

def name
  @name
end

#namespaceFlossFunding::Namespace (readonly)



25
26
27
# File 'lib/floss_funding/inclusion.rb', line 25

def namespace
  @namespace
end

#optionsHash (readonly)

Returns:

  • (Hash)


35
36
37
# File 'lib/floss_funding/inclusion.rb', line 35

def options
  @options
end

#silent#call? (readonly)

Returns:

  • (#call, nil)


21
22
23
# File 'lib/floss_funding/inclusion.rb', line 21

def silent
  @silent
end

#stateString (readonly)

Returns:

  • (String)


31
32
33
# File 'lib/floss_funding/inclusion.rb', line 31

def state
  @state
end