Sha256: 3bbaf7c1987b4c07c14eddee130146f9ecae5811756461f3f7da41d540a088e2

Contents?: true

Size: 1.19 KB

Versions: 29

Compression:

Stored size: 1.19 KB

Contents

require_relative 'resource_requester'

module Contentful
  module Management
    # Wrapper for Environment Association Methods
    # @private
    module EnvironmentAssociationMethodsFactory
      attr_reader :environment

      def initialize(environment)
        @environment = environment
      end

      def all(params = {})
        associated_class.all(environment.client, environment.sys[:space].id, environment.id, params)
      end

      def find(id)
        associated_class.find(environment.client, environment.sys[:space].id, environment.id, id)
      end

      def create(attributes = {})
        associated_class.create(environment.client, environment.sys[:space].id, environment.id, attributes)
      end

      def new
        object = associated_class.new
        object.sys[:space] = environment.space
        object.sys[:environment] = environment
        object.client = environment.client
        object
      end

      def associated_class
        class_name = /\A(.+)Environment(.+)MethodsFactory\z/.match(self.class.name).captures.join
        class_name.split('::').reduce(Object) do |mod, actual_class_name|
          mod.const_get(actual_class_name)
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
contentful-management-3.8.0 lib/contentful/management/environment_association_methods_factory.rb
contentful-management-3.7.0 lib/contentful/management/environment_association_methods_factory.rb
contentful-management-3.6.0 lib/contentful/management/environment_association_methods_factory.rb
contentful-management-3.5.0 lib/contentful/management/environment_association_methods_factory.rb
contentful-management-3.4.0 lib/contentful/management/environment_association_methods_factory.rb
contentful-management-3.3.0 lib/contentful/management/environment_association_methods_factory.rb
contentful-management-3.2.0 lib/contentful/management/environment_association_methods_factory.rb
contentful-management-3.1.0 lib/contentful/management/environment_association_methods_factory.rb
contentful-management-3.0.0 lib/contentful/management/environment_association_methods_factory.rb
contentful-management-2.13.1 lib/contentful/management/environment_association_methods_factory.rb
contentful-management-2.13.0 lib/contentful/management/environment_association_methods_factory.rb
contentful-management-2.12.1 lib/contentful/management/environment_association_methods_factory.rb
contentful-management-2.12.0 lib/contentful/management/environment_association_methods_factory.rb
contentful-management-2.11.0 lib/contentful/management/environment_association_methods_factory.rb
contentful-management-2.10.0 lib/contentful/management/environment_association_methods_factory.rb
contentful-management-2.9.1 lib/contentful/management/environment_association_methods_factory.rb
contentful-management-2.9.0 lib/contentful/management/environment_association_methods_factory.rb
contentful-management-2.8.2 lib/contentful/management/environment_association_methods_factory.rb
contentful-management-2.8.1 lib/contentful/management/environment_association_methods_factory.rb
contentful-management-2.8.0 lib/contentful/management/environment_association_methods_factory.rb