Sha256: 6cb27856bfc123f8144a3cf2dc4f43c8fc59eca2cdce5ef4ed8ccb219f63e360

Contents?: true

Size: 865 Bytes

Versions: 1

Compression:

Stored size: 865 Bytes

Contents

#
# Block Model
#
# Stores the raw information in the database
#
module Annex

  case Annex::config[:adapter]

  when :activerecord
    class Block < ActiveRecord::Base
      validates_presence_of :route

      def self.builder(params)
        block = Block.where(route: "#{params[:route]}_#{params[:identifier]}").first_or_create
        block.content = params[:content][params[:identifier].to_sym]

        return block
      end
    end

  when :mongoid
    class Block
      field :route, type: String
      field :content, type: Hash

      validates_presence_of :route

      def self.builder(params)
        block = Block.where(route: params[:route]).first_or_create

        block.content ||= {}

        params[:content].keys.each do |key|
          block.content[key] = params[:content][key]
        end

        return block
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
annex-cms-0.3.1 app/models/annex/block.rb