Class: ROM::Components::Provider Private
- Inherits:
-
Module
- Object
- Module
- ROM::Components::Provider
- Defined in:
- lib/rom/components/provider.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.
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Instance Attribute Summary collapse
- #features ⇒ Object readonly private
- #provider ⇒ Object readonly private
- #type ⇒ Object readonly private
Instance Method Summary collapse
- #define_configure_method(type, features) {|Module.new { define_method(:configure) do |*args, &block| # Inherit global defaults config.component.inherit!(**ROM.config[type], type: type) # Inherit global defaults for individual features features.each do |name| config[name].inherit!(**ROM.config[name]) if ROM.config.key?(name) end super(*args, &block) end }| ... } ⇒ Object private
- #define_dsl_method(mod, name) ⇒ Object private
- #extended(provider) ⇒ Object private
- #import_settings ⇒ Object private
- #included(provider) ⇒ Object private
-
#initialize(features, type: nil) ⇒ Provider
constructor
private
A new instance of Provider.
- #mod ⇒ Object private
Constructor Details
#initialize(features, type: nil) ⇒ Provider
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 Provider.
62 63 64 65 66 67 |
# File 'lib/rom/components/provider.rb', line 62 def initialize(features, type: nil) super() @provider = nil @type = type @features = features end |
Instance Attribute Details
#features ⇒ Object (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.
30 31 32 |
# File 'lib/rom/components/provider.rb', line 30 def features @features end |
#provider ⇒ Object (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.
26 27 28 |
# File 'lib/rom/components/provider.rb', line 26 def provider @provider end |
#type ⇒ Object (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.
28 29 30 |
# File 'lib/rom/components/provider.rb', line 28 def type @type end |
Instance Method Details
#define_configure_method(type, features) {|Module.new { define_method(:configure) do |*args, &block| # Inherit global defaults config.component.inherit!(**ROM.config[type], type: type) # Inherit global defaults for individual features features.each do |name| config[name].inherit!(**ROM.config[name]) if ROM.config.key?(name) end super(*args, &block) end }| ... } ⇒ Object
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.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rom/components/provider.rb', line 70 def define_configure_method(type, features) yield Module.new { define_method(:configure) do |*args, &block| # Inherit global defaults config.component.inherit!(**ROM.config[type], type: type) # Inherit global defaults for individual features features.each do |name| config[name].inherit!(**ROM.config[name]) if ROM.config.key?(name) end super(*args, &block) end } end |
#define_dsl_method(mod, name) ⇒ Object
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.
139 140 141 142 143 |
# File 'lib/rom/components/provider.rb', line 139 def define_dsl_method(mod, name) mod.define_method(name) { |*args, **opts, &block| DSL.instance_method(name).bind(self).(*args, **opts, &block) } end |
#extended(provider) ⇒ Object
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.
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/rom/components/provider.rb', line 101 def extended(provider) super @provider = provider provider.extend(mod) provider.extend(Configurable) import_settings provider.extend(ClassMethods) define_configure_method(type, features) { |mod| provider.singleton_class.prepend(mod) } freeze end |
#import_settings ⇒ Object
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.
146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/rom/components/provider.rb', line 146 def import_settings # Import default settings for the provider provider.setting(:component, import: ROM.settings[type]) # Import default settings for each feature that the provider supports features.each do |name| if ROM.settings.key?(name) # Define the settings provider.setting(name, import: ROM.settings[name]) end end end |
#included(provider) ⇒ Object
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.
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/rom/components/provider.rb', line 87 def included(provider) super @provider = provider provider.include(mod) provider.include(Configurable) import_settings provider.include(InstanceMethods) define_configure_method(type, features) { |mod| provider.prepend(mod) } freeze end |
#mod ⇒ Object
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.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/rom/components/provider.rb', line 115 def mod @mod ||= Module.new.tap do |mod| define_dsl_method(mod, :__dsl__) features.each do |type| if ROM.components.key?(type) handler = ROM.components[type] [handler.key, handler.namespace] .select { |name| DSL.instance_methods.include?(name) } .each { |name| define_dsl_method(mod, name) } else define_dsl_method(mod, type) end end end end |