lotusrb 0.5.0 → 0.6.0
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/CHANGELOG.md +57 -14
- data/FEATURES.md +21 -0
- data/LICENSE.md +1 -1
- data/README.md +8 -7
- data/bin/lotus +1 -0
- data/lib/lotus.rb +6 -0
- data/lib/lotus/action/csrf_protection.rb +1 -1
- data/lib/lotus/application.rb +4 -4
- data/lib/lotus/application_name.rb +8 -6
- data/lib/lotus/cli.rb +75 -66
- data/lib/lotus/cli_sub_commands/assets.rb +29 -0
- data/lib/lotus/{commands → cli_sub_commands}/db.rb +24 -29
- data/lib/lotus/cli_sub_commands/destroy.rb +102 -0
- data/lib/lotus/cli_sub_commands/generate.rb +127 -0
- data/lib/lotus/commands/assets/precompile.rb +35 -0
- data/lib/lotus/commands/console.rb +28 -8
- data/lib/lotus/commands/db/abstract.rb +6 -2
- data/lib/lotus/commands/db/console.rb +5 -5
- data/lib/lotus/commands/generate/abstract.rb +63 -0
- data/lib/lotus/commands/generate/action.rb +262 -0
- data/lib/lotus/commands/generate/app.rb +116 -0
- data/lib/lotus/commands/generate/mailer.rb +118 -0
- data/lib/lotus/commands/generate/migration.rb +63 -0
- data/lib/lotus/commands/generate/model.rb +96 -0
- data/lib/lotus/commands/new/abstract.rb +128 -0
- data/lib/lotus/commands/new/app.rb +116 -0
- data/lib/lotus/commands/new/container.rb +102 -0
- data/lib/lotus/commands/routes.rb +19 -2
- data/lib/lotus/commands/server.rb +16 -2
- data/lib/lotus/config/framework_configuration.rb +13 -1
- data/lib/lotus/configuration.rb +24 -76
- data/lib/lotus/container.rb +15 -2
- data/lib/lotus/environment.rb +43 -4
- data/lib/lotus/frameworks.rb +1 -0
- data/lib/lotus/generators/action/action_spec.minitest.tt +1 -1
- data/lib/lotus/generators/action/action_spec.rspec.tt +1 -1
- data/lib/lotus/generators/action/view_spec.minitest.tt +1 -1
- data/lib/lotus/generators/action/view_spec.rspec.tt +1 -1
- data/lib/lotus/generators/{slice → app}/.gitkeep.tt +0 -0
- data/lib/lotus/generators/{slice → app}/application.rb.tt +61 -23
- data/lib/lotus/generators/app/config/initializers/.gitkeep +0 -0
- data/lib/lotus/generators/{slice → app}/config/routes.rb.tt +0 -0
- data/lib/lotus/generators/app/favicon.ico +0 -0
- data/lib/lotus/generators/{slice → app}/templates/application.html.erb.tt +2 -1
- data/lib/lotus/generators/app/views/application_layout.rb.tt +7 -0
- data/lib/lotus/generators/application/app/.env.development.tt +1 -0
- data/lib/lotus/generators/application/app/.env.test.tt +1 -0
- data/lib/lotus/generators/application/app/Gemfile.tt +1 -0
- data/lib/lotus/generators/application/app/Rakefile.minitest.tt +1 -0
- data/lib/lotus/generators/application/app/Rakefile.rspec.tt +1 -0
- data/lib/lotus/generators/application/app/config/application.rb.tt +56 -18
- data/lib/lotus/generators/application/app/config/initializers/.gitkeep +0 -0
- data/lib/lotus/generators/application/app/favicon.ico +0 -0
- data/lib/lotus/generators/application/app/gitignore.tt +2 -0
- data/lib/lotus/generators/application/app/lotusrc.tt +3 -3
- data/lib/lotus/generators/application/app/spec_helper.rb.rspec.tt +5 -1
- data/lib/lotus/generators/application/app/templates/application.html.erb.tt +1 -0
- data/lib/lotus/generators/application/container/.env.development.tt +1 -0
- data/lib/lotus/generators/application/container/.env.test.tt +1 -0
- data/lib/lotus/generators/application/container/Gemfile.tt +1 -1
- data/lib/lotus/generators/application/container/Rakefile.minitest.tt +1 -0
- data/lib/lotus/generators/application/container/Rakefile.rspec.tt +1 -0
- data/lib/lotus/generators/application/container/config/initializers/.gitkeep +0 -0
- data/lib/lotus/generators/application/container/gitignore.tt +2 -0
- data/lib/lotus/generators/application/container/lib/chirp/mailers/.gitkeep +0 -0
- data/lib/lotus/generators/application/container/lib/chirp/mailers/templates/.gitkeep +0 -0
- data/lib/lotus/generators/application/container/lotusrc.tt +3 -3
- data/lib/lotus/generators/application/container/spec_helper.rb.rspec.tt +5 -1
- data/lib/lotus/generators/database_config.rb +17 -4
- data/lib/lotus/generators/generatable.rb +51 -0
- data/lib/lotus/generators/generator.rb +35 -0
- data/lib/lotus/generators/test_framework.rb +42 -0
- data/lib/lotus/loader.rb +43 -0
- data/lib/lotus/lotusrc.rb +50 -49
- data/lib/lotus/middleware.rb +28 -10
- data/lib/lotus/rake_helper.rb +68 -0
- data/lib/lotus/rake_tasks.rb +2 -0
- data/lib/lotus/rendering_policy.rb +2 -2
- data/lib/lotus/repositories/car_repository.rb +3 -0
- data/lib/lotus/repositories/name_repository.rb +3 -0
- data/lib/lotus/setup.rb +1 -3
- data/lib/lotus/static.rb +77 -0
- data/lib/lotus/templates/welcome.html.erb +7 -4
- data/lib/lotus/version.rb +1 -1
- data/lib/lotus/views/default.rb +2 -1
- data/lib/lotus/views/default_template_finder.rb +4 -3
- data/lotusrb.gemspec +11 -9
- metadata +79 -60
- data/lib/lotus/commands/generate.rb +0 -97
- data/lib/lotus/commands/new.rb +0 -43
- data/lib/lotus/config/assets.rb +0 -81
- data/lib/lotus/generators/abstract.rb +0 -31
- data/lib/lotus/generators/action.rb +0 -235
- data/lib/lotus/generators/app.rb +0 -39
- data/lib/lotus/generators/app/.gitkeep +0 -1
- data/lib/lotus/generators/application/app.rb +0 -129
- data/lib/lotus/generators/application/container.rb +0 -111
- data/lib/lotus/generators/mailer.rb +0 -112
- data/lib/lotus/generators/migration.rb +0 -58
- data/lib/lotus/generators/model.rb +0 -90
- data/lib/lotus/generators/slice.rb +0 -94
- data/lib/lotus/generators/slice/views/application_layout.rb.tt +0 -7
| 
            File without changes
         | 
| 
            File without changes
         | 
| 
            File without changes
         | 
| @@ -1,3 +1,3 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
             | 
| 3 | 
            -
             | 
| 1 | 
            +
            <%= Lotus::Lotusrc::ARCHITECTURE_KEY %>=<%= Lotus::Lotusrc::DEFAULT_ARCHITECTURE %>
         | 
| 2 | 
            +
            <%= Lotus::Lotusrc::TEST_KEY %>=<%= config[:test] %>
         | 
| 3 | 
            +
            <%= Lotus::Lotusrc::TEMPLATE_KEY %>=<%= Lotus::Lotusrc::DEFAULT_TEMPLATE %>
         | 
| @@ -58,6 +58,11 @@ RSpec.configure do |config| | |
| 58 58 | 
             
              config.filter_run :focus
         | 
| 59 59 | 
             
              config.run_all_when_everything_filtered = true
         | 
| 60 60 |  | 
| 61 | 
            +
              # Allows RSpec to persist some state between runs in order to support
         | 
| 62 | 
            +
              # the `--only-failures` and `--next-failure` CLI options. We recommend
         | 
| 63 | 
            +
              # you configure your source control system to ignore this file.
         | 
| 64 | 
            +
              config.example_status_persistence_file_path = "spec/examples.txt"
         | 
| 65 | 
            +
             | 
| 61 66 | 
             
              # Limits the available syntax to the non-monkey patched syntax that is
         | 
| 62 67 | 
             
              # recommended. For more details, see:
         | 
| 63 68 | 
             
              #   - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
         | 
| @@ -97,4 +102,3 @@ RSpec.configure do |config| | |
| 97 102 | 
             
              Kernel.srand config.seed
         | 
| 98 103 | 
             
            =end
         | 
| 99 104 | 
             
            end
         | 
| 100 | 
            -
             | 
| @@ -1,6 +1,9 @@ | |
| 1 | 
            +
            require 'shellwords'
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            module Lotus
         | 
| 2 4 | 
             
              module Generators
         | 
| 3 5 | 
             
                class DatabaseConfig
         | 
| 6 | 
            +
             | 
| 4 7 | 
             
                  SUPPORTED_ENGINES = {
         | 
| 5 8 | 
             
                    'mysql'      => { type: :sql,         mri: 'mysql2',  jruby: 'jdbc-mysql'    },
         | 
| 6 9 | 
             
                    'mysql2'     => { type: :sql,         mri: 'mysql2',  jruby: 'jdbc-mysql'    },
         | 
| @@ -12,13 +15,15 @@ module Lotus | |
| 12 15 | 
             
                    'memory'     => { type: :memory,      mri: nil,       jruby: nil             }
         | 
| 13 16 | 
             
                  }.freeze
         | 
| 14 17 |  | 
| 18 | 
            +
                  DEFAULT_ENGINE = 'filesystem'.freeze
         | 
| 19 | 
            +
             | 
| 15 20 | 
             
                  attr_reader :engine, :name
         | 
| 16 21 |  | 
| 17 22 | 
             
                  def initialize(engine, name)
         | 
| 18 23 | 
             
                    @engine = engine
         | 
| 19 24 | 
             
                    @name = name
         | 
| 20 25 |  | 
| 21 | 
            -
                    SUPPORTED_ENGINES.key?(engine) or fail "\"#{ engine }\" is not a valid database type"
         | 
| 26 | 
            +
                    SUPPORTED_ENGINES.key?(engine.to_s) or fail "\"#{ engine }\" is not a valid database type"
         | 
| 22 27 | 
             
                  end
         | 
| 23 28 |  | 
| 24 29 | 
             
                  def to_hash
         | 
| @@ -37,6 +42,10 @@ module Lotus | |
| 37 42 | 
             
                    type == :sql
         | 
| 38 43 | 
             
                  end
         | 
| 39 44 |  | 
| 45 | 
            +
                  def filesystem?
         | 
| 46 | 
            +
                    type == :file_system
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
             | 
| 40 49 | 
             
                  private
         | 
| 41 50 |  | 
| 42 51 | 
             
                  def platform
         | 
| @@ -44,7 +53,7 @@ module Lotus | |
| 44 53 | 
             
                  end
         | 
| 45 54 |  | 
| 46 55 | 
             
                  def platform_prefix
         | 
| 47 | 
            -
                    : | 
| 56 | 
            +
                    'jdbc:'.freeze if Lotus::Utils.jruby?
         | 
| 48 57 | 
             
                  end
         | 
| 49 58 |  | 
| 50 59 | 
             
                  def uri
         | 
| @@ -61,7 +70,11 @@ module Lotus | |
| 61 70 | 
             
                  def base_uri
         | 
| 62 71 | 
             
                    case engine
         | 
| 63 72 | 
             
                    when 'mysql', 'mysql2'
         | 
| 64 | 
            -
                       | 
| 73 | 
            +
                      if Lotus::Utils.jruby?
         | 
| 74 | 
            +
                        "mysql://localhost/#{ name }"
         | 
| 75 | 
            +
                      else
         | 
| 76 | 
            +
                        "mysql2://localhost/#{ name }"
         | 
| 77 | 
            +
                      end
         | 
| 65 78 | 
             
                    when 'postgresql', 'postgres'
         | 
| 66 79 | 
             
                      "postgres://localhost/#{ name }"
         | 
| 67 80 | 
             
                    when 'sqlite', 'sqlite3'
         | 
| @@ -78,7 +91,7 @@ module Lotus | |
| 78 91 | 
             
                    when 'sqlite', 'sqlite3'
         | 
| 79 92 | 
             
                      "#{ platform_prefix }#{ base_uri }_#{ environment }.sqlite"
         | 
| 80 93 | 
             
                    else
         | 
| 81 | 
            -
                      "#{ platform_prefix }#{ base_uri }_#{ environment }"
         | 
| 94 | 
            +
                      "#{ platform_prefix if sql? }#{ base_uri }_#{ environment }"
         | 
| 82 95 | 
             
                    end
         | 
| 83 96 | 
             
                  end
         | 
| 84 97 | 
             
                end
         | 
| @@ -0,0 +1,51 @@ | |
| 1 | 
            +
            require 'lotus/generators/generator'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Lotus
         | 
| 4 | 
            +
              module Generators
         | 
| 5 | 
            +
                module Generatable
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                  def start
         | 
| 8 | 
            +
                    map_templates
         | 
| 9 | 
            +
                    process_templates
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  def destroy
         | 
| 13 | 
            +
                    generator.behavior = :revoke
         | 
| 14 | 
            +
                    self
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  def generator
         | 
| 18 | 
            +
                    @generator ||= Lotus::Generators::Generator.new(template_source_path, target_path)
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  def map_templates
         | 
| 22 | 
            +
                    raise NotImplementedError, "must implement the map_templates method"
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  def add_mapping(source, target)
         | 
| 26 | 
            +
                    generator.add_mapping(source, target)
         | 
| 27 | 
            +
                  end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  def process_templates
         | 
| 30 | 
            +
                    generator.process_templates(template_options)
         | 
| 31 | 
            +
                    post_process_templates
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  def post_process_templates
         | 
| 35 | 
            +
                    nil
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                  def template_options
         | 
| 39 | 
            +
                    {}
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  def template_source_path
         | 
| 43 | 
            +
                    raise NotImplementedError, "must implement the template_source_path method"
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                  def target_path
         | 
| 47 | 
            +
                    raise NotImplementedError, "must implement the target_path method"
         | 
| 48 | 
            +
                  end
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
              end
         | 
| 51 | 
            +
            end
         | 
| @@ -0,0 +1,35 @@ | |
| 1 | 
            +
            require 'thor'
         | 
| 2 | 
            +
            require 'forwardable'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module Lotus
         | 
| 5 | 
            +
              module Generators
         | 
| 6 | 
            +
                class Generator
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  extend Forwardable
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  def_delegators :@processor, :run, :behavior=, :inject_into_file, :append_to_file, :prepend_to_file
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  class Processor < Thor
         | 
| 13 | 
            +
                    include Thor::Actions
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  def initialize(template_source_path, target_path)
         | 
| 17 | 
            +
                    @template_source_path = template_source_path
         | 
| 18 | 
            +
                    @target_path = target_path
         | 
| 19 | 
            +
                    @template_mappings = []
         | 
| 20 | 
            +
                    @processor = Processor.new
         | 
| 21 | 
            +
                    @processor.class.source_root(@template_source_path)
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  def add_mapping(source, target)
         | 
| 25 | 
            +
                    @template_mappings << [source, target]
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  def process_templates(options = {})
         | 
| 29 | 
            +
                    @template_mappings.each do |src, dst|
         | 
| 30 | 
            +
                      @processor.template(@template_source_path.join(src), @target_path.join(dst), options)
         | 
| 31 | 
            +
                    end
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
            end
         | 
| @@ -0,0 +1,42 @@ | |
| 1 | 
            +
            require 'lotus/lotusrc'
         | 
| 2 | 
            +
            module Lotus
         | 
| 3 | 
            +
              module Generators
         | 
| 4 | 
            +
                class TestFramework
         | 
| 5 | 
            +
                  RSPEC = 'rspec'.freeze
         | 
| 6 | 
            +
                  MINITEST = 'minitest'.freeze
         | 
| 7 | 
            +
                  VALID_FRAMEWORKS = [RSPEC, MINITEST].freeze
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  attr_reader :framework
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  def initialize(lotusrc, framework)
         | 
| 12 | 
            +
                    @framework = (framework || lotusrc.options.fetch(:test))
         | 
| 13 | 
            +
                    assert_framework!
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  def rspec?
         | 
| 17 | 
            +
                    framework == RSPEC
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                  def minitest?
         | 
| 21 | 
            +
                    framework == MINITEST
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  private
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  def assert_framework!
         | 
| 27 | 
            +
                    if !supported_framework?
         | 
| 28 | 
            +
                      raise ArgumentError.new("Unknown test framework '#{ framework}'. Please use one of #{ valid_test_frameworks.join(', ')}")
         | 
| 29 | 
            +
                    end
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  def valid_test_frameworks
         | 
| 33 | 
            +
                    VALID_FRAMEWORKS.map { |name| "'#{ name }'"}
         | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  def supported_framework?
         | 
| 37 | 
            +
                    VALID_FRAMEWORKS.include?(framework)
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
            end
         | 
    
        data/lib/lotus/loader.rb
    CHANGED
    
    | @@ -31,6 +31,7 @@ module Lotus | |
| 31 31 | 
             
                    load_configuration_load_paths!
         | 
| 32 32 | 
             
                    load_rack!
         | 
| 33 33 | 
             
                    load_frameworks!
         | 
| 34 | 
            +
                    load_initializers!
         | 
| 34 35 | 
             
                  end
         | 
| 35 36 | 
             
                end
         | 
| 36 37 |  | 
| @@ -45,6 +46,7 @@ module Lotus | |
| 45 46 | 
             
                  _configure_model_framework! if defined?(Lotus::Model)
         | 
| 46 47 | 
             
                  _configure_controller_framework!
         | 
| 47 48 | 
             
                  _configure_view_framework!
         | 
| 49 | 
            +
                  _configure_assets_framework!
         | 
| 48 50 | 
             
                  _configure_logger!
         | 
| 49 51 | 
             
                end
         | 
| 50 52 |  | 
| @@ -97,6 +99,34 @@ module Lotus | |
| 97 99 | 
             
                  end
         | 
| 98 100 | 
             
                end
         | 
| 99 101 |  | 
| 102 | 
            +
                def _configure_assets_framework!
         | 
| 103 | 
            +
                  config = configuration
         | 
| 104 | 
            +
             | 
| 105 | 
            +
                  unless application_module.const_defined?('Assets')
         | 
| 106 | 
            +
                    assets = Lotus::Assets.duplicate(namespace) do
         | 
| 107 | 
            +
                      root             config.root
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                      scheme           config.scheme
         | 
| 110 | 
            +
                      host             config.host
         | 
| 111 | 
            +
                      port             config.port
         | 
| 112 | 
            +
             | 
| 113 | 
            +
                      public_directory Lotus.public_directory
         | 
| 114 | 
            +
                      prefix           Utils::PathPrefix.new('/assets').join(config.path_prefix)
         | 
| 115 | 
            +
             | 
| 116 | 
            +
                      manifest         Lotus.public_directory.join('assets.json')
         | 
| 117 | 
            +
                      compile          true
         | 
| 118 | 
            +
             | 
| 119 | 
            +
                      config.assets.__apply(self)
         | 
| 120 | 
            +
                    end
         | 
| 121 | 
            +
             | 
| 122 | 
            +
                    assets.configure do
         | 
| 123 | 
            +
                      cdn host != config.host
         | 
| 124 | 
            +
                    end
         | 
| 125 | 
            +
             | 
| 126 | 
            +
                    application_module.const_set('Assets', assets)
         | 
| 127 | 
            +
                  end
         | 
| 128 | 
            +
                end
         | 
| 129 | 
            +
             | 
| 100 130 | 
             
                def _configure_model_framework!
         | 
| 101 131 | 
             
                  config = configuration
         | 
| 102 132 | 
             
                  if _lotus_model_loaded? && !application_module.const_defined?('Model')
         | 
| @@ -122,6 +152,7 @@ module Lotus | |
| 122 152 |  | 
| 123 153 | 
             
                def load_frameworks!
         | 
| 124 154 | 
             
                  _load_view_framework!
         | 
| 155 | 
            +
                  _load_assets_framework!
         | 
| 125 156 | 
             
                  _load_model_framework!
         | 
| 126 157 | 
             
                end
         | 
| 127 158 |  | 
| @@ -131,6 +162,12 @@ module Lotus | |
| 131 162 | 
             
                  }
         | 
| 132 163 | 
             
                end
         | 
| 133 164 |  | 
| 165 | 
            +
                def _load_assets_framework!
         | 
| 166 | 
            +
                  application_module.module_eval %{
         | 
| 167 | 
            +
                    #{ application_module }::Assets.load!
         | 
| 168 | 
            +
                  }
         | 
| 169 | 
            +
                end
         | 
| 170 | 
            +
             | 
| 134 171 | 
             
                def _load_model_framework!
         | 
| 135 172 | 
             
                  return unless _load_model_framework?
         | 
| 136 173 |  | 
| @@ -211,5 +248,11 @@ module Lotus | |
| 211 248 | 
             
                def namespace
         | 
| 212 249 | 
             
                  configuration.namespace || application_module
         | 
| 213 250 | 
             
                end
         | 
| 251 | 
            +
             | 
| 252 | 
            +
                def load_initializers!
         | 
| 253 | 
            +
                  Dir["#{configuration.root}/config/initializers/**/*.rb"].each do |file|
         | 
| 254 | 
            +
                    require file
         | 
| 255 | 
            +
                  end
         | 
| 256 | 
            +
                end
         | 
| 214 257 | 
             
              end
         | 
| 215 258 | 
             
            end
         | 
    
        data/lib/lotus/lotusrc.rb
    CHANGED
    
    | @@ -1,8 +1,9 @@ | |
| 1 1 | 
             
            require 'pathname'
         | 
| 2 2 | 
             
            require 'dotenv/parser'
         | 
| 3 | 
            +
            require 'lotus/utils/hash'
         | 
| 3 4 |  | 
| 4 5 | 
             
            module Lotus
         | 
| 5 | 
            -
              #  | 
| 6 | 
            +
              # Read the .lotusrc file in the root of the application
         | 
| 6 7 | 
             
              #
         | 
| 7 8 | 
             
              # @since 0.3.0
         | 
| 8 9 | 
             
              # @api private
         | 
| @@ -20,15 +21,21 @@ module Lotus | |
| 20 21 | 
             
                # @since 0.3.0
         | 
| 21 22 | 
             
                # @api private
         | 
| 22 23 | 
             
                #
         | 
| 23 | 
            -
                # @see Lotus::Lotusrc# | 
| 24 | 
            +
                # @see Lotus::Lotusrc#options
         | 
| 24 25 | 
             
                DEFAULT_ARCHITECTURE = 'container'.freeze
         | 
| 25 26 |  | 
| 27 | 
            +
                # Application architecture value
         | 
| 28 | 
            +
                #
         | 
| 29 | 
            +
                # @since 0.6.0
         | 
| 30 | 
            +
                # @api private
         | 
| 31 | 
            +
                APP_ARCHITECTURE = 'app'.freeze
         | 
| 32 | 
            +
             | 
| 26 33 | 
             
                # Architecture key for writing the lotusrc file
         | 
| 27 34 | 
             
                #
         | 
| 28 35 | 
             
                # @since 0.3.0
         | 
| 29 36 | 
             
                # @api private
         | 
| 30 37 | 
             
                #
         | 
| 31 | 
            -
                # @see Lotus::Lotusrc | 
| 38 | 
            +
                # @see Lotus::Lotusrc::DEFAULT_OPTIONS
         | 
| 32 39 | 
             
                ARCHITECTURE_KEY = 'architecture'.freeze
         | 
| 33 40 |  | 
| 34 41 | 
             
                # Test suite default value
         | 
| @@ -36,7 +43,7 @@ module Lotus | |
| 36 43 | 
             
                # @since 0.3.0
         | 
| 37 44 | 
             
                # @api private
         | 
| 38 45 | 
             
                #
         | 
| 39 | 
            -
                # @see Lotus::Lotusrc | 
| 46 | 
            +
                # @see Lotus::Lotusrc::DEFAULT_OPTIONS
         | 
| 40 47 | 
             
                DEFAULT_TEST_SUITE = 'minitest'.freeze
         | 
| 41 48 |  | 
| 42 49 | 
             
                # Test suite key for writing the lotusrc file
         | 
| @@ -44,7 +51,7 @@ module Lotus | |
| 44 51 | 
             
                # @since 0.3.0
         | 
| 45 52 | 
             
                # @api private
         | 
| 46 53 | 
             
                #
         | 
| 47 | 
            -
                # @see Lotus::Lotusrc | 
| 54 | 
            +
                # @see Lotus::Lotusrc::DEFAULT_OPTIONS
         | 
| 48 55 | 
             
                TEST_KEY = 'test'.freeze
         | 
| 49 56 |  | 
| 50 57 | 
             
                # Template default value
         | 
| @@ -52,7 +59,7 @@ module Lotus | |
| 52 59 | 
             
                # @since 0.3.0
         | 
| 53 60 | 
             
                # @api private
         | 
| 54 61 | 
             
                #
         | 
| 55 | 
            -
                # @see Lotus::Lotusrc | 
| 62 | 
            +
                # @see Lotus::Lotusrc::DEFAULT_OPTIONS
         | 
| 56 63 | 
             
                DEFAULT_TEMPLATE = 'erb'.freeze
         | 
| 57 64 |  | 
| 58 65 | 
             
                # Template key for writing the lotusrc file
         | 
| @@ -60,66 +67,44 @@ module Lotus | |
| 60 67 | 
             
                # @since 0.3.0
         | 
| 61 68 | 
             
                # @api private
         | 
| 62 69 | 
             
                #
         | 
| 63 | 
            -
                # @see Lotus::Lotusrc | 
| 70 | 
            +
                # @see Lotus::Lotusrc::DEFAULT_OPTIONS
         | 
| 64 71 | 
             
                TEMPLATE_KEY = 'template'.freeze
         | 
| 65 72 |  | 
| 66 | 
            -
                #  | 
| 67 | 
            -
                # | 
| 73 | 
            +
                # Default values for writing the lotusrc file
         | 
| 74 | 
            +
                #
         | 
| 75 | 
            +
                # @since 0.5.1
         | 
| 76 | 
            +
                # @api private
         | 
| 77 | 
            +
                #
         | 
| 78 | 
            +
                # @see Lotus::Lotusrc#options
         | 
| 79 | 
            +
                DEFAULT_OPTIONS = Utils::Hash.new({
         | 
| 80 | 
            +
                  ARCHITECTURE_KEY => DEFAULT_ARCHITECTURE,
         | 
| 81 | 
            +
                  TEST_KEY         => DEFAULT_TEST_SUITE,
         | 
| 82 | 
            +
                  TEMPLATE_KEY     => DEFAULT_TEMPLATE
         | 
| 83 | 
            +
                }).symbolize!.freeze
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                # Initialize Lotusrc class with application's root and environment options.
         | 
| 68 86 | 
             
                #
         | 
| 69 87 | 
             
                # @param root [Pathname] Application's root
         | 
| 70 | 
            -
                # @param options [Hash] Environment's options
         | 
| 71 88 | 
             
                #
         | 
| 72 89 | 
             
                # @see Lotus::Environment#initialize
         | 
| 73 | 
            -
                def initialize(root | 
| 74 | 
            -
                  @root | 
| 75 | 
            -
                  @options = options
         | 
| 76 | 
            -
             | 
| 77 | 
            -
                  # NOTE this line is here in order to auto-upgrade applications generated
         | 
| 78 | 
            -
                  # with lotusrb < 0.3.0. Consider to remove it in the future.
         | 
| 79 | 
            -
                  create
         | 
| 90 | 
            +
                def initialize(root)
         | 
| 91 | 
            +
                  @root = root
         | 
| 80 92 | 
             
                end
         | 
| 81 93 |  | 
| 82 | 
            -
                # Read lotusrc file and parse it's values.
         | 
| 94 | 
            +
                # Read lotusrc file (if exists) and parse it's values or return default.
         | 
| 83 95 | 
             
                #
         | 
| 84 96 | 
             
                # @return [Lotus::Utils::Hash] parsed values
         | 
| 85 97 | 
             
                #
         | 
| 86 98 | 
             
                # @example Default values if file doesn't exist
         | 
| 87 | 
            -
                #   Lotus::Lotusrc.new(Pathname.new(Dir.pwd)). | 
| 99 | 
            +
                #   Lotus::Lotusrc.new(Pathname.new(Dir.pwd)).options
         | 
| 88 100 | 
             
                #    # => { architecture: 'container', test: 'minitest', template: 'erb' }
         | 
| 89 101 | 
             
                #
         | 
| 90 102 | 
             
                # @example Custom values if file doesn't exist
         | 
| 91 103 | 
             
                #   options = { architect: 'application', test: 'rspec', template: 'slim' }
         | 
| 92 | 
            -
                #   Lotus::Lotusrc.new(Pathname.new(Dir.pwd), options). | 
| 104 | 
            +
                #   Lotus::Lotusrc.new(Pathname.new(Dir.pwd), options).options
         | 
| 93 105 | 
             
                #    # => { architecture: 'application', test: 'rspec', template: 'slim' }
         | 
| 94 | 
            -
                def  | 
| 95 | 
            -
                   | 
| 96 | 
            -
                    Utils::Hash.new(
         | 
| 97 | 
            -
                      Dotenv::Parser.call(content)
         | 
| 98 | 
            -
                    ).symbolize!
         | 
| 99 | 
            -
                  end
         | 
| 100 | 
            -
                end
         | 
| 101 | 
            -
             | 
| 102 | 
            -
                private
         | 
| 103 | 
            -
             | 
| 104 | 
            -
                # Create lotusrc file if exists
         | 
| 105 | 
            -
                #
         | 
| 106 | 
            -
                # @since 0.3.0
         | 
| 107 | 
            -
                # @api private
         | 
| 108 | 
            -
                #
         | 
| 109 | 
            -
                # @see Lotus::Lotusrc::DEFAULT_ARCHITECTURE
         | 
| 110 | 
            -
                # @see Lotus::Lotusrc::ARCHITECTURE_KEY
         | 
| 111 | 
            -
                # @see Lotus::Lotusrc::DEFAULT_TEST_SUITE
         | 
| 112 | 
            -
                # @see Lotus::Lotusrc::TEST_KEY
         | 
| 113 | 
            -
                # @see Lotus::Lotusrc::DEFAULT_TEMPLATE
         | 
| 114 | 
            -
                # @see Lotus::Lotusrc::TEMPLATE_KEY
         | 
| 115 | 
            -
                def create
         | 
| 116 | 
            -
                  unless exists?
         | 
| 117 | 
            -
                    rcfile = File.new(path_file, "w")
         | 
| 118 | 
            -
                    rcfile.puts "#{ ARCHITECTURE_KEY }=#{ @options.fetch(:architecture, DEFAULT_ARCHITECTURE) }"
         | 
| 119 | 
            -
                    rcfile.puts "#{ TEST_KEY }=#{ @options.fetch(:test, DEFAULT_TEST_SUITE) }"
         | 
| 120 | 
            -
                    rcfile.puts "#{ TEMPLATE_KEY }=#{ @options.fetch(:template, DEFAULT_TEMPLATE) }"
         | 
| 121 | 
            -
                    rcfile.close
         | 
| 122 | 
            -
                  end
         | 
| 106 | 
            +
                def options
         | 
| 107 | 
            +
                  @options ||= symbolize(DEFAULT_OPTIONS.merge(file_options))
         | 
| 123 108 | 
             
                end
         | 
| 124 109 |  | 
| 125 110 | 
             
                # Check if lotusrc file exists
         | 
| @@ -132,6 +117,16 @@ module Lotus | |
| 132 117 | 
             
                  path_file.exist?
         | 
| 133 118 | 
             
                end
         | 
| 134 119 |  | 
| 120 | 
            +
                private
         | 
| 121 | 
            +
             | 
| 122 | 
            +
                def symbolize(hash)
         | 
| 123 | 
            +
                  Utils::Hash.new(hash).symbolize!
         | 
| 124 | 
            +
                end
         | 
| 125 | 
            +
             | 
| 126 | 
            +
                def file_options
         | 
| 127 | 
            +
                  symbolize(exists? ? Dotenv::Parser.call(content) : {})
         | 
| 128 | 
            +
                end
         | 
| 129 | 
            +
             | 
| 135 130 | 
             
                # Return the lotusrc file's path
         | 
| 136 131 | 
             
                #
         | 
| 137 132 | 
             
                # @since 0.3.0
         | 
| @@ -144,6 +139,12 @@ module Lotus | |
| 144 139 | 
             
                  @root.join FILE_NAME
         | 
| 145 140 | 
             
                end
         | 
| 146 141 |  | 
| 142 | 
            +
                # Return the content of lotusrc file
         | 
| 143 | 
            +
                #
         | 
| 144 | 
            +
                # @since 0.3.0
         | 
| 145 | 
            +
                # @api private
         | 
| 146 | 
            +
                #
         | 
| 147 | 
            +
                # @return [String] content of lotusrc file
         | 
| 147 148 | 
             
                def content
         | 
| 148 149 | 
             
                  path_file.read
         | 
| 149 150 | 
             
                end
         |