Class: Bridgetown::Model::BuilderOrigin
- Inherits:
-
Origin
- Object
- Origin
- Bridgetown::Model::BuilderOrigin
show all
- Defined in:
- lib/bridgetown-core/model/builder_origin.rb
Constant Summary
Constants inherited
from Origin
Origin::EAGER_LOAD_DESCENDANTS
Instance Attribute Summary collapse
Attributes inherited from Origin
#id, #site
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Origin
#verify_model?
Constructor Details
#initialize(id, site: Bridgetown::Current.site) ⇒ BuilderOrigin
Returns a new instance of BuilderOrigin.
19
20
21
22
|
# File 'lib/bridgetown-core/model/builder_origin.rb', line 19
def initialize(id, site: Bridgetown::Current.site)
super
@relative_path = Pathname.new(url.path.delete_prefix("/"))
end
|
Instance Attribute Details
#relative_path ⇒ Pathname
7
8
9
|
# File 'lib/bridgetown-core/model/builder_origin.rb', line 7
def relative_path
@relative_path
end
|
Class Method Details
.handle_scheme?(scheme) ⇒ Boolean
10
11
12
|
# File 'lib/bridgetown-core/model/builder_origin.rb', line 10
def handle_scheme?(scheme)
scheme == "builder"
end
|
.id_for_builder_path(builder, path) ⇒ Object
14
15
16
|
# File 'lib/bridgetown-core/model/builder_origin.rb', line 14
def id_for_builder_path(builder, path)
"builder://#{builder.class.name.gsub("::", ".")}/#{path}"
end
|
Instance Method Details
#exists? ⇒ Boolean
37
38
39
|
# File 'lib/bridgetown-core/model/builder_origin.rb', line 37
def exists?
false
end
|
#read ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/bridgetown-core/model/builder_origin.rb', line 28
def read
@data = block_given? ? yield : read_data_from_builder
@data[:_id_] = id
@data[:_origin_] = self
@relative_path = Pathname.new(@data[:_relative_path_]) if @data[:_relative_path_]
@data
end
|
#read_data_from_builder ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/bridgetown-core/model/builder_origin.rb', line 41
def read_data_from_builder
builder = Kernel.const_get(url.host.gsub(".", "::"))
raise NameError unless builder.instance_methods.include?(:resource_data_for_id)
builder.new.resource_data_for_id(id) || raise(NameError)
rescue NameError
raise(
Bridgetown::Errors::FatalException,
"Builder not found which can read #{id}"
)
end
|
#url ⇒ Object
24
25
26
|
# File 'lib/bridgetown-core/model/builder_origin.rb', line 24
def url
@url ||= URI.parse(id)
end
|