Class: RailsEngineToolkit::Config
- Inherits:
-
Object
- Object
- RailsEngineToolkit::Config
- Defined in:
- lib/rails_engine_toolkit/config.rb
Constant Summary collapse
- DEFAULT_PATH =
'config/engine_toolkit.yml'- REQUIRED_TOP_LEVEL_KEYS =
%w[project author defaults metadata].freeze
- VALID_DATABASES =
%w[postgresql mysql2 sqlite3].freeze
- DEFAULT_DDD_FOLDERS =
[ 'app/use_cases', 'app/services', 'app/policies', 'app/serializers', 'app/repositories', 'app/contracts' ].freeze
- SKIP_FLAG_MAPPING =
{ 'skip_asset_pipeline' => '--skip-asset-pipeline', 'skip_action_mailbox' => '--skip-action-mailbox', 'skip_action_text' => '--skip-action-text', 'skip_active_storage' => '--skip-active-storage', 'skip_hotwire' => '--skip-hotwire', 'skip_jbuilder' => '--skip-jbuilder', 'skip_system_test' => '--skip-system-test', 'skip_rubocop' => '--skip-rubocop' }.freeze
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
- #api_only? ⇒ Boolean
- #author_email ⇒ Object
- #author_name ⇒ Object
- #create_ddd_structure? ⇒ Boolean
- #ddd_folders ⇒ Object
- #default_database ⇒ Object
-
#initialize(data, path:) ⇒ Config
constructor
A new instance of Config.
- #license ⇒ Object
- #mount_routes? ⇒ Boolean
- #project_name ⇒ Object
- #project_slug ⇒ Object
- #project_url ⇒ Object
- #rails_version ⇒ Object
- #ruby_version ⇒ Object
- #skip_flags ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(data, path:) ⇒ Config
Returns a new instance of Config.
37 38 39 40 |
# File 'lib/rails_engine_toolkit/config.rb', line 37 def initialize(data, path:) @data = data @path = path end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
28 29 30 |
# File 'lib/rails_engine_toolkit/config.rb', line 28 def data @data end |
Class Method Details
.load(project_root, path: DEFAULT_PATH) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/rails_engine_toolkit/config.rb', line 30 def self.load(project_root, path: DEFAULT_PATH) full_path = Pathname(project_root).join(path) raise ValidationError, "Configuration file not found: #{full_path}" unless full_path.exist? new(YAML.safe_load(full_path.read, aliases: true) || {}, path: full_path).tap(&:validate!) end |
Instance Method Details
#api_only? ⇒ Boolean
67 |
# File 'lib/rails_engine_toolkit/config.rb', line 67 def api_only? = !!fetch('defaults', 'api_only', default: true) |
#author_email ⇒ Object
62 |
# File 'lib/rails_engine_toolkit/config.rb', line 62 def = fetch('author', 'email') |
#author_name ⇒ Object
61 |
# File 'lib/rails_engine_toolkit/config.rb', line 61 def = fetch('author', 'name') |
#create_ddd_structure? ⇒ Boolean
69 |
# File 'lib/rails_engine_toolkit/config.rb', line 69 def create_ddd_structure? = !!fetch('defaults', 'create_ddd_structure', default: true) |
#ddd_folders ⇒ Object
78 79 80 |
# File 'lib/rails_engine_toolkit/config.rb', line 78 def ddd_folders fetch('ddd', 'folders', default: DEFAULT_DDD_FOLDERS) end |
#default_database ⇒ Object
66 |
# File 'lib/rails_engine_toolkit/config.rb', line 66 def default_database = fetch('defaults', 'database', default: 'postgresql') |
#license ⇒ Object
63 |
# File 'lib/rails_engine_toolkit/config.rb', line 63 def license = fetch('metadata', 'license', default: 'MIT') |
#mount_routes? ⇒ Boolean
68 |
# File 'lib/rails_engine_toolkit/config.rb', line 68 def mount_routes? = !!fetch('defaults', 'mount_routes', default: true) |
#project_name ⇒ Object
58 |
# File 'lib/rails_engine_toolkit/config.rb', line 58 def project_name = fetch('project', 'name') |
#project_slug ⇒ Object
59 |
# File 'lib/rails_engine_toolkit/config.rb', line 59 def project_slug = fetch('project', 'slug') |
#project_url ⇒ Object
60 |
# File 'lib/rails_engine_toolkit/config.rb', line 60 def project_url = fetch('project', 'url', default: '') |
#rails_version ⇒ Object
65 |
# File 'lib/rails_engine_toolkit/config.rb', line 65 def rails_version = fetch('metadata', 'rails_version', default: '>= 8.1.2') |
#ruby_version ⇒ Object
64 |
# File 'lib/rails_engine_toolkit/config.rb', line 64 def ruby_version = fetch('metadata', 'ruby_version', default: '>= 3.2') |
#skip_flags ⇒ Object
71 72 73 74 75 76 |
# File 'lib/rails_engine_toolkit/config.rb', line 71 def skip_flags defaults = data.fetch('defaults', {}) SKIP_FLAG_MAPPING.filter_map do |key, flag| flag if defaults.fetch(key, true) end end |
#validate! ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rails_engine_toolkit/config.rb', line 42 def validate! REQUIRED_TOP_LEVEL_KEYS.each do |key| raise ValidationError, "Missing config section: #{key} in #{@path}" unless data.key?(key) end validate_string('project', 'name') validate_string('project', 'slug') validate_string('author', 'name') validate_string('author', 'email') raise ValidationError, 'project.slug must be snake_case' unless Utils.snake_case?(project_slug) return true if VALID_DATABASES.include?(default_database) raise ValidationError, "defaults.database must be one of: #{VALID_DATABASES.join(', ')}" end |