Sha256: 12c7e284d1802b445b0bb42dbd9c715dca65d5045a97e87f3d84ae2ca160796a

Contents?: true

Size: 1.29 KB

Versions: 14

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module Bridgetown
  module Model
    # Abstract Superclass
    class Origin
      extend ActiveSupport::DescendantsTracker

      EAGER_LOAD_DESCENDANTS = %i(BuilderOrigin RepoOrigin PluginOrigin).freeze

      # @return [String]
      attr_accessor :id

      # @return [Bridgetown::Site]
      attr_accessor :site

      # You must implement in subclasses
      def self.handle_scheme?(_scheme)
        false
      end

      def initialize(id, site: Bridgetown::Current.site)
        self.id = id
        self.site = site
      end

      # You can override in subclass
      def verify_model?(klass)
        collection_name = URI.parse(id).host.chomp(".collection")

        return klass.collection_name.to_s == collection_name if klass.respond_to?(:collection_name)

        klass.name == ActiveSupport::Inflector.classify(collection_name)
      end

      def read
        raise "Implement #read in a subclass of Bridgetown::Model::Origin"
      end

      # @return [Pathname]
      def relative_path
        raise "Implement #relative_path in a subclass of Bridgetown::Model::Origin"
      end

      def exists?
        raise "Implement #exists? in a subclass of Bridgetown::Model::Origin"
      end
    end

    Origin::EAGER_LOAD_DESCENDANTS.each { const_get _1 }
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
bridgetown-core-1.3.4 lib/bridgetown-core/model/origin.rb
bridgetown-core-1.3.3 lib/bridgetown-core/model/origin.rb
bridgetown-core-1.3.2 lib/bridgetown-core/model/origin.rb
bridgetown-core-1.3.1 lib/bridgetown-core/model/origin.rb
bridgetown-core-1.3.0 lib/bridgetown-core/model/origin.rb
bridgetown-core-1.3.0.beta3 lib/bridgetown-core/model/origin.rb
bridgetown-core-1.3.0.beta2 lib/bridgetown-core/model/origin.rb
bridgetown-core-1.3.0.beta1 lib/bridgetown-core/model/origin.rb
bridgetown-core-1.2.0 lib/bridgetown-core/model/origin.rb
bridgetown-core-1.2.0.beta5 lib/bridgetown-core/model/origin.rb
bridgetown-core-1.2.0.beta4 lib/bridgetown-core/model/origin.rb
bridgetown-core-1.2.0.beta3 lib/bridgetown-core/model/origin.rb
bridgetown-core-1.2.0.beta2 lib/bridgetown-core/model/origin.rb
bridgetown-core-1.2.0.beta1 lib/bridgetown-core/model/origin.rb