biran 0.1.8 → 0.1.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +33 -1
- data/config/_my_config.yml.erb +2 -0
- data/config/app_config.yml +13 -0
- data/lib/biran.rb +1 -0
- data/lib/biran/config_defaults.rb +20 -8
- data/lib/biran/configurinator.rb +13 -11
- data/lib/biran/erb_config.rb +31 -9
- data/lib/biran/exceptions.rb +16 -0
- data/lib/biran/version.rb +1 -1
- data/lib/tasks/biran_tasks.rake +23 -2
- metadata +31 -23
- data/lib/biran/configurinator.rb.debug +0 -145
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: ec150cd74d08598ecb7d3bfb1324bf57c15e20806c0143b042b257569f430bf6
         | 
| 4 | 
            +
              data.tar.gz: 7863cf3face519ede43bb1ca24f569112ad83fe8e686c467141c81a13a0b981d
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 5464720ba0f9989e9941b77ca1fd54a17388eedd3d044e180689ce58fb7a1da87252e0ccfa09fab514410077ffe18b0a7fbbb52a56a35fce0ebc8ed6b5fb4964
         | 
| 7 | 
            +
              data.tar.gz: 1edb42ac1ebc49f45d6c60e312a4bd089495fdc11c2c96be0f1f2328f4a8d6bbdb5d14b11dbfe16fae34b8c1ab086b6ee48c82bfe4d0c3d0e8a0400e73a4b907
         | 
    
        data/README.md
    CHANGED
    
    | @@ -231,7 +231,7 @@ Availble in: environment, initializer, instance** | |
| 231 231 |  | 
| 232 232 | 
             
            Generally not needed to specify unless you are not using rails or do not want to use `Rails.env` for lookups in config blocks.  
         | 
| 233 233 | 
             
            You can set the app_env during instance creation by passing an environment string.  
         | 
| 234 | 
            -
            The following example will use the  | 
| 234 | 
            +
            The following example will use the value of one of the built in environment variable found, checked in the following order: BIRAN_APP_ENV, RAILS_ENV, RACK_ENV. If one of the environment variables is not found, the default value will be used.
         | 
| 235 235 | 
             
            ```
         | 
| 236 236 | 
             
            config = Biran::Configurinator.new
         | 
| 237 237 | 
             
            ```
         | 
| @@ -302,7 +302,39 @@ app: | |
| 302 302 | 
             
                  extension: ‘.yml’
         | 
| 303 303 | 
             
                  output_dir: ‘/srv/app/current/reports’
         | 
| 304 304 | 
             
                  output_name: ‘user_report’
         | 
| 305 | 
            +
            ```  
         | 
| 306 | 
            +
             | 
| 307 | 
            +
            In a more advanced example, you can generate multiple files from the same template by setting the `config_index_list` option. If you set this as a list of indexes, then a file will be generated for each index. The index number 
         | 
| 308 | 
            +
            will get passed to the template as an instance variable (`@config_index`) and can be used to look up a specific version of values from the config file. The file that is generated will respect the normal naming, including using the `output_name` option, however, it will append the 
         | 
| 309 | 
            +
            index number to the end of the file name. If the name was going to be special_file, and you add an index list of `[1,2]`, two files will get generated named `special_file-1` and `special_file-2`.  
         | 
| 310 | 
            +
            Advanced example from `config/app:.yml`:
         | 
| 311 | 
            +
            ```
         | 
| 312 | 
            +
            app:
         | 
| 313 | 
            +
              files_to_generate:
         | 
| 314 | 
            +
                reports:
         | 
| 315 | 
            +
                  extension: '.yml'
         | 
| 316 | 
            +
                  config_index_list:
         | 
| 317 | 
            +
                    - one
         | 
| 318 | 
            +
                    - two
         | 
| 319 | 
            +
            reports:
         | 
| 320 | 
            +
              default: &reports_default_values
         | 
| 321 | 
            +
                some_value: 'some_value'
         | 
| 322 | 
            +
                other_value: 'other_value'
         | 
| 323 | 
            +
              one:
         | 
| 324 | 
            +
                <<: *reports_default_values
         | 
| 325 | 
            +
              two:
         | 
| 326 | 
            +
                <<: *reports_default_values
         | 
| 327 | 
            +
                some_value: 'my_value'
         | 
| 328 | 
            +
            ```  
         | 
| 329 | 
            +
            Then in your template file you can use the index to get the proper config for each generated file. This allows you to reuse the same template to generate multiple files, each with different content. This is useful for generating service config files, like for sidekiq workers.
         | 
| 330 | 
            +
            The config above would generate two files: `config/reports-one.yml` and `config/reports-two.yml`, using the content from each index block as specified in the following simple template example.
         | 
| 305 331 | 
             
            ```
         | 
| 332 | 
            +
            <% index = "{@config_index}" -%>
         | 
| 333 | 
            +
            defaults:
         | 
| 334 | 
            +
              :some_value: <%= @app_config[:reports][index.to_sym][:some_value] %>
         | 
| 335 | 
            +
              :other_value: <%= @app_config[:reports][index.to_sym][:other_value] %>
         | 
| 336 | 
            +
            ```  
         | 
| 337 | 
            +
             | 
| 306 338 | 
             
            ### vhost_public_dirname
         | 
| 307 339 | 
             
            **Type: string  
         | 
| 308 340 | 
             
            Default: 'public'  
         | 
    
        data/lib/biran.rb
    CHANGED
    
    
| @@ -11,16 +11,16 @@ module Biran | |
| 11 11 | 
             
                      shared_dir: configuration.shared_dir,
         | 
| 12 12 | 
             
                      base_dir: configuration.base_dir,
         | 
| 13 13 | 
             
                      use_capistrano: configuration.use_capistrano,
         | 
| 14 | 
            -
                      db_config: configuration.db_config,
         | 
| 15 | 
            -
                      secrets: configuration.secrets,
         | 
| 16 14 | 
             
                      bindings: configuration.bindings,
         | 
| 17 15 | 
             
                      vhost_public_dirname: configuration.vhost_public_dirname
         | 
| 18 | 
            -
                    }
         | 
| 16 | 
            +
                    },
         | 
| 17 | 
            +
                    db_config: configuration.db_config,
         | 
| 18 | 
            +
                    secrets: configuration.secrets,
         | 
| 19 19 | 
             
                  }
         | 
| 20 20 | 
             
                end
         | 
| 21 21 |  | 
| 22 22 | 
             
                def app_env
         | 
| 23 | 
            -
                  ENV['BIRAN_APP_ENV'] || ENV[' | 
| 23 | 
            +
                  ENV['BIRAN_APP_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || configuration.app_env
         | 
| 24 24 | 
             
                end
         | 
| 25 25 |  | 
| 26 26 | 
             
                def app_base
         | 
| @@ -47,7 +47,11 @@ module Biran | |
| 47 47 |  | 
| 48 48 | 
             
                def local_config_file
         | 
| 49 49 | 
             
                  ENV['BIRAN_LOCAL_CONFIG_FILE'] ||
         | 
| 50 | 
            -
                    File.join(app_shared_dir, configuration.config_dirname,  | 
| 50 | 
            +
                    File.join(app_shared_dir, configuration.config_dirname, local_config_filename)
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                def local_config_filename
         | 
| 54 | 
            +
                  ENV['BIRAN_LOCAL_CONFIG_FILENAME'] || app_config_defaults[:app][:local_config_filename] || configuration.local_config_filename
         | 
| 51 55 | 
             
                end
         | 
| 52 56 |  | 
| 53 57 | 
             
                def vhost_public_dirname
         | 
| @@ -55,15 +59,23 @@ module Biran | |
| 55 59 | 
             
                end
         | 
| 56 60 |  | 
| 57 61 | 
             
                def db_config_override_file
         | 
| 58 | 
            -
                  File.join(app_shared_dir, configuration.config_dirname,  | 
| 62 | 
            +
                  File.join(app_shared_dir, configuration.config_dirname, db_config_filename)
         | 
| 63 | 
            +
                end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                def db_config_filename
         | 
| 66 | 
            +
                   app_config_defaults[:app][:db_config_filename] || configuration.db_config_filename
         | 
| 59 67 | 
             
                end
         | 
| 60 68 |  | 
| 61 69 | 
             
                def secrets_file
         | 
| 62 | 
            -
                  File.join(configuration.base_path, configuration.config_dirname,  | 
| 70 | 
            +
                  File.join(configuration.base_path, configuration.config_dirname, secrets_filename)
         | 
| 71 | 
            +
                end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                def secrets_filename
         | 
| 74 | 
            +
                  app_config_defaults[:app][:secrets_filename] || configuration.secrets_filename
         | 
| 63 75 | 
             
                end
         | 
| 64 76 |  | 
| 65 77 | 
             
                def default_db_config_file
         | 
| 66 | 
            -
                  File.join(config_dir,  | 
| 78 | 
            +
                  File.join(config_dir, db_config_filename)
         | 
| 67 79 | 
             
                end
         | 
| 68 80 |  | 
| 69 81 | 
             
                def use_capistrano?
         | 
    
        data/lib/biran/configurinator.rb
    CHANGED
    
    | @@ -30,12 +30,17 @@ module Biran | |
| 30 30 | 
             
                    .tap { |files_list| files_list.each(&sanitize_config_files(files_list)) }
         | 
| 31 31 | 
             
                end
         | 
| 32 32 |  | 
| 33 | 
            -
                def create(name:, extension:, output_dir: nil, output_name: nil)
         | 
| 33 | 
            +
                def create(name:, extension:, output_dir: nil, output_name: nil, config_index_list: [])
         | 
| 34 34 | 
             
                  output_dir ||= config_dir
         | 
| 35 35 | 
             
                  output_name ||= name
         | 
| 36 36 | 
             
                  generated_file = ERBConfig.new(filtered_config, name, extension, config_dir, output_dir, output_name)
         | 
| 37 37 | 
             
                  generated_file.bindings = bindings
         | 
| 38 | 
            -
                  generated_file.save!
         | 
| 38 | 
            +
                  return generated_file.save! unless config_index_list.any?
         | 
| 39 | 
            +
                  config_index_list.each do |config_index|
         | 
| 40 | 
            +
                    generated_file.output_name = "#{output_name}-#{config_index}"
         | 
| 41 | 
            +
                    generated_file.template_config_index = config_index
         | 
| 42 | 
            +
                    generated_file.save!
         | 
| 43 | 
            +
                  end
         | 
| 39 44 | 
             
                end
         | 
| 40 45 |  | 
| 41 46 | 
             
                private
         | 
| @@ -53,8 +58,8 @@ module Biran | |
| 53 58 | 
             
                  }
         | 
| 54 59 |  | 
| 55 60 | 
             
                  app_config.deep_merge! app_config_defaults
         | 
| 56 | 
            -
                  app_config[:secrets]  | 
| 57 | 
            -
                  app_config[:db_config]  | 
| 61 | 
            +
                  app_config[:secrets].deep_merge! get_secrets_content(app_config[:secrets_file_path])
         | 
| 62 | 
            +
                  app_config[:db_config].deep_merge! build_db_config
         | 
| 58 63 |  | 
| 59 64 | 
             
                  app_config.deep_merge! local_config_file_contents
         | 
| 60 65 | 
             
                end
         | 
| @@ -103,16 +108,13 @@ module Biran | |
| 103 108 | 
             
                  @local_config_contents = process_config_file(local_config_file)
         | 
| 104 109 | 
             
                end
         | 
| 105 110 |  | 
| 106 | 
            -
                def  | 
| 107 | 
            -
                   | 
| 108 | 
            -
                   | 
| 109 | 
            -
                    secrets_file_contents = process_config_file app_config[:secrets_file_path]
         | 
| 110 | 
            -
                  end
         | 
| 111 | 
            -
                  secrets_file_contents
         | 
| 111 | 
            +
                def get_secrets_content(secrets_file)
         | 
| 112 | 
            +
                  return {} unless File.exists? secrets_file
         | 
| 113 | 
            +
                  process_config_file secrets_file
         | 
| 112 114 | 
             
                end
         | 
| 113 115 |  | 
| 114 116 | 
             
                def sanitize_config_files files_list
         | 
| 115 | 
            -
                  lambda do |file, _|
         | 
| 117 | 
            +
                  lambda do |(file, _)|
         | 
| 116 118 | 
             
                    files_list[file] ||=  {extension: ''}
         | 
| 117 119 | 
             
                    ext = files_list[file].fetch(:extension, '').strip
         | 
| 118 120 | 
             
                    ext.prepend('.') unless ext.start_with?('.') || ext.empty?
         | 
    
        data/lib/biran/erb_config.rb
    CHANGED
    
    | @@ -1,34 +1,56 @@ | |
| 1 1 | 
             
            module Biran
         | 
| 2 2 | 
             
              class ERBConfig
         | 
| 3 | 
            -
                attr_reader :output_dir, :source_dir, :name, :extension, :config, : | 
| 4 | 
            -
                attr_accessor :bindings
         | 
| 3 | 
            +
                attr_reader :output_dir, :source_dir, :name, :extension, :config, :template_contents
         | 
| 4 | 
            +
                attr_accessor :bindings, :output_name, :template_config_index
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                DEFAULT_TEMPLATE_CONFIG_INDEX = 1
         | 
| 5 7 |  | 
| 6 8 | 
             
                def initialize(config, name, extension, source, output_dir, output_name)
         | 
| 7 | 
            -
                   | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 9 | 
            +
                  before_process_erb do
         | 
| 10 | 
            +
                    @name       = name
         | 
| 11 | 
            +
                    @extension  = extension
         | 
| 12 | 
            +
                    @config     = config
         | 
| 13 | 
            +
                    @source_dir = source
         | 
| 14 | 
            +
                    @output_dir = output_dir
         | 
| 15 | 
            +
                    @output_name = output_name
         | 
| 16 | 
            +
                  end
         | 
| 13 17 | 
             
                end
         | 
| 14 18 |  | 
| 15 19 | 
             
                def save!
         | 
| 16 20 | 
             
                  File.open(File.join(output_dir, "#{output_name}#{extension}"), 'w') do |f|
         | 
| 17 | 
            -
                    f.print  | 
| 21 | 
            +
                    f.print template_contents.result(build_erb_env.call)
         | 
| 18 22 | 
             
                  end
         | 
| 19 23 | 
             
                end
         | 
| 20 24 |  | 
| 21 25 | 
             
                private
         | 
| 22 26 |  | 
| 27 | 
            +
                def before_process_erb
         | 
| 28 | 
            +
                  yield
         | 
| 29 | 
            +
                  raise ArgumentError unless process_erb_ready?
         | 
| 30 | 
            +
                  @template_contents = process_erb
         | 
| 31 | 
            +
                rescue ArgumentError
         | 
| 32 | 
            +
                  e_message = "Settings required to determine template name for #{name} are not configured"
         | 
| 33 | 
            +
                  raise Biran::ConfigSyntaxError, e_message
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                def process_erb_ready?
         | 
| 37 | 
            +
                  @name &&
         | 
| 38 | 
            +
                  @extension &&
         | 
| 39 | 
            +
                  @source_dir
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 23 42 | 
             
                def process_erb
         | 
| 24 43 | 
             
                  config_erb_file = File.join(source_dir, "_#{name}#{extension}.erb")
         | 
| 25 44 | 
             
                  ERB.new(File.read(config_erb_file), nil, '-')
         | 
| 45 | 
            +
                rescue Errno::ENOENT
         | 
| 46 | 
            +
                  raise Biran::ConfigSyntaxError, "Missing template file for #{name}: #{config_erb_file}"
         | 
| 26 47 | 
             
                end
         | 
| 27 48 |  | 
| 28 49 | 
             
                def build_erb_env
         | 
| 29 50 | 
             
                  proc do
         | 
| 30 51 | 
             
                    @environment = config[:env]
         | 
| 31 52 | 
             
                    @app_config  = config
         | 
| 53 | 
            +
                    @config_index =  template_config_index || DEFAULT_TEMPLATE_CONFIG_INDEX
         | 
| 32 54 |  | 
| 33 55 | 
             
                    @bindings.each(&assign_instance_vars) unless @bindings.nil?
         | 
| 34 56 |  | 
| @@ -0,0 +1,16 @@ | |
| 1 | 
            +
            module Biran
         | 
| 2 | 
            +
              class ConfigSyntaxError < ::StandardError
         | 
| 3 | 
            +
                def initialize(msg=nil)
         | 
| 4 | 
            +
                  @msg = msg || 'Missing required argument or bad formatting in config file'
         | 
| 5 | 
            +
                  set_backtrace []
         | 
| 6 | 
            +
                end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def to_s
         | 
| 9 | 
            +
                  @msg
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def p_warning
         | 
| 13 | 
            +
                  "Warning: #{@msg}"
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
            end
         | 
    
        data/lib/biran/version.rb
    CHANGED
    
    
    
        data/lib/tasks/biran_tasks.rake
    CHANGED
    
    | @@ -1,18 +1,39 @@ | |
| 1 1 | 
             
            namespace :config do
         | 
| 2 2 | 
             
              config = Biran::Configurinator.new
         | 
| 3 3 |  | 
| 4 | 
            -
              desc 'Generate new config files'
         | 
| 5 | 
            -
              task : | 
| 4 | 
            +
              desc 'Legacy - Generate all new config files'
         | 
| 5 | 
            +
              task :generate_legacy do
         | 
| 6 6 | 
             
                Rake::Task['config:generate_with_deps'].enhance config.file_tasks
         | 
| 7 7 | 
             
                Rake::Task['config:generate_with_deps'].invoke
         | 
| 8 8 | 
             
              end
         | 
| 9 9 |  | 
| 10 10 | 
             
              task :generate_with_deps
         | 
| 11 11 |  | 
| 12 | 
            +
              desc 'Generate all new config files'
         | 
| 13 | 
            +
              task :generate do
         | 
| 14 | 
            +
                error_count = 0
         | 
| 15 | 
            +
                config.file_tasks.each do |task|
         | 
| 16 | 
            +
                  Rake::Task["config:#{task}"].invoke
         | 
| 17 | 
            +
                rescue Biran::ConfigSyntaxError => e
         | 
| 18 | 
            +
                  error_count += 1
         | 
| 19 | 
            +
                  puts e.p_warning
         | 
| 20 | 
            +
                  next
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                abort 'Errors in creating config files' unless error_count == 0
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
             | 
| 12 26 | 
             
              config.files_to_generate.each do |file_name, options|
         | 
| 13 27 | 
             
                desc %(Generate the #{file_name}#{options.fetch(:extension, '')} config file)
         | 
| 14 28 | 
             
                task file_name do
         | 
| 15 29 | 
             
                  config.create name: file_name, **options
         | 
| 30 | 
            +
                rescue ArgumentError => e
         | 
| 31 | 
            +
                  e_message = "Missing required argument or bad formatting in config file for #{file_name}"
         | 
| 32 | 
            +
                  e.set_backtrace([])
         | 
| 33 | 
            +
                  raise Biran::ConfigSyntaxError, e_message
         | 
| 34 | 
            +
                rescue Biran::ConfigSyntaxError => e
         | 
| 35 | 
            +
                  e.set_backtrace([])
         | 
| 36 | 
            +
                  raise Biran::ConfigSyntaxError, e.message
         | 
| 16 37 | 
             
                end
         | 
| 17 38 | 
             
              end
         | 
| 18 39 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,16 +1,16 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: biran
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.13.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - javierg
         | 
| 8 8 | 
             
            - brlanier
         | 
| 9 9 | 
             
            - seancookr
         | 
| 10 | 
            -
            autorequire: | 
| 10 | 
            +
            autorequire:
         | 
| 11 11 | 
             
            bindir: bin
         | 
| 12 12 | 
             
            cert_chain: []
         | 
| 13 | 
            -
            date:  | 
| 13 | 
            +
            date: 2021-03-18 00:00:00.000000000 Z
         | 
| 14 14 | 
             
            dependencies:
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 16 16 | 
             
              name: railties
         | 
| @@ -44,6 +44,9 @@ dependencies: | |
| 44 44 | 
             
              name: rails
         | 
| 45 45 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 46 46 | 
             
                requirements:
         | 
| 47 | 
            +
                - - "~>"
         | 
| 48 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 49 | 
            +
                    version: '5.0'
         | 
| 47 50 | 
             
                - - ">="
         | 
| 48 51 | 
             
                  - !ruby/object:Gem::Version
         | 
| 49 52 | 
             
                    version: 5.0.7
         | 
| @@ -51,6 +54,9 @@ dependencies: | |
| 51 54 | 
             
              prerelease: false
         | 
| 52 55 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 53 56 | 
             
                requirements:
         | 
| 57 | 
            +
                - - "~>"
         | 
| 58 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 59 | 
            +
                    version: '5.0'
         | 
| 54 60 | 
             
                - - ">="
         | 
| 55 61 | 
             
                  - !ruby/object:Gem::Version
         | 
| 56 62 | 
             
                    version: 5.0.7
         | 
| @@ -58,58 +64,58 @@ dependencies: | |
| 58 64 | 
             
              name: bundler
         | 
| 59 65 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 60 66 | 
             
                requirements:
         | 
| 61 | 
            -
                - - " | 
| 67 | 
            +
                - - "~>"
         | 
| 62 68 | 
             
                  - !ruby/object:Gem::Version
         | 
| 63 | 
            -
                    version: ' | 
| 69 | 
            +
                    version: '2.1'
         | 
| 64 70 | 
             
              type: :development
         | 
| 65 71 | 
             
              prerelease: false
         | 
| 66 72 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 67 73 | 
             
                requirements:
         | 
| 68 | 
            -
                - - " | 
| 74 | 
            +
                - - "~>"
         | 
| 69 75 | 
             
                  - !ruby/object:Gem::Version
         | 
| 70 | 
            -
                    version: ' | 
| 76 | 
            +
                    version: '2.1'
         | 
| 71 77 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 72 78 | 
             
              name: rspec
         | 
| 73 79 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 74 80 | 
             
                requirements:
         | 
| 75 | 
            -
                - - " | 
| 81 | 
            +
                - - "~>"
         | 
| 76 82 | 
             
                  - !ruby/object:Gem::Version
         | 
| 77 | 
            -
                    version: ' | 
| 83 | 
            +
                    version: '3.7'
         | 
| 78 84 | 
             
              type: :development
         | 
| 79 85 | 
             
              prerelease: false
         | 
| 80 86 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 81 87 | 
             
                requirements:
         | 
| 82 | 
            -
                - - " | 
| 88 | 
            +
                - - "~>"
         | 
| 83 89 | 
             
                  - !ruby/object:Gem::Version
         | 
| 84 | 
            -
                    version: ' | 
| 90 | 
            +
                    version: '3.7'
         | 
| 85 91 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 86 92 | 
             
              name: tapout
         | 
| 87 93 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 88 94 | 
             
                requirements:
         | 
| 89 | 
            -
                - - " | 
| 95 | 
            +
                - - "~>"
         | 
| 90 96 | 
             
                  - !ruby/object:Gem::Version
         | 
| 91 | 
            -
                    version: '0'
         | 
| 97 | 
            +
                    version: '0.4'
         | 
| 92 98 | 
             
              type: :development
         | 
| 93 99 | 
             
              prerelease: false
         | 
| 94 100 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 95 101 | 
             
                requirements:
         | 
| 96 | 
            -
                - - " | 
| 102 | 
            +
                - - "~>"
         | 
| 97 103 | 
             
                  - !ruby/object:Gem::Version
         | 
| 98 | 
            -
                    version: '0'
         | 
| 104 | 
            +
                    version: '0.4'
         | 
| 99 105 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 100 106 | 
             
              name: rspec-ontap
         | 
| 101 107 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 102 108 | 
             
                requirements:
         | 
| 103 | 
            -
                - - " | 
| 109 | 
            +
                - - "~>"
         | 
| 104 110 | 
             
                  - !ruby/object:Gem::Version
         | 
| 105 | 
            -
                    version: '0'
         | 
| 111 | 
            +
                    version: '0.3'
         | 
| 106 112 | 
             
              type: :development
         | 
| 107 113 | 
             
              prerelease: false
         | 
| 108 114 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 109 115 | 
             
                requirements:
         | 
| 110 | 
            -
                - - " | 
| 116 | 
            +
                - - "~>"
         | 
| 111 117 | 
             
                  - !ruby/object:Gem::Version
         | 
| 112 | 
            -
                    version: '0'
         | 
| 118 | 
            +
                    version: '0.3'
         | 
| 113 119 | 
             
            description: Biran is the guy that will help you generate config files for your rail
         | 
| 114 120 | 
             
              app.
         | 
| 115 121 | 
             
            email:
         | 
| @@ -121,12 +127,14 @@ files: | |
| 121 127 | 
             
            - MIT-LICENSE
         | 
| 122 128 | 
             
            - README.md
         | 
| 123 129 | 
             
            - Rakefile
         | 
| 130 | 
            +
            - config/_my_config.yml.erb
         | 
| 131 | 
            +
            - config/app_config.yml
         | 
| 124 132 | 
             
            - lib/biran.rb
         | 
| 125 133 | 
             
            - lib/biran/config.rb
         | 
| 126 134 | 
             
            - lib/biran/config_defaults.rb
         | 
| 127 135 | 
             
            - lib/biran/configurinator.rb
         | 
| 128 | 
            -
            - lib/biran/configurinator.rb.debug
         | 
| 129 136 | 
             
            - lib/biran/erb_config.rb
         | 
| 137 | 
            +
            - lib/biran/exceptions.rb
         | 
| 130 138 | 
             
            - lib/biran/railtie.rb
         | 
| 131 139 | 
             
            - lib/biran/version.rb
         | 
| 132 140 | 
             
            - lib/tasks/biran_tasks.rake
         | 
| @@ -134,7 +142,7 @@ homepage: https://github.com/amco/biran | |
| 134 142 | 
             
            licenses:
         | 
| 135 143 | 
             
            - MIT
         | 
| 136 144 | 
             
            metadata: {}
         | 
| 137 | 
            -
            post_install_message: | 
| 145 | 
            +
            post_install_message:
         | 
| 138 146 | 
             
            rdoc_options: []
         | 
| 139 147 | 
             
            require_paths:
         | 
| 140 148 | 
             
            - lib
         | 
| @@ -149,8 +157,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 149 157 | 
             
                - !ruby/object:Gem::Version
         | 
| 150 158 | 
             
                  version: '0'
         | 
| 151 159 | 
             
            requirements: []
         | 
| 152 | 
            -
            rubygems_version: 3. | 
| 153 | 
            -
            signing_key: | 
| 160 | 
            +
            rubygems_version: 3.2.3
         | 
| 161 | 
            +
            signing_key:
         | 
| 154 162 | 
             
            specification_version: 4
         | 
| 155 163 | 
             
            summary: Helper for generating config generate tasks.
         | 
| 156 164 | 
             
            test_files: []
         | 
| @@ -1,145 +0,0 @@ | |
| 1 | 
            -
            module Biran
         | 
| 2 | 
            -
              class Configurinator
         | 
| 3 | 
            -
                include ConfigDefaults
         | 
| 4 | 
            -
             | 
| 5 | 
            -
                DEFAULT_ENV = 'development'
         | 
| 6 | 
            -
             | 
| 7 | 
            -
                attr_reader :config, :db_config
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                class << self
         | 
| 10 | 
            -
                  attr_accessor :config
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                  def configure
         | 
| 13 | 
            -
                    self.config ||= Config.instance
         | 
| 14 | 
            -
                    yield config
         | 
| 15 | 
            -
                  end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                  def env= env
         | 
| 18 | 
            -
                    @env = env
         | 
| 19 | 
            -
                  end
         | 
| 20 | 
            -
                end
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                def env
         | 
| 23 | 
            -
                  return @env if @env
         | 
| 24 | 
            -
                  @env = app_env
         | 
| 25 | 
            -
                end
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                def initialize
         | 
| 28 | 
            -
                  @config = build_app_config
         | 
| 29 | 
            -
                end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                def file_tasks
         | 
| 32 | 
            -
                  files_to_generate.keys
         | 
| 33 | 
            -
                end
         | 
| 34 | 
            -
             | 
| 35 | 
            -
                def debug_stuff
         | 
| 36 | 
            -
                  puts "app env2 is: #{app_env}"
         | 
| 37 | 
            -
                  puts "instance @env is #{@env}"
         | 
| 38 | 
            -
                  puts "env from method is #{env}"
         | 
| 39 | 
            -
                  puts "rack env is #{ENV['RACK_ENV']}"
         | 
| 40 | 
            -
                end
         | 
| 41 | 
            -
             | 
| 42 | 
            -
                def files_to_generate
         | 
| 43 | 
            -
                  @files_to_generate ||= config.fetch(:app, {})
         | 
| 44 | 
            -
                    .fetch(:files_to_generate, configuration.files_to_generate)
         | 
| 45 | 
            -
                    .tap { |files_list| files_list.each(&sanitize_config_files(files_list)) }
         | 
| 46 | 
            -
                end
         | 
| 47 | 
            -
             | 
| 48 | 
            -
                def create(name:, extension:, output_dir: nil)
         | 
| 49 | 
            -
                  output_dir ||= config_dir
         | 
| 50 | 
            -
                  #debug_stuff
         | 
| 51 | 
            -
                  generated_file = ERBConfig.new(filtered_config, name, extension, config_dir, output_dir)
         | 
| 52 | 
            -
                  generated_file.bindings = bindings
         | 
| 53 | 
            -
                  generated_file.save!
         | 
| 54 | 
            -
                end
         | 
| 55 | 
            -
             | 
| 56 | 
            -
                private
         | 
| 57 | 
            -
             | 
| 58 | 
            -
                def build_app_config
         | 
| 59 | 
            -
                  app_config = {
         | 
| 60 | 
            -
                    app_root_dir: app_root,
         | 
| 61 | 
            -
                    app_shared_dir: app_shared_dir,
         | 
| 62 | 
            -
                    app_base_dir: app_base,
         | 
| 63 | 
            -
                    env: env,
         | 
| 64 | 
            -
                    local_config_file: local_config_file,
         | 
| 65 | 
            -
                    secrets_file_path: secrets_file,
         | 
| 66 | 
            -
                    vhost: config_vhost_dirs
         | 
| 67 | 
            -
                  }
         | 
| 68 | 
            -
             | 
| 69 | 
            -
                  app_config.deep_merge! app_config_defaults
         | 
| 70 | 
            -
                  app_config[:secrets] = get_secret_contents(app_config)
         | 
| 71 | 
            -
                  app_config[:db_config] = build_db_config
         | 
| 72 | 
            -
             | 
| 73 | 
            -
                  app_config.deep_merge! local_config_file_contents
         | 
| 74 | 
            -
                end
         | 
| 75 | 
            -
             | 
| 76 | 
            -
                def build_db_config
         | 
| 77 | 
            -
                  default_db_config = base_db_config
         | 
| 78 | 
            -
                  return default_db_config unless File.exist? db_config_override_file
         | 
| 79 | 
            -
                  default_db_config.deep_merge! process_config_file(db_config_override_file)
         | 
| 80 | 
            -
                end
         | 
| 81 | 
            -
             | 
| 82 | 
            -
                def base_db_config
         | 
| 83 | 
            -
                  return @base_db_config if @base_db_config
         | 
| 84 | 
            -
                  return @base_db_config = {} unless File.exists? default_db_config_file
         | 
| 85 | 
            -
                  @base_db_config ||= process_config_file(default_db_config_file)
         | 
| 86 | 
            -
                end
         | 
| 87 | 
            -
             | 
| 88 | 
            -
                def app_config_defaults
         | 
| 89 | 
            -
                  return @app_config_defaults if @app_config_defaults
         | 
| 90 | 
            -
                  app_config_file = File.join(configuration.config_dirname, configuration.config_filename)
         | 
| 91 | 
            -
                  app_defaults = app_defaults_init.dup
         | 
| 92 | 
            -
                  config_properties = process_config_file(app_config_file)
         | 
| 93 | 
            -
                  @app_config_defaults = app_defaults.deep_merge! config_properties
         | 
| 94 | 
            -
                end
         | 
| 95 | 
            -
             | 
| 96 | 
            -
                def process_config_file(config_file)
         | 
| 97 | 
            -
                  config_file_contents = File.read(config_file)
         | 
| 98 | 
            -
                  config_file_contents = ERB.new(config_file_contents).result
         | 
| 99 | 
            -
                  config_file_contents = YAML.safe_load(config_file_contents, [], [], true)
         | 
| 100 | 
            -
                  config_file_contents[env].deep_symbolize_keys!
         | 
| 101 | 
            -
                rescue Errno::ENOENT
         | 
| 102 | 
            -
                  raise "Missing config file: #{config_file}"
         | 
| 103 | 
            -
                end
         | 
| 104 | 
            -
             | 
| 105 | 
            -
                def config_vhost_dirs
         | 
| 106 | 
            -
                  {
         | 
| 107 | 
            -
                    public_dir: File.join(app_root, vhost_public_dirname),
         | 
| 108 | 
            -
                    shared_dir: app_shared_dir.to_s,
         | 
| 109 | 
            -
                    log_dir: File.join(app_root, 'log'),
         | 
| 110 | 
            -
                    pids_dir: File.join(app_root, 'tmp', 'pids')
         | 
| 111 | 
            -
                  }
         | 
| 112 | 
            -
                end
         | 
| 113 | 
            -
             | 
| 114 | 
            -
                def local_config_file_contents
         | 
| 115 | 
            -
                  return @local_config_contents if @local_config_contents
         | 
| 116 | 
            -
                  return @local_config_conents = {} unless File.exists? local_config_file
         | 
| 117 | 
            -
                  @local_config_contents = process_config_file(local_config_file)
         | 
| 118 | 
            -
                end
         | 
| 119 | 
            -
             | 
| 120 | 
            -
                def get_secret_contents(app_config)
         | 
| 121 | 
            -
                  secrets_file_contents = {}
         | 
| 122 | 
            -
                  if File.exist? app_config[:secrets_file_path]
         | 
| 123 | 
            -
                    secrets_file_contents = process_config_file app_config[:secrets_file_path]
         | 
| 124 | 
            -
                  end
         | 
| 125 | 
            -
                  secrets_file_contents
         | 
| 126 | 
            -
                end
         | 
| 127 | 
            -
             | 
| 128 | 
            -
                def sanitize_config_files files_list
         | 
| 129 | 
            -
                  lambda do |file, _|
         | 
| 130 | 
            -
                    files_list[file] ||=  {extension: ''}
         | 
| 131 | 
            -
                    ext = files_list[file].fetch(:extension, '').strip
         | 
| 132 | 
            -
                    ext.prepend('.') unless ext.start_with?('.') || ext.empty?
         | 
| 133 | 
            -
                    files_list[file][:extension] = ext
         | 
| 134 | 
            -
                  end
         | 
| 135 | 
            -
                end
         | 
| 136 | 
            -
             | 
| 137 | 
            -
                def filtered_config
         | 
| 138 | 
            -
                  @filtered_config ||= config.except(*configuration.app_setup_blocks)
         | 
| 139 | 
            -
                end
         | 
| 140 | 
            -
             | 
| 141 | 
            -
                def use_capistrano?
         | 
| 142 | 
            -
                  app_config_defaults[:app][:use_capistrano]
         | 
| 143 | 
            -
                end
         | 
| 144 | 
            -
              end
         | 
| 145 | 
            -
            end
         |