Class: Vapey::Reindexer
- Inherits:
-
Object
- Object
- Vapey::Reindexer
- Defined in:
- lib/vapey/reindexer.rb
Instance Attribute Summary collapse
-
#redis ⇒ Object
Returns the value of attribute redis.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Reindexer
constructor
A new instance of Reindexer.
- #run(directory = nil, drop: false) ⇒ Object
Constructor Details
#initialize ⇒ Reindexer
Returns a new instance of Reindexer.
47 48 49 |
# File 'lib/vapey/reindexer.rb', line 47 def initialize @redis ||= Redis.new(host: ENV.fetch("REDIS_HOST") { "127.0.0.1" }, port: ENV.fetch("REDIS_PORT") { "6379" }.to_i) end |
Instance Attribute Details
#redis ⇒ Object
Returns the value of attribute redis.
15 16 17 |
# File 'lib/vapey/reindexer.rb', line 15 def redis @redis end |
Class Method Details
.invoke ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vapey/reindexer.rb', line 18 def invoke = { drop: false } OptionParser.new do |opts| opts. = "Usage: reindexer.rb [options]" opts.on('-s', '--source SOURCE_DIR', 'Source directory') do |source_dir| [:source_dir] = source_dir end opts.on('-d', '--drop', 'Drop and create index before reindexing') do [:drop] = true end end.parse! # Validate the presence of source and destination directories unless [:source_dir] puts "Error: source directory (-s or --source) must be specified." exit 1 end # Instantiate the ToMkDocs class and perform the conversion reindexer = Vapey::Reindexer.new reindexer.run([:source_dir], drop: [:drop]) puts "Reindexer completed successfully." end |
Instance Method Details
#run(directory = nil, drop: false) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/vapey/reindexer.rb', line 51 def run(directory = nil, drop: false) vapey = Vapey::Search.new if drop vapey.recreate_index end directory ||= ENV.fetch("DOCS_DIRECTORY") { "/Users/david/development/docs/examples" } sections = Vapey::MarkdownParser.process(directory) sections.each do |section| puts "indexing: #{section[:file]} section: #{section[:section_title]}" data = section.stringify_keys id = data['id'] vapey.redis.json_set("item:#{id}", Rejson::Path.root_path, data) end end |