Class: Middleman::Sitemap::ProxyResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/middleman-core/sitemap/extensions/proxies.rb

Constant Summary

Constants inherited from Resource

Resource::METADATA_HASH

Constants included from Contracts

Contracts::PATH_MATCHER

Instance Attribute Summary collapse

Attributes inherited from Resource

#destination_path, #ignored, #path

Instance Method Summary collapse

Methods inherited from Resource

#Any, #Bool, #Hash, #METADATA_HASH, #String, #add_metadata, #binary?, #data, #ext, #ignore!, #ignored?, #indifferent_access?, #locals, #normalized_path, #options, #page_id, #proxy_to, #render, #source_file, #template?, #url

Methods included from Extensions::Traversal

#children, #directory_index?, #eponymous_directory?, #eponymous_directory_path, #parent, #siblings, #traversal_root

Methods included from Contracts

#Contract

Constructor Details

#initialize(store, path, target) ⇒ ProxyResource

Initialize resource with parent store and URL

Parameters:



73
74
75
76
77
78
79
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 73

def initialize(store, path, target)
  super(store, path)

  target = ::Middleman::Util.normalize_path(target)
  raise "You can't proxy #{path} to itself!" if target == path
  @target = target
end

Instance Attribute Details

#targetObject (readonly)

Returns the value of attribute target.



67
68
69
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 67

def target
  @target
end

Instance Method Details

#content_typeObject



109
110
111
112
113
114
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 109

def content_type
  mime_type = super
  return mime_type if mime_type

  target_resource.content_type
end

#file_descriptorObject



100
101
102
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 100

def file_descriptor
  target_resource.file_descriptor
end

#metadataObject



104
105
106
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 104

def 
  target_resource..deep_merge super
end

#target_resourceObject



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 85

def target_resource
  resource = @store.find_resource_by_path(@target)

  unless resource
    raise "Path #{path} proxies to unknown file #{@target}:#{@store.resources.map(&:path)}"
  end

  if resource.is_a? ProxyResource
    raise "You can't proxy #{path} to #{@target} which is itself a proxy."
  end

  resource
end

#to_sObject Also known as: inspect



116
117
118
# File 'lib/middleman-core/sitemap/extensions/proxies.rb', line 116

def to_s
  "#<#{self.class} path=#{@path} target=#{@target}>"
end