-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
74 lines (57 loc) · 2.41 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# frozen_string_literal: true
# Load Bundler's gem tasks (e.g., `rake build`, `rake install`, etc.)
require 'bundler/gem_tasks'
# Load RSpec's rake task to run the test suite using `rake spec`
require 'rspec/core/rake_task'
# Define the `spec` task to run RSpec tests
RSpec::Core::RakeTask.new(:spec)
# Load RuboCop's rake task to check for style guide violations using `rake rubocop`
require 'rubocop/rake_task'
# Define the `rubocop` task to run RuboCop linter
RuboCop::RakeTask.new
# Load Yard's rake task for generating documentation using `rake yard`
require 'yard'
# Define the `yard` task to generate documentation in the `docs` directory
YARD::Rake::YardocTask.new do |t|
t.options = ['--output-dir', 'docs']
end
# By default, run both the `spec` (tests) and `rubocop` (linter) tasks
task default: %i[spec rubocop]
require_relative 'lib/nse_data'
namespace :docs do
desc 'Update README with dynamically defined methods'
task :update_readme do
# Ensure the API methods are defined
NseData.define_api_methods
# List all methods defined on NseData
methods = NseData.methods(false).grep(/^fetch_/)
# Read the existing README
readme_path = 'README.md'
readme_content = File.read(readme_path)
# Define markers for where to insert the methods section
start_marker = '## Available Methods'
end_marker = '## Usage'
start_index = readme_content.index(start_marker) + start_marker.length
end_index = readme_content.index(end_marker)
if start_index && end_index
methods_section = readme_content[start_index...end_index]
new_methods_section = "#{start_marker}\n\n"
methods.each do |method|
new_methods_section += "- #{method}\n"
end
# Write back the updated README
updated_content = readme_content.sub(methods_section, new_methods_section)
File.write(readme_path, updated_content)
puts 'README updated with the following methods:'
methods.each { |method| puts "- #{method}" }
else
puts 'Could not find markers to update in README.md'
end
end
end
# Usage:
# 1. `rake spec` - Runs the RSpec tests
# 2. `rake rubocop` - Runs RuboCop linter for code quality checks
# 3. `rake yard` - Generates Yard documentation (output in the `docs/` folder)
# 4. `rake` - Runs both the tests and RuboCop checks (default task)
# 5. `rake docs:update_readme` - Update readme with available methods generated dynamically in nse_data.rb