Class: ROM::Configurable::Config Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rom/support/configurable.rb

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

Constant Summary collapse

WRITER_REGEXP =

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

/=$/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ Config

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 Config.



15
16
17
# File 'lib/rom/support/configurable.rb', line 15

def initialize(settings = {})
  @settings = settings
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &_block) ⇒ Object (private)

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.



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rom/support/configurable.rb', line 66

def method_missing(meth, *args, &_block)
  return settings.fetch(meth, nil) if frozen?

  name = meth.to_s
  key = name.gsub(WRITER_REGEXP, '').to_sym

  if writer?(name)
    settings[key] = args.first
  else
    settings.fetch(key) { settings[key] = self.class.new }
  end
end

Instance Attribute Details

#settingsObject (readonly)

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.



12
13
14
# File 'lib/rom/support/configurable.rb', line 12

def settings
  @settings
end

Instance Method Details

#[](name) ⇒ Mixed

Return a setting

Returns:

  • (Mixed)


24
25
26
# File 'lib/rom/support/configurable.rb', line 24

def [](name)
  public_send(name)
end

#dupObject

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.



49
50
51
# File 'lib/rom/support/configurable.rb', line 49

def dup
  self.class.new(dup_settings(settings))
end

#freezeObject

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.



38
39
40
41
# File 'lib/rom/support/configurable.rb', line 38

def freeze
  settings.each_value(&:freeze)
  super
end

#key?(name) ⇒ 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)


29
30
31
# File 'lib/rom/support/configurable.rb', line 29

def key?(name)
  settings.key?(name)
end

#respond_to_missing?(_name, _include_private = false) ⇒ 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)


44
45
46
# File 'lib/rom/support/configurable.rb', line 44

def respond_to_missing?(_name, _include_private = false)
  true
end

#to_hashObject

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.



33
34
35
# File 'lib/rom/support/configurable.rb', line 33

def to_hash
  settings
end