Sha256: a0db7acac385a9c03de2e91cfff38e43d53d91e68f0ceb3e8b1c3e0ea3300515

Contents?: true

Size: 1.86 KB

Versions: 30

Compression:

Stored size: 1.86 KB

Contents

module Fog
  module Service

    def self.extended(other)
      super
      other.module_eval <<-EOS, __FILE__, __LINE__
        class Error < Fog::Errors::Error; end
        class NotFound < Fog::Errors::NotFound; end

        module Collections; end

        def self.new(options={})
          missing = []
          for requirement in requirements
            missing << requirement unless options[requirement]
          end
          unless missing.empty?
            if missing.length == 1
              raise(ArgumentError, [missing.first, "is required for this service"].join(' '))
            else
              raise(ArgumentError, [missing[0...-1].join(", "), 'and', missing[-1], 'are required for this service'].join(' '))
            end
          end

          unless @required
            for model in models
              require [@model_path, model].join('/')
            end
            for request in requests
              require [@request_path, request].join('/')
            end
            @required = true
          end

          instance = if Fog.mocking?
            Mock.new(options)
          else
            Real.new(options)
          end

          if self.respond_to?(:after_new)
            instance = self.after_new(instance, options)
          end
          instance
        end
      EOS
    end

    def model_path(new_path)
      @model_path = new_path
    end

    def model(new_model)
      models << new_model
    end

    def models
      @models ||= []
    end

    def request_path(new_path)
      @request_path = new_path
    end

    def request(new_request)
      requests << new_request
    end

    def requests
      @requests ||= []
    end

    def requires(*args)
      requirements.concat(args)
    end

    def requirements
      @requirements ||= []
    end

    def reset_data(keys=Mock.data.keys)
      Mock.reset_data(keys)
    end

  end
end

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
fog-0.2.30 lib/fog/service.rb
fog-0.2.28 lib/fog/service.rb
fog-0.2.27 lib/fog/service.rb
fog-0.2.26 lib/fog/service.rb
fog-0.2.25 lib/fog/service.rb
fog-0.2.24 lib/fog/service.rb
tecnh-fog-0.2.23.vpc lib/fog/service.rb
fog-0.2.23 lib/fog/service.rb
fog-0.2.22 lib/fog/service.rb
fog-0.2.21 lib/fog/service.rb
fog-0.2.20 lib/fog/service.rb
fog-0.2.19 lib/fog/service.rb
fog-0.2.18 lib/fog/service.rb
fog-0.2.17 lib/fog/service.rb
fog-0.2.16 lib/fog/service.rb
fog-0.2.15 lib/fog/service.rb
fog-0.2.14 lib/fog/service.rb
fog-0.2.13 lib/fog/service.rb
fog-0.2.12 lib/fog/service.rb
fog-0.2.11 lib/fog/service.rb