Sha256: 2f216e5e19fc2a622b3ab4550edcd92febc1fea55371b2823b2788e1a343fd2e

Contents?: true

Size: 1.56 KB

Versions: 23

Compression:

Stored size: 1.56 KB

Contents

module Stringex
  module ActsAsUrl
    module Adapter
      class DataMapper < Base
        def self.load
          ensure_loadable
          orm_class.send :include, Stringex::ActsAsUrl::ActsAsUrlInstanceMethods
          ::DataMapper::Model.send :include, Stringex::ActsAsUrl::ActsAsUrlClassMethods
        end

      private

        def create_callback
          klass.class_eval do
            before acts_as_url_configuration.settings.sync_url ? :save : :create, :ensure_unique_url
          end
        end

        def instance_from_db
          instance.class.get(instance.id)
        end

        def is_blank?(object)
          object.nil? || object == '' || object == []
        end

        def is_new?(object)
          object.new?
        end

        def is_present?(object)
          !is_blank? object
        end

        def klass_previous_instances(&block)
          klass.all(:conditions => {settings.url_attribute => [nil]}).each(&block)
        end

        def primary_key
          instance.class.key.first.instance_variable_get '@name'
        end

        def read_attribute(instance, attribute)
          instance.attributes[attribute]
        end

        def url_owners
          @url_owners ||= url_owners_class.all(:conditions => url_owner_conditions)
        end

        def read_attribute(instance, name)
          instance.attribute_get name
        end

        def write_attribute(instance, name, value)
          instance.attribute_set name, value
        end

        def self.orm_class
          ::DataMapper::Resource
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
stringex-2.6.1 lib/stringex/acts_as_url/adapter/data_mapper.rb
stringex-2.6.0 lib/stringex/acts_as_url/adapter/data_mapper.rb
stringex-2.5.2 lib/stringex/acts_as_url/adapter/data_mapper.rb
stringex-2.5.1 lib/stringex/acts_as_url/adapter/data_mapper.rb
stringex-2.5.0 lib/stringex/acts_as_url/adapter/data_mapper.rb
stringex-2.4.2 lib/stringex/acts_as_url/adapter/data_mapper.rb
stringex-2.4.1 lib/stringex/acts_as_url/adapter/data_mapper.rb
stringex-2.3.0 lib/stringex/acts_as_url/adapter/data_mapper.rb
stringex-2.2.2 lib/stringex/acts_as_url/adapter/data_mapper.rb
stringex-2.2.1 lib/stringex/acts_as_url/adapter/data_mapper.rb
stringex-2.2.0 lib/stringex/acts_as_url/adapter/data_mapper.rb
stringex-2.1.2 lib/stringex/acts_as_url/adapter/data_mapper.rb
stringex-2.1.1 lib/stringex/acts_as_url/adapter/data_mapper.rb
stringex-2.1.0 lib/stringex/acts_as_url/adapter/data_mapper.rb
stringex-2.0.11 lib/stringex/acts_as_url/adapter/data_mapper.rb
stringex-2.0.10 lib/stringex/acts_as_url/adapter/data_mapper.rb
stringex-2.0.9 lib/stringex/acts_as_url/adapter/data_mapper.rb
stringex-2.0.8 lib/stringex/acts_as_url/adapter/data_mapper.rb
stringex-2.0.7 lib/stringex/acts_as_url/adapter/data_mapper.rb
stringex-2.0.6 lib/stringex/acts_as_url/adapter/data_mapper.rb