Sha256: ad2fdb4f9754f311ac17dbc11a1c187964f3b366efc8c40dc7a8bc053461dcf6

Contents?: true

Size: 1.19 KB

Versions: 5

Compression:

Stored size: 1.19 KB

Contents

class DefaultAdapter
  class << self
    def all(klass)
      klass.get_model_class.all
    end

    def delete(klass, id)
      object = klass.get_model_class.find_by_id(id)
      object.delete if object
    end

    def delete_all(klass)
      klass.get_model_class.delete_all
    end

    def exists?(klass, id)
      klass.get_model_class.exists?(id)
    end

    def find(klass, id)
      klass.get_model_class.find(id)
    end

    def first(klass)
      klass.get_model_class.first
    end

    def last(klass)
      klass.get_model_class.last
    end

    def create(klass, attributes)
      object = klass.get_model_class.create(attributes)
    end

    def update_attribute(klass, id, key, value)
      object = id.nil? ? klass.get_model_class.new(key.to_sym => value) : klass.get_model_class.find(id)

      ret = object.update_attribute(key, value)

      [ret, object]
    end

    def update_attributes(klass, id, attributes)
      object = id.nil? ? klass.get_model_class.new : klass.get_model_class.find(id)

      ret = object.update_attributes(attributes)

      [ret, object]
    end

    def where(klass, args)
      # raise args.inspect
      klass.get_model_class.where(args)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
active_repository-0.2.7 lib/active_repository/adapters/default_adapter.rb
active_repository-0.2.6 lib/active_repository/adapters/default_adapter.rb
active_repository-0.2.5 lib/active_repository/adapters/default_adapter.rb
active_repository-0.2.4 lib/active_repository/adapters/default_adapter.rb
active_repository-0.2.3 lib/active_repository/adapters/default_adapter.rb