Sha256: f8773259d6ea2148d50284f93d6481d99292c5dce78981bf978d802d26496d76

Contents?: true

Size: 1.24 KB

Versions: 30

Compression:

Stored size: 1.24 KB

Contents

require 'orm_adapter'

# TODO: extract in gem orm_apdater-her
module Her
  module Errors
    class ResourceNotFound < StandardError
    end
  end
  
  module Model
    module ClassMethods
      include OrmAdapter::ToAdapter
    end
    
    class OrmAdapter < ::OrmAdapter::Base
      # get a list of column names for a given class
      def column_names
        @columns ||= klass.instance_methods.grep(/_will_change!$/).map { |e| e.to_s.gsub('_will_change!','') }
      end

      # @see OrmAdapter::Base#get!
      def get!(id)
        res = klass.find(wrap_key(id))
        raise Her::Errors::ResourceNotFound, "resource not found" unless res
        res
      end

      # @see OrmAdapter::Base#get
      def get(id)
        klass.find(wrap_key(id))
      end

      # @see OrmAdapter::Base#find_first
      def find_first(options = {})
        klass.where(options).limit(1).first
      end

      # @see OrmAdapter::Base#find_all
      def find_all(options = {})
        klass.where(options)
      end

      # @see OrmAdapter::Base#create!
      def create!(attributes = {})
        klass.create!(attributes)
      end

      # @see OrmAdapter::Base#destroy
      def destroy(object)
        object.destroy if valid_object?(object)
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
mno-enterprise-core-3.4.0 lib/her_extension/her_orm_adapter.rb
mno-enterprise-core-3.3.3 lib/her_extension/her_orm_adapter.rb
mno-enterprise-core-3.3.2 lib/her_extension/her_orm_adapter.rb
mno-enterprise-core-3.2.1 lib/her_extension/her_orm_adapter.rb
mno-enterprise-core-3.3.1 lib/her_extension/her_orm_adapter.rb
mno-enterprise-core-3.3.0 lib/her_extension/her_orm_adapter.rb
mno-enterprise-core-3.2.0 lib/her_extension/her_orm_adapter.rb
mno-enterprise-core-3.1.4 lib/her_extension/her_orm_adapter.rb
mno-enterprise-core-3.0.7 lib/her_extension/her_orm_adapter.rb
mno-enterprise-core-2.0.9 lib/her_extension/her_orm_adapter.rb
mno-enterprise-core-3.1.3 lib/her_extension/her_orm_adapter.rb
mno-enterprise-core-3.0.6 lib/her_extension/her_orm_adapter.rb
mno-enterprise-core-2.0.8 lib/her_extension/her_orm_adapter.rb
mno-enterprise-core-3.1.2 lib/her_extension/her_orm_adapter.rb
mno-enterprise-core-3.0.5 lib/her_extension/her_orm_adapter.rb
mno-enterprise-core-2.0.7 lib/her_extension/her_orm_adapter.rb
mno-enterprise-core-2.0.6 lib/her_extension/her_orm_adapter.rb
mno-enterprise-core-2.0.5 lib/her_extension/her_orm_adapter.rb
mno-enterprise-core-3.1.1 lib/her_extension/her_orm_adapter.rb
mno-enterprise-core-3.0.4 lib/her_extension/her_orm_adapter.rb