Sha256: 7188026504a82051ebbc78984c7749432dcf2a8807df051887045d129f41f97e

Contents?: true

Size: 1.04 KB

Versions: 24

Compression:

Stored size: 1.04 KB

Contents

require 'active_support/inflector'

module Brightcontent
  class RoutesParser
    def initialize(routes_hash = nil, engine_resources = Brightcontent.engine_resources)
      @routes_hash = routes_hash
      @engine_resources = engine_resources
    end

    def resources
      Resources.new(resources_array)
    end

    private

    attr_reader :engine_resources

    def resources_array
      (resource_names - engine_resources).map do |name|
        Resource.new(name)
      end
    end

    def resource_names
      routes_hash.map do |route|
        next unless route && route[:controller] && route[:path_spec]
        name = route[:controller].match(/brightcontent\/(.+)/)[1]
        if route[:action] == "index" && route[:path_spec].start_with?('/' + name)
          name
        end
      end.compact.uniq
    end

    def routes_hash
      @routes_hash ||= Engine.routes.routes.map do |r|
        {
          controller: r.defaults[:controller],
          action: r.defaults[:action],
          path_spec: r.path.spec.to_s
        }
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
brightcontent-core-2.6.0 lib/brightcontent/routes_parser.rb
brightcontent-core-2.5.1 lib/brightcontent/routes_parser.rb
brightcontent-core-2.5.0 lib/brightcontent/routes_parser.rb
brightcontent-core-2.4.6 lib/brightcontent/routes_parser.rb
brightcontent-core-2.4.5 lib/brightcontent/routes_parser.rb
brightcontent-core-2.4.4 lib/brightcontent/routes_parser.rb
brightcontent-core-2.4.3 lib/brightcontent/routes_parser.rb
brightcontent-core-2.4.2 lib/brightcontent/routes_parser.rb
brightcontent-core-2.4.1 lib/brightcontent/routes_parser.rb
brightcontent-core-2.4.0 lib/brightcontent/routes_parser.rb
brightcontent-core-2.3.4 lib/brightcontent/routes_parser.rb
brightcontent-core-2.3.3 lib/brightcontent/routes_parser.rb
brightcontent-core-2.3.2 lib/brightcontent/routes_parser.rb
brightcontent-core-2.3.1 lib/brightcontent/routes_parser.rb
brightcontent-core-2.3.0 lib/brightcontent/routes_parser.rb
brightcontent-core-2.2.2 lib/brightcontent/routes_parser.rb
brightcontent-core-2.2.1 lib/brightcontent/routes_parser.rb
brightcontent-core-2.2.0 lib/brightcontent/routes_parser.rb
brightcontent-core-2.1.5 lib/brightcontent/routes_parser.rb
brightcontent-core-2.1.4 lib/brightcontent/routes_parser.rb