Class: Bridgetown::Model::Origin

Inherits:
Object
  • Object
show all
Defined in:
bridgetown-core/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.



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

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

Instance Attribute Details

#idString

Returns:

  • (String)


10
11
12
# File 'bridgetown-core/lib/bridgetown-core/model/origin.rb', line 10

def id
  @id
end

#siteBridgetown::Site

Returns:



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

def site
  @site
end

Class Method Details

.handle_scheme?(_scheme) ⇒ Boolean

You must implement in subclasses

Returns:

  • (Boolean)


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

def self.handle_scheme?(_scheme)
  false
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'bridgetown-core/lib/bridgetown-core/model/origin.rb', line 43

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

#readObject



34
35
36
# File 'bridgetown-core/lib/bridgetown-core/model/origin.rb', line 34

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

#relative_pathPathname

Returns:

  • (Pathname)


39
40
41
# File 'bridgetown-core/lib/bridgetown-core/model/origin.rb', line 39

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)


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

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 == site.config.inflector.classify(collection_name)
end