Class: Spree::Core::Engine
- Inherits:
-
Rails::Engine
- Object
- Rails::Engine
- Spree::Core::Engine
- Defined in:
- lib/spree/core/engine.rb,
lib/spree/core/routes.rb,
lib/spree/core/components.rb
Class Method Summary collapse
- .add_routes(&block) ⇒ Object
- .api_available? ⇒ Boolean
- .append_routes(&block) ⇒ Object
- .backend_available? ⇒ Boolean
- .draw_routes(&block) ⇒ Object
- .frontend_available? ⇒ Boolean
Instance Method Summary collapse
Class Method Details
.add_routes(&block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/spree/core/routes.rb', line 4 def self.add_routes(&block) @spree_routes ||= [] # Anything that causes the application's routes to be reloaded, # will cause this method to be called more than once # i.e. https://github.com/plataformatec/devise/blob/31971e69e6a1bcf6c7f01eaaa44f227c4af5d4d2/lib/devise/rails.rb#L14 # In the case of Devise, this *only* happens in the production env # This coupled with Rails 4's insistence that routes are not drawn twice, # poses quite a serious problem. # # This is mainly why this whole file exists in the first place. # # Thus we need to make sure that the routes aren't drawn twice. @spree_routes << block unless @spree_routes.include?(block) end |
.api_available? ⇒ Boolean
4 5 6 |
# File 'lib/spree/core/components.rb', line 4 def self.api_available? @@api_available ||= ::Rails::Engine.subclasses.map(&:instance).map { |e| e.class.to_s }.include?('Spree::Api::Engine') end |
.append_routes(&block) ⇒ Object
20 21 22 23 24 |
# File 'lib/spree/core/routes.rb', line 20 def self.append_routes(&block) @append_routes ||= [] # See comment in add_routes. @append_routes << block unless @append_routes.include?(block) end |
.backend_available? ⇒ Boolean
8 9 10 |
# File 'lib/spree/core/components.rb', line 8 def self.backend_available? @@backend_available ||= ::Rails::Engine.subclasses.map(&:instance).map { |e| e.class.to_s }.include?('Spree::Backend::Engine') end |
.draw_routes(&block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/spree/core/routes.rb', line 26 def self.draw_routes(&block) @spree_routes ||= [] @append_routes ||= [] eval_block(block) if block_given? @spree_routes.each { |r| eval_block(&r) } @append_routes.each { |r| eval_block(&r) } # # Clear out routes so that they aren't drawn twice. @spree_routes = [] @append_routes = [] end |
.frontend_available? ⇒ Boolean
12 13 14 |
# File 'lib/spree/core/components.rb', line 12 def self.frontend_available? @@frontend_available ||= ::Rails::Engine.subclasses.map(&:instance).map { |e| e.class.to_s }.include?('Spree::Frontend::Engine') end |