Class: ROM::Rails::Railtie
- Inherits:
-
Rails::Railtie
- Object
- Rails::Railtie
- ROM::Rails::Railtie
- Defined in:
- lib/rom/rails/railtie.rb
Constant Summary collapse
- COMPONENT_DIRS =
%w(relations mappers commands).freeze
- MissingGatewayConfigError =
Class.new(StandardError)
Instance Method Summary collapse
- #active_record? ⇒ Boolean private
-
#configure(&block) ⇒ Object
Behaves like ‘Railtie#configure` if the given block does not take any arguments.
- #container ⇒ Object
- #create_configuration ⇒ Object
- #create_container ⇒ Object private
- #disconnect ⇒ Object private
- #gateways ⇒ Object private
-
#infer_default_gateway ⇒ Object
private
If there’s no default gateway configured, try to infer it from other sources, e.g.
- #load_initializer ⇒ Object
- #root ⇒ Object private
Instance Method Details
#active_record? ⇒ 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.
116 117 118 |
# File 'lib/rom/rails/railtie.rb', line 116 def active_record? defined?(::ActiveRecord) end |
#configure(&block) ⇒ Object
Behaves like ‘Railtie#configure` if the given block does not take any arguments. Otherwise yields the ROM configuration to the block.
55 56 57 58 59 60 61 62 63 |
# File 'lib/rom/rails/railtie.rb', line 55 def configure(&block) config.rom = Configuration.new unless config.respond_to?(:rom) if block.arity == 1 block.call(config.rom) else super end end |
#container ⇒ Object
111 112 113 |
# File 'lib/rom/rails/railtie.rb', line 111 def container ROM.env end |
#create_configuration ⇒ Object
65 66 67 |
# File 'lib/rom/rails/railtie.rb', line 65 def create_configuration ROM::Configuration.new(gateways) end |
#create_container ⇒ 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 |
# File 'lib/rom/rails/railtie.rb', line 70 def create_container configuration = create_configuration configuration.auto_registration(root.join("app"), namespace: false) ROM.container(configuration) end |
#disconnect ⇒ 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.
102 103 104 |
# File 'lib/rom/rails/railtie.rb', line 102 def disconnect container.disconnect unless container.nil? end |
#gateways ⇒ 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.
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rom/rails/railtie.rb', line 77 def gateways config.rom.gateways[:default] ||= infer_default_gateway if active_record? raise( MissingGatewayConfigError, "seems like you didn't configure any gateways" ) unless config.rom.gateways.any? config.rom.gateways end |
#infer_default_gateway ⇒ 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.
If there’s no default gateway configured, try to infer it from other sources, e.g. ActiveRecord.
92 93 94 95 |
# File 'lib/rom/rails/railtie.rb', line 92 def infer_default_gateway spec = ROM::Rails::ActiveRecord::Configuration.call [:sql, spec[:uri], spec[:options]] end |
#load_initializer ⇒ Object
97 98 99 |
# File 'lib/rom/rails/railtie.rb', line 97 def load_initializer load "#{root}/config/initializers/rom.rb" rescue LoadError end |
#root ⇒ 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.
107 108 109 |
# File 'lib/rom/rails/railtie.rb', line 107 def root ::Rails.root end |