Module: FlossFunding

Defined in:
lib/floss_funding/silent.rb,
lib/floss_funding/poke.rb,
lib/floss_funding/check.rb,
lib/floss_funding/config.rb,
lib/floss_funding/version.rb,
lib/floss_funding/constants.rb,
lib/floss_funding/under_bar.rb,
lib/floss_funding.rb

Overview

Now declare some constants

Defined Under Namespace

Modules: Check, Config, Constants, Poke, Silent, UnderBar, Version Classes: Error

Constant Summary collapse

FREE_AS_IN_BEER =

Unpaid activation option intended for open-source and not-for-profit use.

Returns:

  • (String)
"Free-as-in-beer"
BUSINESS_IS_NOT_GOOD_YET =

Unpaid activation option acknowledging commercial use without payment.

Returns:

  • (String)
"Business-is-not-good-yet"
NOT_FINANCIALLY_SUPPORTING =

Activation option to explicitly opt out of funding prompts for a namespace.

Returns:

  • (String)
"Not-financially-supporting"
START_MONTH =

First month index against which base words are validated.
Do not change once released as it would invalidate existing activation keys.

Returns:

  • (Integer)
Month.new(2025, 7).to_i
BASE_WORDS_PATH =

Absolute path to the base words list used for paid activation validation.

Returns:

  • (String)
File.expand_path("../../base.txt", __FILE__)
EIGHT_BYTES =

Number of hex characters required for a paid activation key (64 = 256 bits).

Returns:

  • (Integer)
64
HEX_LICENSE_RULE =

Format for a paid activation key (64 hex chars).

Returns:

  • (Regexp)
/\A[0-9a-fA-F]{#{EIGHT_BYTES}}\z/
<<-FOOTER
=====================================================================================
- Please buy FLOSS "peace-of-mind" activation keys to support open source developers.
floss_funding v#{::FlossFunding::Version::VERSION} is made with ❤️ in 🇺🇸 & 🇮🇩 by Galtzo FLOSS (galtzo.com)
FOOTER

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.mutexObject (readonly)

Provides access to the mutex for thread synchronization



76
77
78
# File 'lib/floss_funding.rb', line 76

def mutex
  @mutex
end

Class Method Details

.activatedArray<String>

New name: activated (preferred)

Returns:

  • (Array<String>)


80
81
82
# File 'lib/floss_funding.rb', line 80

def activated
  mutex.synchronize { @activated.dup }
end

.activated=(value) ⇒ Object

New name: activated= (preferred)

Parameters:

  • value (Array<String>)


86
87
88
# File 'lib/floss_funding.rb', line 86

def activated=(value)
  mutex.synchronize { @activated = value }
end

.activation_occurrencesArray<String>

Thread-safe getter for all activation occurrences (each successful activation event)

Returns:

  • (Array<String>)

    list of namespaces for each activation occurrence



171
172
173
# File 'lib/floss_funding.rb', line 171

def activation_occurrences
  mutex.synchronize { @activation_occurrences.dup }
end

.add_activated(library) ⇒ Object

Thread-safely adds a library to the activated list
Ensures no duplicates are added

Parameters:

  • library (String)

    Namespace of the library to add



105
106
107
# File 'lib/floss_funding.rb', line 105

def add_activated(library)
  mutex.synchronize { @activated << library unless @activated.include?(library) }
end

.add_activation_occurrence(namespace) ⇒ Object

Record a single activation occurrence (may include duplicates per namespace)

Parameters:

  • namespace (String)


177
178
179
# File 'lib/floss_funding.rb', line 177

def add_activation_occurrence(namespace)
  mutex.synchronize { @activation_occurrences << namespace }
end

.add_unactivated(library) ⇒ Object

Thread-safely adds a library to the unactivated list
Ensures no duplicates are added

Parameters:

  • library (String)

    Namespace of the library to add



112
113
114
# File 'lib/floss_funding.rb', line 112

def add_unactivated(library)
  mutex.synchronize { @unactivated << library unless @unactivated.include?(library) }
end

.base_words(num_valid_words) ⇒ Array<String>

Reads the first N lines from the base words file to validate paid activation keys.

Parameters:

  • num_valid_words (Integer)

    number of words to read from the word list

Returns:

  • (Array<String>)

    the first N words; empty when N is nil or zero



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

def base_words(num_valid_words)
  return [] if num_valid_words.nil? || num_valid_words.zero?
  File.open(::FlossFunding::BASE_WORDS_PATH, "r") do |file|
    lines = []
    num_valid_words.times do
      line = file.gets
      break if line.nil?
      lines << line.chomp
    end
    lines
  end
end

.configuration(library) ⇒ Hash

Thread-safe getter for a specific library’s configuration

Parameters:

  • library (String)

    Namespace of the library

Returns:

  • (Hash)

    Configuration for the library; always a hash, but might be empty



126
127
128
# File 'lib/floss_funding.rb', line 126

def configuration(library)
  mutex.synchronize { @configurations[library].dup }
end

.configurationsHash

Thread-safe accessor for the configurations hash
Returns a duplicate to prevent external modification

Returns:

  • (Hash)

    Hash of library configurations



119
120
121
# File 'lib/floss_funding.rb', line 119

def configurations
  mutex.synchronize { @configurations.dup }
end

.env_var_name_for(library) ⇒ String?

Thread-safe getter for ENV var name used by a library

Parameters:

  • library (String)

Returns:

  • (String, nil)


159
160
161
# File 'lib/floss_funding.rb', line 159

def env_var_name_for(library)
  mutex.synchronize { @env_var_names[library] }
end

.env_var_namesHash{String=>String}

Thread-safe getter for all ENV var names

Returns:

  • (Hash{String=>String})


165
166
167
# File 'lib/floss_funding.rb', line 165

def env_var_names
  mutex.synchronize { @env_var_names.dup }
end

.set_configuration(library, config) ⇒ Object

Thread-safe setter for a library’s configuration

Parameters:

  • library (String)

    Namespace of the library

  • config (Hash)

    Configuration for the library



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/floss_funding.rb', line 133

def set_configuration(library, config)
  mutex.synchronize do
    existing = @configurations[library]
    merged = {}
    # Ensure all known keys are arrays and merged
    keys = (existing.keys + config.keys).uniq
    keys.each do |k|
      merged[k] = []
      merged[k].concat(Array(existing[k])) if existing.key?(k)
      merged[k].concat(Array(config[k])) if config.key?(k)
      merged[k] = merged[k].compact.flatten.uniq
    end
    @configurations[library] = merged
  end
end

.set_env_var_name(library, env_var_name) ⇒ Object

Thread-safe setter for ENV var name used by a library

Parameters:

  • library (String)
  • env_var_name (String)


152
153
154
# File 'lib/floss_funding.rb', line 152

def set_env_var_name(library, env_var_name)
  mutex.synchronize { @env_var_names[library] = env_var_name }
end

.unactivatedArray<String>

New name: unactivated (preferred)

Returns:

  • (Array<String>)


92
93
94
# File 'lib/floss_funding.rb', line 92

def unactivated
  mutex.synchronize { @unactivated.dup }
end

.unactivated=(value) ⇒ Object

New name: unactivated= (preferred)

Parameters:

  • value (Array<String>)


98
99
100
# File 'lib/floss_funding.rb', line 98

def unactivated=(value)
  mutex.synchronize { @unactivated = value }
end