Sha256: ef5c1e68ce535af215b1bffaf664631d4fdafbb1c5108ad635416a59b2ce4a0a

Contents?: true

Size: 1.59 KB

Versions: 14

Compression:

Stored size: 1.59 KB

Contents

require 'active_support/concern'

module Neo4j
  module Core
    class CypherSession
      module Adaptors
        # Containing the logic for dealing with adaptors which use URIs
        module HasUri
          extend ActiveSupport::Concern

          module ClassMethods
            attr_reader :default_uri

            def default_url(default_url)
              @default_uri = uri_from_url!(default_url)
            end

            def validate_uri(&block)
              @uri_validator = block
            end

            def uri_from_url!(url)
              validate_url!(url)

              @uri = url.nil? ? @default_uri : URI(url)

              fail ArgumentError, "Invalid URL: #{url.inspect}" if uri_valid?(@uri)

              @uri
            end

            private

            def validate_url!(url)
              fail ArgumentError, "Invalid URL: #{url.inspect}" if !(url.is_a?(String) || url.nil?)
              fail ArgumentError, 'No URL or default URL specified' if url.nil? && @default_uri.nil?
            end

            def uri_valid?(uri)
              @uri_validator && !@uri_validator.call(uri)
            end
          end

          def url
            @uri.to_s
          end

          def url=(url)
            @uri = self.class.uri_from_url!(url)
          end

          included do
            %w[scheme user password host port].each do |method|
              define_method(method) do
                (@uri && @uri.send(method)) || (self.class.default_uri && self.class.default_uri.send(method))
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
neo4j-core-8.1.4 lib/neo4j/core/cypher_session/adaptors/has_uri.rb
neo4j-core-8.1.3 lib/neo4j/core/cypher_session/adaptors/has_uri.rb
neo4j-core-8.1.2 lib/neo4j/core/cypher_session/adaptors/has_uri.rb
neo4j-core-8.1.1 lib/neo4j/core/cypher_session/adaptors/has_uri.rb
neo4j-core-8.1.0 lib/neo4j/core/cypher_session/adaptors/has_uri.rb
neo4j-core-8.0.4 lib/neo4j/core/cypher_session/adaptors/has_uri.rb
neo4j-core-8.0.3 lib/neo4j/core/cypher_session/adaptors/has_uri.rb
neo4j-core-8.0.2 lib/neo4j/core/cypher_session/adaptors/has_uri.rb
neo4j-core-8.0.1 lib/neo4j/core/cypher_session/adaptors/has_uri.rb
neo4j-core-7.2.4 lib/neo4j/core/cypher_session/adaptors/has_uri.rb
neo4j-core-8.0.0 lib/neo4j/core/cypher_session/adaptors/has_uri.rb
neo4j-core-7.2.3 lib/neo4j/core/cypher_session/adaptors/has_uri.rb
neo4j-core-7.2.2 lib/neo4j/core/cypher_session/adaptors/has_uri.rb
neo4j-core-7.2.1 lib/neo4j/core/cypher_session/adaptors/has_uri.rb