Sha256: 99783c3635d5f0fbbee1393cfc10e043dcef20f56cdd8df974aaf4067f019060

Contents?: true

Size: 924 Bytes

Versions: 3

Compression:

Stored size: 924 Bytes

Contents

require 'active_support/concern'
require_dependency Smithy::Engine.root.join('app', 'models', 'smithy', 'content_block').to_s

module Smithy
  module ContentBlocks
    class Registry
      @@content_blocks = []

      class << self
        def clear
          @@content_blocks = []
        end

        def content_blocks
          @@content_blocks
        end

        def register(content_block)
          return unless ActiveRecord::Base.connection.table_exists?(Smithy::ContentBlock.table_name)
          return unless ActiveRecord::Base.connection.table_exists?(content_block.table_name)
          content_block_name = content_block.to_s.demodulize
          @@content_blocks << content_block_name unless @@content_blocks.include?(content_block_name)
          cb = Smithy::ContentBlock.find_or_initialize_by_name(content_block_name)
          cb.save
          @@content_blocks
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
smithycms-0.0.3 lib/smithy/content_blocks/registry.rb
smithycms-0.0.2 lib/smithy/content_blocks/registry.rb
smithycms-0.0.1 lib/smithy/content_blocks/registry.rb