Module: ScaffoldProjectDetector
- Defined in:
- lib/scaffolding/project_detector.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- AUTOMATION_GEMS =
{ 'watir' => 'watir', 'selenium-webdriver' => 'selenium', 'appium_lib' => 'appium', 'eyes_selenium' => 'selenium', 'axe-core-rspec' => 'selenium', 'axe-core-cucumber' => 'selenium' }.freeze
- FRAMEWORK_GEMS =
{ 'rspec' => 'rspec', 'cucumber' => 'cucumber' }.freeze
- CONFIG_PATH =
'config/config.yml'
Class Method Summary collapse
-
.config ⇒ Object
Loads and parses config/config.yml.
-
.config_path(type) ⇒ Object
Returns the custom path for a scaffold type from config, or nil.
- .detect ⇒ Object
- .detect_automation(gemfile = read_gemfile) ⇒ Object
- .detect_framework(gemfile = read_gemfile) ⇒ Object
- .read_gemfile ⇒ Object
- .selenium? ⇒ Boolean
-
.validate_project ⇒ Object
Validates that the current directory looks like a Ruby Raider project.
- .watir? ⇒ Boolean
Class Method Details
.config ⇒ Object
Loads and parses config/config.yml. Returns a hash. Raises ScaffoldProjectDetector::Error on malformed YAML.
77 78 79 80 81 82 83 |
# File 'lib/scaffolding/project_detector.rb', line 77 def config return {} unless File.exist?(CONFIG_PATH) YAML.safe_load(File.read(CONFIG_PATH), permitted_classes: [Symbol]) || {} rescue Psych::SyntaxError => e raise Error, "#{CONFIG_PATH} has invalid YAML syntax: #{e.}" end |
.config_path(type) ⇒ Object
Returns the custom path for a scaffold type from config, or nil.
86 87 88 |
# File 'lib/scaffolding/project_detector.rb', line 86 def config_path(type) config["#{type}_path"] end |
.detect ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/scaffolding/project_detector.rb', line 26 def detect gemfile = read_gemfile { automation: detect_automation(gemfile), framework: detect_framework(gemfile), has_spec: Dir.exist?('spec'), has_features: Dir.exist?('features') } end |
.detect_automation(gemfile = read_gemfile) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/scaffolding/project_detector.rb', line 36 def detect_automation(gemfile = read_gemfile) AUTOMATION_GEMS.each do |gem_name, automation| return automation if gemfile.include?("'#{gem_name}'") || gemfile.include?("\"#{gem_name}\"") end 'selenium' end |
.detect_framework(gemfile = read_gemfile) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/scaffolding/project_detector.rb', line 43 def detect_framework(gemfile = read_gemfile) FRAMEWORK_GEMS.each do |gem_name, framework| return framework if gemfile.include?("'#{gem_name}'") || gemfile.include?("\"#{gem_name}\"") end 'rspec' end |
.read_gemfile ⇒ Object
50 51 52 53 54 |
# File 'lib/scaffolding/project_detector.rb', line 50 def read_gemfile return '' unless File.exist?('Gemfile') File.read('Gemfile') end |
.selenium? ⇒ Boolean
56 57 58 |
# File 'lib/scaffolding/project_detector.rb', line 56 def selenium? detect_automation == 'selenium' end |
.validate_project ⇒ Object
Validates that the current directory looks like a Ruby Raider project. Returns an array of warning messages (empty = valid project).
66 67 68 69 70 71 72 73 |
# File 'lib/scaffolding/project_detector.rb', line 66 def validate_project warnings = [] warnings << 'Gemfile not found. Are you in a Ruby Raider project directory?' unless File.exist?('Gemfile') unless File.exist?(CONFIG_PATH) warnings << "#{CONFIG_PATH} not found. Scaffolded pages won't include URL navigation methods." end warnings end |
.watir? ⇒ Boolean
60 61 62 |
# File 'lib/scaffolding/project_detector.rb', line 60 def watir? detect_automation == 'watir' end |