Class: RubynCode::Learning::Shortcut
- Inherits:
-
Object
- Object
- RubynCode::Learning::Shortcut
- Defined in:
- lib/rubyn_code/learning/shortcut.rb
Overview
Uses learned instincts to skip redundant discovery steps. For example, if we know the project uses FactoryBot, skip checking test_helper.rb and looking for factories/ — just generate FactoryBot-style specs.
Constant Summary collapse
- SHORTCUT_RULES =
{ 'uses_factory_bot' => { skip: %w[test_helper factories_check], apply: { spec_template: :factory_bot_rspec } }, 'uses_rspec' => { skip: %w[framework_detection], apply: { test_framework: :rspec } }, 'uses_minitest' => { skip: %w[framework_detection], apply: { test_framework: :minitest } }, 'uses_service_objects' => { skip: %w[pattern_detection], apply: { service_pattern: 'app/services/**/*_service.rb' } }, 'uses_devise' => { skip: %w[auth_detection], apply: { auth_framework: :devise } }, 'uses_grape' => { skip: %w[api_detection], apply: { api_framework: :grape } }, 'uses_sidekiq' => { skip: %w[job_detection], apply: { job_framework: :sidekiq } } }.freeze
Instance Attribute Summary collapse
-
#applied_shortcuts ⇒ Object
readonly
Returns the value of attribute applied_shortcuts.
-
#tokens_saved_estimate ⇒ Object
readonly
Returns the value of attribute tokens_saved_estimate.
Instance Method Summary collapse
-
#apply(instinct_patterns) ⇒ Hash
Apply shortcuts based on instinct patterns.
-
#initialize ⇒ Shortcut
constructor
A new instance of Shortcut.
-
#skip?(step_name) ⇒ Boolean
Check if a discovery step should be skipped.
-
#stats ⇒ Object
Returns stats about shortcuts applied this session.
Constructor Details
#initialize ⇒ Shortcut
Returns a new instance of Shortcut.
42 43 44 45 |
# File 'lib/rubyn_code/learning/shortcut.rb', line 42 def initialize @applied_shortcuts = [] @tokens_saved_estimate = 0 end |
Instance Attribute Details
#applied_shortcuts ⇒ Object (readonly)
Returns the value of attribute applied_shortcuts.
40 41 42 |
# File 'lib/rubyn_code/learning/shortcut.rb', line 40 def applied_shortcuts @applied_shortcuts end |
#tokens_saved_estimate ⇒ Object (readonly)
Returns the value of attribute tokens_saved_estimate.
40 41 42 |
# File 'lib/rubyn_code/learning/shortcut.rb', line 40 def tokens_saved_estimate @tokens_saved_estimate end |
Instance Method Details
#apply(instinct_patterns) ⇒ Hash
Apply shortcuts based on instinct patterns.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rubyn_code/learning/shortcut.rb', line 51 def apply(instinct_patterns) settings = {} instinct_patterns.each do |pattern| rule_key = match_rule(pattern) next unless rule_key rule = SHORTCUT_RULES[rule_key] settings.merge!(rule[:apply]) @applied_shortcuts << { rule: rule_key, skipped: rule[:skip] } @tokens_saved_estimate += rule[:skip].size * 500 end settings end |
#skip?(step_name) ⇒ Boolean
Check if a discovery step should be skipped.
71 72 73 |
# File 'lib/rubyn_code/learning/shortcut.rb', line 71 def skip?(step_name) @applied_shortcuts.any? { |s| s[:skipped].include?(step_name.to_s) } end |
#stats ⇒ Object
Returns stats about shortcuts applied this session.
76 77 78 79 80 81 82 |
# File 'lib/rubyn_code/learning/shortcut.rb', line 76 def stats { shortcuts_applied: @applied_shortcuts.size, steps_skipped: @applied_shortcuts.sum { |s| s[:skipped].size }, tokens_saved_estimate: @tokens_saved_estimate } end |