Class: Trifle::Docs::Harvester::Walker
- Inherits:
-
Object
- Object
- Trifle::Docs::Harvester::Walker
- Defined in:
- lib/trifle/docs/harvester.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#router ⇒ Object
readonly
Returns the value of attribute router.
Instance Method Summary collapse
- #collection_for(url:) ⇒ Object
- #content_for(url:) ⇒ Object
-
#gather ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#initialize(**keywords) ⇒ Walker
constructor
A new instance of Walker.
- #meta_for(url:) ⇒ Object
- #not_found(url:) ⇒ Object
- #route_for(url:) ⇒ Object
- #sitemap ⇒ Object
Constructor Details
#initialize(**keywords) ⇒ Walker
Returns a new instance of Walker.
9 10 11 12 13 14 15 16 17 |
# File 'lib/trifle/docs/harvester.rb', line 9 def initialize(**keywords) @path = keywords.fetch(:path) @harvesters = keywords.fetch(:harvesters) @namespace = keywords.fetch(:namespace) @cache = keywords.fetch(:cache) @router = {} gather end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
7 8 9 |
# File 'lib/trifle/docs/harvester.rb', line 7 def cache @cache end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
7 8 9 |
# File 'lib/trifle/docs/harvester.rb', line 7 def namespace @namespace end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/trifle/docs/harvester.rb', line 7 def path @path end |
#router ⇒ Object (readonly)
Returns the value of attribute router.
7 8 9 |
# File 'lib/trifle/docs/harvester.rb', line 7 def router @router end |
Instance Method Details
#collection_for(url:) ⇒ Object
44 45 46 47 48 |
# File 'lib/trifle/docs/harvester.rb', line 44 def collection_for(url:) return sitemap if url.empty? sitemap.dig(*url.split('/')) end |
#content_for(url:) ⇒ Object
50 51 52 |
# File 'lib/trifle/docs/harvester.rb', line 50 def content_for(url:) route_for(url: url)&.content end |
#gather ⇒ Object
rubocop:disable Metrics/MethodLength
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/trifle/docs/harvester.rb', line 19 def gather # rubocop:disable Metrics/MethodLength Dir["#{path}/**/*.*"].each do |file| @harvesters.each do |harvester| sieve = harvester::Sieve.new(path: path, file: file) next unless sieve.match? @router[sieve.to_url] = harvester::Conveyor.new( file: file, url: sieve.to_url, namespace: namespace, cache: cache ) break end end true end |
#meta_for(url:) ⇒ Object
54 55 56 |
# File 'lib/trifle/docs/harvester.rb', line 54 def (url:) route_for(url: url)&. end |
#not_found(url:) ⇒ Object
62 63 64 |
# File 'lib/trifle/docs/harvester.rb', line 62 def not_found(url:) puts "No route found for url: #{url}" end |
#route_for(url:) ⇒ Object
58 59 60 |
# File 'lib/trifle/docs/harvester.rb', line 58 def route_for(url:) @router[url] || not_found(url: url) end |