Sha256: fc5d51066e78552d0dd7f44ff9200137c1dc66c8dea057499d1ffac62e453ed4

Contents?: true

Size: 822 Bytes

Versions: 8

Compression:

Stored size: 822 Bytes

Contents

require 'active_support/inflector'

module Brightcontent
  class RoutesParser

    def self.parse(routes_hash=nil, engine_resources=nil)
      new(routes_hash, engine_resources).user_resource
    end

    def initialize(routes_hash=nil, engine_resources=nil)
      @routes_hash = routes_hash
      @engine_resources = engine_resources
    end

    def user_resource
      resource_names - engine_resources
    end

    private

    def resource_names
      routes_hash.map do |route|
        if route && route[:action] == "index"
          route[:controller].match(/brightcontent\/(.+)/)[1]
        end
      end.compact
    end

    def routes_hash
      @routes_hash ||= Engine.routes.routes.map(&:defaults)
    end

    def engine_resources
      @engine_resources ||= Brightcontent.engine_resources
    end

  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
brightcontent-core-2.0.2 lib/brightcontent/routes_parser.rb
brightcontent-core-2.0.1 lib/brightcontent/routes_parser.rb
brightcontent-core-2.0.0.alpha6 lib/brightcontent/routes_parser.rb
brightcontent-core-2.0.0.alpha5 lib/brightcontent/routes_parser.rb
brightcontent-2.0.0.alpha3 core/lib/brightcontent/routes_parser.rb
brightcontent-core-2.0.0.alpha3 lib/brightcontent/routes_parser.rb
brightcontent-2.0.0.alpha2 core/lib/brightcontent/routes_parser.rb
brightcontent-core-2.0.0.alpha2 lib/brightcontent/routes_parser.rb