Module: Classy::Yaml

Defined in:
lib/classy/yaml.rb,
lib/classy/yaml/engine.rb,
lib/classy/yaml/helpers.rb,
lib/classy/yaml/version.rb,
lib/classy/yaml/component_helpers.rb,
lib/classy/yaml/invalid_key_error.rb

Defined Under Namespace

Modules: ComponentHelpers, Helpers Classes: Engine, InvalidKeyError

Constant Summary collapse

VERSION =
'1.4.0'
@@default_file =
"config/utility_classes.yml"
@@engine_files =
[]
@@extra_files =
[]

Class Method Summary collapse

Class Method Details

.cached_default_yamlObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/classy/yaml.rb', line 57

def self.cached_default_yaml
  # Bypass cache in development and test environments
  return load_default_yaml if Rails.env.development? || Rails.env.test?

  # Use cache in other environments
  return @cached_default_yaml if @cached_default_yaml

  @load_lock.synchronize do
    return @cached_default_yaml if @cached_default_yaml
    @cached_default_yaml = load_default_yaml
  end
end

.cached_engine_yamlsObject

– Cached Data Accessors (Lazy Loading) –



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/classy/yaml.rb', line 43

def self.cached_engine_yamls
  # Bypass cache in development and test environments
  return load_engine_yamls if Rails.env.development? || Rails.env.test?

  # Use cache in other environments
  return @cached_engine_yamls if @cached_engine_yamls

  @load_lock.synchronize do
    # Double-check idiom to ensure loading happens only once
    return @cached_engine_yamls if @cached_engine_yamls
    @cached_engine_yamls = load_engine_yamls
  end
end

.default_file=(value) ⇒ Object



37
38
39
40
# File 'lib/classy/yaml.rb', line 37

def self.default_file=(value)
  @@default_file = value
  @cached_default_yaml = nil # Clear cache on reassignment
end

.engine_files=(value) ⇒ Object

– Configuration Setters with Path Resolution –



27
28
29
30
# File 'lib/classy/yaml.rb', line 27

def self.engine_files=(value)
  @@engine_files = Array.wrap(value).reject(&:blank?).map { |file| Rails.root.join(file) }
  @cached_engine_yamls = nil # Clear cache on reassignment
end

.extra_files=(value) ⇒ Object



32
33
34
35
# File 'lib/classy/yaml.rb', line 32

def self.extra_files=(value)
  @@extra_files = Array.wrap(value).reject(&:blank?).map { |file| Rails.root.join(file) }
  # Note: extra_files are not cached globally by default
end

.setup {|_self| ... } ⇒ Object

– Setup Method –

Yields:

  • (_self)

Yield Parameters:

  • _self (Classy::Yaml)

    the object that the method was called on



71
72
73
74
75
76
# File 'lib/classy/yaml.rb', line 71

def self.setup
  yield self
  # Clear all caches when configuration changes
  @cached_engine_yamls = nil
  @cached_default_yaml = nil
end