Module: Athar::Generators::FxHelper
- Included in:
- InstallGenerator, ModelGenerator
- Defined in:
- lib/generators/athar/fx_helper.rb
Class Method Summary collapse
Instance Method Summary collapse
- #athar_foreign_key_type ⇒ Object
-
#athar_primary_key_type ⇒ Object
Resolve the app-wide Rails generator primary/foreign-key types.
- #ensure_raw_sql_supported! ⇒ Object
- #fx? ⇒ Boolean
-
#indent_sql(text, spaces) ⇒ Object
Indent each non-blank line of ‘text` by `spaces` spaces.
- #primary_key_setting ⇒ Object
- #schema_format ⇒ Object
Class Method Details
.included(base) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/generators/athar/fx_helper.rb', line 8 def self.included(base) base.class_option :fx, type: :boolean, optional: true, desc: "Use the fx gem to manage SQL functions and triggers (default when fx is loaded)." end |
Instance Method Details
#athar_foreign_key_type ⇒ Object
47 48 49 |
# File 'lib/generators/athar/fx_helper.rb', line 47 def athar_foreign_key_type primary_key_setting || :bigint end |
#athar_primary_key_type ⇒ Object
Resolve the app-wide Rails generator primary/foreign-key types.
43 44 45 |
# File 'lib/generators/athar/fx_helper.rb', line 43 def athar_primary_key_type primary_key_setting || :primary_key end |
#ensure_raw_sql_supported! ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/generators/athar/fx_helper.rb', line 28 def ensure_raw_sql_supported! return if schema_format == :sql raise ::Thor::Error, "Athar requires the fx gem (default) or `config.active_record.schema_format = :sql` " \ "when using --no-fx. Either install fx or switch the host app to SQL schema dumps." end |
#fx? ⇒ Boolean
15 16 17 18 19 20 |
# File 'lib/generators/athar/fx_helper.rb', line 15 def fx? return true if [:fx] == true return false if [:fx] == false defined?(::Fx::SchemaDumper) ? true : false end |
#indent_sql(text, spaces) ⇒ Object
Indent each non-blank line of ‘text` by `spaces` spaces.
37 38 39 40 |
# File 'lib/generators/athar/fx_helper.rb', line 37 def indent_sql(text, spaces) prefix = " " * spaces text.each_line.map { |line| line.strip.empty? ? line : prefix + line }.join end |
#primary_key_setting ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/generators/athar/fx_helper.rb', line 51 def primary_key_setting return nil unless defined?(::Rails) && ::Rails.respond_to?(:configuration) generators_config = ::Rails.configuration.generators orm = generators_config.orm generators_config.[orm][:primary_key_type] end |
#schema_format ⇒ Object
22 23 24 25 26 |
# File 'lib/generators/athar/fx_helper.rb', line 22 def schema_format return :ruby unless Rails.application Rails.application.config.active_record.schema_format || :ruby end |