Sha256: 57b324ae611ca02d438b42da47280c12b5c2eecdd68f2f4abdf22df060858fd9

Contents?: true

Size: 966 Bytes

Versions: 1

Compression:

Stored size: 966 Bytes

Contents

module Cas
  class Setup
    def install
      ActiveRecord::Base.transaction do
        config = YAML.load_file(filename)

        config["sites"].each do |site_slug, site_config|
          site = ::Cas::Site.where(slug: site_slug).first_or_create
          site.update!(
            domains: site_config["domains"],
            name: site_config["name"]
          )

          site_config["sections"].each do |key, section|
            model = ::Cas::Section.where(
              slug: key,
              site_id: site.id
            ).first_or_create!(
              name: section["name"],
              section_type: section["type"],
            )

            model.update!(
              name: section["name"],
              section_type: section["type"],
            )
          end
        end
      end
    end

    private

    def filename
      if Rails.env.test?
        "spec/fixtures/cas.yml"
      else
        "cas.yml"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cas-cms-0.1.0 lib/cas/setup.rb