Class: Arfi::Commands::Init
- Defined in:
- lib/arfi/commands/init.rb,
sig/lib/arfi/commands/init.rbs
Overview
Initializes ARFI directory structure inside a Rails project.
Creates/ensures:
- db/functions/public
- db/functions/
/public (when adapter provided)
Constant Summary collapse
- ADAPTERS =
%i[postgresql mysql].freeze
- ROOT_DIR =
'db/functions'- DEFAULT_SCHEMA =
'public'
Instance Method Summary collapse
-
#create ⇒ void
steep:ignore:end.
-
#create_adapter_dirs ⇒ void
Create the adapter-specific function directories (e.g. db/functions/postgresql/public).
-
#create_base_dirs ⇒ void
Create the base db/functions and db/functions/public directories.
-
#validate_schema_format! ⇒ void
Validate that the Rails schema format is set to :ruby.
Methods inherited from Thor
Instance Method Details
#create ⇒ void
This method returns an undefined value.
steep:ignore:end
34 35 36 37 38 |
# File 'lib/arfi/commands/init.rb', line 34 def create validate_schema_format! create_base_dirs create_adapter_dirs if [:adapter] # steep:ignore NoMethod end |
#create_adapter_dirs ⇒ void
This method returns an undefined value.
Create the adapter-specific function directories (e.g. db/functions/postgresql/public).
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/arfi/commands/init.rb', line 75 def create_adapter_dirs adapter = [:adapter].to_s # steep:ignore NoMethod raise Arfi::Errors::AdapterNotSupported unless ADAPTERS.include?(adapter.to_sym) root = Rails.root.join(ROOT_DIR) adapter_root = root.join(adapter) FileUtils.mkdir_p(adapter_root) puts "Ensured: #{adapter_root}" FileUtils.mkdir_p(adapter_root.join(DEFAULT_SCHEMA)) puts "Ensured: #{adapter_root.join(DEFAULT_SCHEMA)}" end |
#create_base_dirs ⇒ void
This method returns an undefined value.
Create the base db/functions and db/functions/public directories.
62 63 64 65 66 67 68 |
# File 'lib/arfi/commands/init.rb', line 62 def create_base_dirs root = Rails.root.join(ROOT_DIR) FileUtils.mkdir_p(root) puts "Ensured: #{root}" FileUtils.mkdir_p(root.join(DEFAULT_SCHEMA)) puts "Ensured: #{root.join(DEFAULT_SCHEMA)}" end |
#validate_schema_format! ⇒ void
This method returns an undefined value.
Validate that the Rails schema format is set to :ruby.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/arfi/commands/init.rb', line 47 def validate_schema_format! fmt = if defined?(Rails) && Rails.application Rails.application.config.active_record.schema_format elsif defined?(ActiveRecord::Base) && ActiveRecord::Base.respond_to?(:schema_format) ActiveRecord::Base.schema_format end raise Arfi::Errors::InvalidSchemaFormat unless fmt == :ruby end |