Sha256: 7524f744be4af9ee6539a62c374435085c876ffc17752c05d16d955ceb3da290

Contents?: true

Size: 1.53 KB

Versions: 22

Compression:

Stored size: 1.53 KB

Contents

module Garage
  module Meta
    class RemoteService
      class << self
        def configure(&block)
          @config = Config.new
          @config.instance_eval(&block)
        end

        def configuration
          @config or raise "Garage::Meta::RemoteService.configure must be called in initializer"
        end

        def all
          configuration.services
        end

        def build_permissions(perms, other, target)
          perms.permits! :read
        end
      end

      include Garage::Representer
      include Garage::Authorizable

      property :namespace
      property :name
      property :endpoint
      property :alternate_endpoints

      attr_accessor :namespace, :name, :endpoint

      def alternate_endpoints
        @alternate_endpoints ||= {}
      end

      class Config
        attr_reader :services

        def initialize
          @services = []
        end

        def service(&block)
          service = ServiceDSL.new
          service.instance_eval(&block)
          @services << service.build
        end
      end

      class ServiceDSL
        def initialize
          @service = RemoteService.new
        end

        def namespace(arg)
          @service.namespace = arg.to_s
        end

        def name(arg)
          @service.name = arg
        end

        def endpoint(arg)
          @service.endpoint = arg
        end

        def alternate_endpoint(rel, url)
          @service.alternate_endpoints[rel] = url
        end

        def build
          @service
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
the_garage-2.8.2 lib/garage/meta/remote_service.rb
the_garage-2.8.1 lib/garage/meta/remote_service.rb
the_garage-2.8.0 lib/garage/meta/remote_service.rb
the_garage-2.7.0 lib/garage/meta/remote_service.rb
the_garage-2.6.1 lib/garage/meta/remote_service.rb
the_garage-2.6.0 lib/garage/meta/remote_service.rb
the_garage-2.5.0 lib/garage/meta/remote_service.rb
the_garage-2.4.4 lib/garage/meta/remote_service.rb
the_garage-2.4.3 lib/garage/meta/remote_service.rb
the_garage-2.4.2 lib/garage/meta/remote_service.rb
the_garage-2.4.1 lib/garage/meta/remote_service.rb
the_garage-2.4.0 lib/garage/meta/remote_service.rb
the_garage-2.3.3 lib/garage/meta/remote_service.rb
the_garage-2.3.2 lib/garage/meta/remote_service.rb
the_garage-2.3.1 lib/garage/meta/remote_service.rb
the_garage-2.3.0 lib/garage/meta/remote_service.rb
the_garage-2.2.0 lib/garage/meta/remote_service.rb
the_garage-2.1.0 lib/garage/meta/remote_service.rb
the_garage-2.0.3 lib/garage/meta/remote_service.rb
the_garage-2.0.2 lib/garage/meta/remote_service.rb