Class: Chiron::ProjectConfig
- Inherits:
-
Object
- Object
- Chiron::ProjectConfig
- Defined in:
- lib/chiron/project_config.rb
Instance Attribute Summary collapse
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
#framework ⇒ Object
readonly
Returns the value of attribute framework.
-
#linter ⇒ Object
readonly
Returns the value of attribute linter.
-
#test_runner ⇒ Object
readonly
Returns the value of attribute test_runner.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #format_command(file = nil) ⇒ Object
- #framework_name ⇒ Object
-
#initialize(project_type, framework = nil) ⇒ ProjectConfig
constructor
A new instance of ProjectConfig.
- #install_command ⇒ Object
- #lint_command(file = nil) ⇒ Object
- #package_file ⇒ Object
- #test_command(file = nil) ⇒ Object
Constructor Details
#initialize(project_type, framework = nil) ⇒ ProjectConfig
Returns a new instance of ProjectConfig.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/chiron/project_config.rb', line 7 def initialize(project_type, framework = nil) @type = project_type @framework = framework case project_type when :rails @test_runner = 'bin/rspec' @linter = 'bin/rubocop' @formatter = 'bin/rubocop --autocorrect' when :python @test_runner = 'pytest' @linter = 'flake8' @formatter = 'black' end end |
Instance Attribute Details
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
5 6 7 |
# File 'lib/chiron/project_config.rb', line 5 def formatter @formatter end |
#framework ⇒ Object (readonly)
Returns the value of attribute framework.
5 6 7 |
# File 'lib/chiron/project_config.rb', line 5 def framework @framework end |
#linter ⇒ Object (readonly)
Returns the value of attribute linter.
5 6 7 |
# File 'lib/chiron/project_config.rb', line 5 def linter @linter end |
#test_runner ⇒ Object (readonly)
Returns the value of attribute test_runner.
5 6 7 |
# File 'lib/chiron/project_config.rb', line 5 def test_runner @test_runner end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/chiron/project_config.rb', line 5 def type @type end |
Instance Method Details
#format_command(file = nil) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/chiron/project_config.rb', line 45 def format_command(file = nil) case @type when :rails file ? "#{@formatter} #{file}" : @formatter when :python file ? "#{@formatter} #{file}" : "#{@formatter} ." end end |
#framework_name ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/chiron/project_config.rb', line 23 def framework_name case @framework when :django 'Django' when :fastapi 'FastAPI' when :flask 'Flask' else @type.to_s.capitalize end end |
#install_command ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/chiron/project_config.rb', line 80 def install_command case @type when :rails 'bundle install' when :python if File.exist?('Pipfile') 'pipenv install' elsif File.exist?('pyproject.toml') && File.read('pyproject.toml').include?('[tool.poetry]') 'poetry install' else 'pip install -r requirements.txt' end end end |
#lint_command(file = nil) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/chiron/project_config.rb', line 54 def lint_command(file = nil) case @type when :rails file ? "#{@linter} #{file}" : @linter when :python file ? "#{@linter} #{file}" : @linter end end |
#package_file ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/chiron/project_config.rb', line 63 def package_file case @type when :rails 'Gemfile' when :python if File.exist?('pyproject.toml') 'pyproject.toml' elsif File.exist?('Pipfile') 'Pipfile' elsif File.exist?('setup.py') 'setup.py' else 'requirements.txt' end end end |
#test_command(file = nil) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/chiron/project_config.rb', line 36 def test_command(file = nil) case @type when :rails file ? "#{@test_runner} #{file}" : @test_runner when :python file ? "#{@test_runner} #{file}" : @test_runner end end |