Sha256: 39a9d6fb4e30a35d6e3e64e2f42cd9d9184a63a235bf9eca82639cf499611417

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

require "kvom"

module RailsConnector

  # This is the abstract class from which all CMS models derive.
  #
  class CmsBaseModel < Kvom::Model::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 "dynamo"
              Kvom::Adapter::DynamodbAdapter.new(connection_spec)
            when "file"
              Kvom::Adapter::FilesystemAdapter.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] || ""

        # up to this point: backend independent

        # this may be backend dependent (suffix character)
        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, end_key + "~")

        adapter.query(hash_value, range_value)
      end

    end

    def save
      raise "CmsBaseModel is read-only"
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
infopark_cloud_connector-6.8.0.210.ed204b0 lib/rails_connector/cms_base_model.rb
infopark_cloud_connector-6.8.0.110.6570b45 lib/rails_connector/cms_base_model.rb
infopark_cloud_connector-6.8.0.72.d18d096 lib/rails_connector/cms_base_model.rb