Total Complexity | 7 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # frozen_string_literal: true |
||
8 | class InstallGenerator < ::Rails::Generators::Base |
||
9 | include ::Rails::Generators::Migration |
||
10 | |||
11 | source_root File.expand_path("../templates", __FILE__) |
||
12 | |||
13 | class_option( |
||
14 | :with_static_bics, |
||
15 | type: :boolean, |
||
16 | default: false, |
||
17 | desc: "Don't create bics table, use static bics." |
||
18 | ) |
||
19 | |||
20 | class_option( |
||
21 | :bics_table_name, |
||
22 | type: :string, |
||
23 | default: "bics", |
||
24 | desc: "BICs table name, `bics` by default." |
||
25 | ) |
||
26 | |||
27 | desc "Generates an initializer file for configuring IbanBic." \ |
||
28 | " Also can generate a migration to add a bics table." |
||
29 | |||
30 | def create_migration_file |
||
31 | migration_template "create_bics.rb.erb", File.join("db", "migrate", "create_bics.rb") unless options.with_static_bics? |
||
32 | end |
||
33 | |||
34 | def create_initializer |
||
35 | template "iban_bic.rb.erb", File.join("config", "initializers", "iban_bic.rb") |
||
36 | end |
||
37 | |||
38 | def self.next_migration_number(dirname) |
||
39 | ::ActiveRecord::Generators::Base.next_migration_number(dirname) |
||
40 | end |
||
41 | |||
42 | def migration_version |
||
43 | "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]" |
||
44 | end |
||
45 | |||
46 | def bics_table_name |
||
47 | options.bics_table_name |
||
48 | end |
||
49 | |||
50 | def static_bics? |
||
51 | options.with_static_bics? |
||
52 | end |
||
53 | end |
||
54 | end |
||
55 |