Sha256: d8fb3c6bc7b391143a58add02e9533b7f59468a6d94d6a43309485cc4b837f98

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

require "kvom"
require "kvom/adapter/couchdb_adapter"
require "kvom/adapter/dynamodb_adapter"

module RailsConnector

  # This is the abstract class from which all CMS models derive.
  #
  class CmsBaseModel < Kvom::Base #:nodoc:
    class << self
      def instance_name=(ignore) # :nodoc:
        # this method is here only for compatibility with the fiona connector.
      end

      def adapter
        @@cms_database_adapter
      end

      def configure_database(connection_spec)
        @@cms_database_adapter =
            case connection_spec["type"]
            when "couch"
              Kvom::Adapter::CouchdbAdapter.new(connection_spec)
            when "dynamo"
              Kvom::Adapter::DynamodbAdapter.new(connection_spec)
            else
              raise "Unexpected database type #{connection_spec["type"]}"
            end
      end

      def query_index(model, index, params = {})
        hash_value = "#{model}/#{index}/#{params[:hash_value]}"
        range_value = params[:range_value] || ""
        range_value_extender = params[:range_value_extender]

        # up to this point: backend independent

        # this may be backend dependent (suffix character)
        if range_value_extender
          start_key, end_key =
              case range_value
              when Range
                [range_value.begin, range_value.end]
              else
                [range_value, range_value]
              end
          range_value = Range.new(start_key + range_value_extender, end_key + range_value_extender + "~")
        end

        adapter.query(hash_value, range_value)
      end

    end

    def save
      raise "CmsBaseModel is read-only"
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
infopark_cloud_connector-6.8.0.beta.200.621.4c8e1b0 lib/rails_connector/cms_base_model.rb