Class: Bridgetown::Model::Origin

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::DescendantsTracker
Defined in:
lib/bridgetown-core/model/origin.rb

Overview

Abstract Superclass

Direct Known Subclasses

BuilderOrigin, RepoOrigin

Constant Summary collapse

EAGER_LOAD_DESCENDANTS =
%i(BuilderOrigin RepoOrigin PluginOrigin).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, site: Bridgetown::Current.site) ⇒ Origin

Returns a new instance of Origin.



22
23
24
25
# File 'lib/bridgetown-core/model/origin.rb', line 22

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

Instance Attribute Details

#idString

Returns:

  • (String)


12
13
14
# File 'lib/bridgetown-core/model/origin.rb', line 12

def id
  @id
end

#siteBridgetown::Site

Returns:



15
16
17
# File 'lib/bridgetown-core/model/origin.rb', line 15

def site
  @site
end

Class Method Details

.handle_scheme?(_scheme) ⇒ Boolean

You must implement in subclasses

Returns:

  • (Boolean)


18
19
20
# File 'lib/bridgetown-core/model/origin.rb', line 18

def self.handle_scheme?(_scheme)
  false
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/bridgetown-core/model/origin.rb', line 45

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

#readObject



36
37
38
# File 'lib/bridgetown-core/model/origin.rb', line 36

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

#relative_pathPathname

Returns:

  • (Pathname)


41
42
43
# File 'lib/bridgetown-core/model/origin.rb', line 41

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

#verify_model?(klass) ⇒ Boolean

You can override in subclass

Returns:

  • (Boolean)


28
29
30
31
32
33
34
# File 'lib/bridgetown-core/model/origin.rb', line 28

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