lotusrb 0.3.2 → 0.4.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 +20 -0
- data/FEATURES.md +17 -0
- data/README.md +16 -355
- data/lib/lotus.rb +0 -1
- data/lib/lotus/action/csrf_protection.rb +167 -0
- data/lib/lotus/application.rb +3 -1
- data/lib/lotus/cli.rb +14 -13
- data/lib/lotus/commands/console.rb +1 -1
- data/lib/lotus/commands/db.rb +102 -0
- data/lib/lotus/commands/db/abstract.rb +15 -0
- data/lib/lotus/commands/db/apply.rb +14 -0
- data/lib/lotus/commands/db/console.rb +1 -5
- data/lib/lotus/commands/db/create.rb +14 -0
- data/lib/lotus/commands/db/drop.rb +14 -0
- data/lib/lotus/commands/db/migrate.rb +19 -0
- data/lib/lotus/commands/db/prepare.rb +14 -0
- data/lib/lotus/commands/db/version.rb +14 -0
- data/lib/lotus/commands/generate.rb +20 -20
- data/lib/lotus/commands/new.rb +1 -0
- data/lib/lotus/commands/routes.rb +1 -2
- data/lib/lotus/configuration.rb +29 -0
- data/lib/lotus/container.rb +19 -3
- data/lib/lotus/environment.rb +62 -9
- data/lib/lotus/frameworks.rb +1 -0
- data/lib/lotus/generators/action.rb +46 -10
- 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 +2 -1
- data/lib/lotus/generators/action/view_spec.rspec.tt +2 -1
- data/lib/lotus/generators/app.rb +39 -0
- data/lib/lotus/generators/app/.gitkeep +1 -0
- data/lib/lotus/generators/application/app.rb +184 -0
- data/lib/lotus/generators/application/app/.env.development.tt +3 -0
- data/lib/lotus/generators/application/app/.env.test.tt +3 -0
- data/lib/lotus/generators/application/{container/config → app}/.env.tt +0 -0
- data/lib/lotus/generators/application/app/.gitkeep +1 -0
- data/lib/lotus/generators/application/app/Gemfile.tt +35 -0
- data/lib/lotus/generators/application/app/Rakefile.minitest.tt +10 -0
- data/lib/lotus/generators/application/app/Rakefile.rspec.tt +5 -0
- data/lib/lotus/generators/application/app/apps/.gitkeep.tt +1 -0
- data/lib/lotus/generators/application/app/capybara.rb.rspec.tt +8 -0
- data/lib/lotus/generators/application/app/config.ru.tt +3 -0
- data/lib/lotus/generators/application/app/config/application.rb.tt +227 -0
- data/lib/lotus/generators/application/app/config/environment.rb.tt +5 -0
- data/lib/lotus/generators/application/app/config/routes.rb.tt +2 -0
- data/lib/lotus/generators/application/app/db/.gitkeep +1 -0
- data/lib/lotus/generators/application/app/features_helper.rb.minitest.tt +11 -0
- data/lib/lotus/generators/application/app/features_helper.rb.rspec.tt +12 -0
- data/lib/lotus/generators/application/app/gitignore.tt +2 -0
- data/lib/lotus/generators/application/app/lib/app_name.rb.tt +47 -0
- data/lib/lotus/generators/application/app/lib/chirp/entities/.gitkeep +1 -0
- data/lib/lotus/generators/application/app/lib/chirp/repositories/.gitkeep +1 -0
- data/lib/lotus/generators/application/app/lib/config/mapping.rb.tt +7 -0
- data/lib/lotus/generators/application/app/lotusrc.tt +3 -0
- data/lib/lotus/generators/application/app/rspec.rspec.tt +2 -0
- data/lib/lotus/generators/application/app/schema.sql.tt +0 -0
- data/lib/lotus/generators/application/app/spec_helper.rb.minitest.tt +7 -0
- data/lib/lotus/generators/application/app/spec_helper.rb.rspec.tt +100 -0
- data/lib/lotus/generators/application/app/templates/application.html.erb.tt +9 -0
- data/lib/lotus/generators/application/app/views/application_layout.rb.tt +7 -0
- data/lib/lotus/generators/application/container.rb +37 -13
- data/lib/lotus/generators/application/container/{config/.env.development.tt → .env.development.tt} +0 -0
- data/lib/lotus/generators/application/container/{config/.env.test.tt → .env.test.tt} +0 -0
- data/lib/lotus/generators/application/container/.env.tt +1 -0
- data/lib/lotus/generators/application/container/lib/app_name.rb.tt +9 -0
- data/lib/lotus/generators/application/container/schema.sql.tt +0 -0
- data/lib/lotus/generators/migration.rb +58 -0
- data/lib/lotus/generators/migration/migration.rb.tt +4 -0
- data/lib/lotus/generators/model.rb +10 -7
- data/lib/lotus/generators/slice.rb +4 -12
- data/lib/lotus/generators/slice/application.rb.tt +3 -19
- data/lib/lotus/generators/slice/config/routes.rb.tt +1 -7
- data/lib/lotus/loader.rb +15 -1
- data/lib/lotus/lotusrc.rb +8 -3
- data/lib/lotus/templates/{welcome.html → welcome.html.erb} +4 -3
- data/lib/lotus/version.rb +1 -1
- data/lib/lotus/welcome.rb +20 -1
- data/lotusrb.gemspec +5 -5
- metadata +67 -18
- data/lib/lotus/generators/slice/action.rb.tt +0 -8
- data/lib/lotus/generators/slice/config/mapping.rb.tt +0 -13
- data/lib/lotus/generators/slice/templates/template.html.erb.tt +0 -2
- data/lib/lotus/generators/slice/view.rb.tt +0 -5
- data/lib/lotus/logger.rb +0 -141
@@ -0,0 +1 @@
|
|
1
|
+
#
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Require this file for feature tests
|
2
|
+
require_relative './spec_helper'
|
3
|
+
|
4
|
+
require 'capybara'
|
5
|
+
require 'capybara/rspec'
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.include RSpec::FeatureExampleGroup
|
9
|
+
|
10
|
+
config.include Capybara::DSL, feature: true
|
11
|
+
config.include Capybara::RSpecMatchers, feature: true
|
12
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'lotus/model'
|
2
|
+
Dir["#{ __dir__ }/<%= config[:app_name] %>/**/*.rb"].each { |file| require_relative file }
|
3
|
+
|
4
|
+
Lotus::Model.configure do
|
5
|
+
# Database adapter
|
6
|
+
#
|
7
|
+
# Available options:
|
8
|
+
#
|
9
|
+
# * Memory adapter
|
10
|
+
# adapter type: :memory, uri: 'memory://localhost/<%= config[:app_name] %>_development'
|
11
|
+
#
|
12
|
+
# * SQL adapter
|
13
|
+
# adapter type: :sql, uri: 'sqlite://db/<%= config[:app_name] %>_development.sqlite3'
|
14
|
+
# adapter type: :sql, uri: 'postgres://localhost/<%= config[:app_name] %>_development'
|
15
|
+
# adapter type: :sql, uri: 'mysql://localhost/<%= config[:app_name] %>_development'
|
16
|
+
#
|
17
|
+
adapter type: :<%= config[:database_config][:type] %>, uri: ENV['<%= config[:app_name].to_env_s %>_DATABASE_URL']
|
18
|
+
|
19
|
+
<%- if config[:database_config][:type] == :sql -%>
|
20
|
+
##
|
21
|
+
# Migrations
|
22
|
+
#
|
23
|
+
migrations 'db/migrations'
|
24
|
+
schema 'db/schema.sql'
|
25
|
+
|
26
|
+
<%- end -%>
|
27
|
+
##
|
28
|
+
# Database mapping
|
29
|
+
#
|
30
|
+
# Intended for specifying application wide mappings.
|
31
|
+
#
|
32
|
+
# You can specify mapping file to load with:
|
33
|
+
#
|
34
|
+
# mapping "#{__dir__}/config/mapping"
|
35
|
+
#
|
36
|
+
# Alternatively, you can use a block syntax like the following:
|
37
|
+
#
|
38
|
+
mapping do
|
39
|
+
# collection :users do
|
40
|
+
# entity User
|
41
|
+
# repository UserRepository
|
42
|
+
#
|
43
|
+
# attribute :id, Integer
|
44
|
+
# attribute :name, String
|
45
|
+
# end
|
46
|
+
end
|
47
|
+
end.load!
|
@@ -0,0 +1 @@
|
|
1
|
+
#
|
@@ -0,0 +1 @@
|
|
1
|
+
#
|
File without changes
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# Require this file for unit tests
|
2
|
+
ENV['LOTUS_ENV'] ||= 'test'
|
3
|
+
|
4
|
+
require_relative '../config/environment'
|
5
|
+
Lotus::Application.preload!
|
6
|
+
|
7
|
+
Dir[__dir__ + '/support/**/*.rb'].each { |f| require f }
|
8
|
+
|
9
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
10
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
11
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
12
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
13
|
+
# files.
|
14
|
+
#
|
15
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
16
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
17
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
18
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
19
|
+
# a separate helper file that requires the additional dependencies and performs
|
20
|
+
# the additional setup, and require it from the spec files that actually need
|
21
|
+
# it.
|
22
|
+
#
|
23
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
24
|
+
# users commonly want.
|
25
|
+
#
|
26
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
27
|
+
RSpec.configure do |config|
|
28
|
+
# rspec-expectations config goes here. You can use an alternate
|
29
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
30
|
+
# assertions if you prefer.
|
31
|
+
config.expect_with :rspec do |expectations|
|
32
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
33
|
+
# and `failure_message` of custom matchers include text for helper methods
|
34
|
+
# defined using `chain`, e.g.:
|
35
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
36
|
+
# # => "be bigger than 2 and smaller than 4"
|
37
|
+
# ...rather than:
|
38
|
+
# # => "be bigger than 2"
|
39
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
40
|
+
end
|
41
|
+
|
42
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
43
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
44
|
+
config.mock_with :rspec do |mocks|
|
45
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
46
|
+
# a real object. This is generally recommended, and will default to
|
47
|
+
# `true` in RSpec 4.
|
48
|
+
mocks.verify_partial_doubles = true
|
49
|
+
end
|
50
|
+
|
51
|
+
# The settings below are suggested to provide a good initial experience
|
52
|
+
# with RSpec, but feel free to customize to your heart's content.
|
53
|
+
=begin
|
54
|
+
# These two settings work together to allow you to limit a spec run
|
55
|
+
# to individual examples or groups you care about by tagging them with
|
56
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
57
|
+
# get run.
|
58
|
+
config.filter_run :focus
|
59
|
+
config.run_all_when_everything_filtered = true
|
60
|
+
|
61
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
62
|
+
# recommended. For more details, see:
|
63
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
64
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
65
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
66
|
+
config.disable_monkey_patching!
|
67
|
+
|
68
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
69
|
+
# be too noisy due to issues in dependencies.
|
70
|
+
config.warnings = true
|
71
|
+
|
72
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
73
|
+
# file, and it's useful to allow more verbose output when running an
|
74
|
+
# individual spec file.
|
75
|
+
if config.files_to_run.one?
|
76
|
+
# Use the documentation formatter for detailed output,
|
77
|
+
# unless a formatter has already been configured
|
78
|
+
# (e.g. via a command-line flag).
|
79
|
+
config.default_formatter = 'doc'
|
80
|
+
end
|
81
|
+
|
82
|
+
# Print the 10 slowest examples and example groups at the
|
83
|
+
# end of the spec run, to help surface which specs are running
|
84
|
+
# particularly slow.
|
85
|
+
config.profile_examples = 10
|
86
|
+
|
87
|
+
# Run specs in random order to surface order dependencies. If you find an
|
88
|
+
# order dependency and want to debug it, you can fix the order by providing
|
89
|
+
# the seed, which is printed after each run.
|
90
|
+
# --seed 1234
|
91
|
+
config.order = :random
|
92
|
+
|
93
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
94
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
95
|
+
# test failures related to randomization by passing the same `--seed` value
|
96
|
+
# as the one that triggered the failure.
|
97
|
+
Kernel.srand config.seed
|
98
|
+
=end
|
99
|
+
end
|
100
|
+
|
@@ -13,7 +13,7 @@ module Lotus
|
|
13
13
|
@lotus_head = options.fetch(:lotus_head)
|
14
14
|
@test = options[:test]
|
15
15
|
@database = options[:database]
|
16
|
-
@lotus_model_version = '~> 0.
|
16
|
+
@lotus_model_version = '~> 0.4'
|
17
17
|
|
18
18
|
cli.class.source_root(source)
|
19
19
|
end
|
@@ -30,23 +30,28 @@ module Lotus
|
|
30
30
|
}
|
31
31
|
|
32
32
|
templates = {
|
33
|
-
'lotusrc.tt'
|
34
|
-
'
|
35
|
-
'
|
36
|
-
'
|
37
|
-
'
|
38
|
-
'config
|
39
|
-
'config
|
40
|
-
'lib/app_name.rb.tt'
|
41
|
-
'lib/config/mapping.rb.tt'
|
33
|
+
'lotusrc.tt' => '.lotusrc',
|
34
|
+
'.env.tt' => '.env',
|
35
|
+
'.env.development.tt' => '.env.development',
|
36
|
+
'.env.test.tt' => '.env.test',
|
37
|
+
'Gemfile.tt' => 'Gemfile',
|
38
|
+
'config.ru.tt' => 'config.ru',
|
39
|
+
'config/environment.rb.tt' => 'config/environment.rb',
|
40
|
+
'lib/app_name.rb.tt' => "lib/#{ app_name }.rb",
|
41
|
+
'lib/config/mapping.rb.tt' => 'lib/config/mapping.rb',
|
42
42
|
}
|
43
43
|
|
44
44
|
empty_directories = [
|
45
|
-
"db",
|
46
45
|
"lib/#{ app_name }/entities",
|
47
46
|
"lib/#{ app_name }/repositories"
|
48
47
|
]
|
49
48
|
|
49
|
+
empty_directories << if sql_database?
|
50
|
+
"db/migrations"
|
51
|
+
else
|
52
|
+
"db"
|
53
|
+
end
|
54
|
+
|
50
55
|
case options[:test]
|
51
56
|
when 'rspec'
|
52
57
|
templates.merge!(
|
@@ -64,6 +69,12 @@ module Lotus
|
|
64
69
|
)
|
65
70
|
end
|
66
71
|
|
72
|
+
if sql_database?
|
73
|
+
templates.merge!(
|
74
|
+
'schema.sql.tt' => 'db/schema.sql'
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
67
78
|
empty_directories << [
|
68
79
|
"spec/#{ app_name }/entities",
|
69
80
|
"spec/#{ app_name }/repositories",
|
@@ -123,10 +134,14 @@ module Lotus
|
|
123
134
|
end
|
124
135
|
end
|
125
136
|
|
137
|
+
def sql_database?
|
138
|
+
database_type == :sql
|
139
|
+
end
|
140
|
+
|
126
141
|
def database_uri
|
127
142
|
{
|
128
|
-
development:
|
129
|
-
test:
|
143
|
+
development: database_environment_uri(:development),
|
144
|
+
test: database_environment_uri(:test)
|
130
145
|
}
|
131
146
|
end
|
132
147
|
|
@@ -146,6 +161,15 @@ module Lotus
|
|
146
161
|
"file:///db/#{app_name}"
|
147
162
|
end
|
148
163
|
end
|
164
|
+
|
165
|
+
def database_environment_uri(environment)
|
166
|
+
case @database
|
167
|
+
when 'sqlite', 'sqlite3'
|
168
|
+
"#{database_base_uri}_#{environment}.sqlite"
|
169
|
+
else
|
170
|
+
"#{database_base_uri}_#{environment}"
|
171
|
+
end
|
172
|
+
end
|
149
173
|
end
|
150
174
|
end
|
151
175
|
end
|
data/lib/lotus/generators/application/container/{config/.env.development.tt → .env.development.tt}
RENAMED
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
# Define ENV variables
|
@@ -2,6 +2,7 @@ require 'lotus/model'
|
|
2
2
|
Dir["#{ __dir__ }/<%= config[:app_name] %>/**/*.rb"].each { |file| require_relative file }
|
3
3
|
|
4
4
|
Lotus::Model.configure do
|
5
|
+
##
|
5
6
|
# Database adapter
|
6
7
|
#
|
7
8
|
# Available options:
|
@@ -16,6 +17,14 @@ Lotus::Model.configure do
|
|
16
17
|
#
|
17
18
|
adapter type: :<%= config[:database_config][:type] %>, uri: ENV['<%= config[:app_name].to_env_s %>_DATABASE_URL']
|
18
19
|
|
20
|
+
<%- if config[:database_config][:type] == :sql -%>
|
21
|
+
##
|
22
|
+
# Migrations
|
23
|
+
#
|
24
|
+
migrations 'db/migrations'
|
25
|
+
schema 'db/schema.sql'
|
26
|
+
|
27
|
+
<%- end -%>
|
19
28
|
##
|
20
29
|
# Database mapping
|
21
30
|
#
|
File without changes
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'lotus/generators/abstract'
|
2
|
+
require 'lotus/utils/string'
|
3
|
+
|
4
|
+
module Lotus
|
5
|
+
module Generators
|
6
|
+
# @since 0.4.0
|
7
|
+
# @api private
|
8
|
+
class Migration < Abstract
|
9
|
+
# @since 0.4.0
|
10
|
+
# @api private
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# 20150612160502
|
14
|
+
TIMESTAMP_FORMAT = '%Y%m%d%H%M%S'.freeze
|
15
|
+
|
16
|
+
# @since 0.4.0
|
17
|
+
# @api private
|
18
|
+
#
|
19
|
+
# @example
|
20
|
+
# 20150612160502_create_books.rb
|
21
|
+
FILENAME = '%{timestamp}_%{name}.rb'.freeze
|
22
|
+
|
23
|
+
# @since 0.4.0
|
24
|
+
# @api private
|
25
|
+
def initialize(command)
|
26
|
+
super
|
27
|
+
|
28
|
+
timestamp = Time.now.utc.strftime(TIMESTAMP_FORMAT)
|
29
|
+
filename = FILENAME % { timestamp: timestamp, name: name }
|
30
|
+
|
31
|
+
env.require_application_environment
|
32
|
+
@destination = Lotus::Model.configuration.migrations.join(filename)
|
33
|
+
|
34
|
+
cli.class.source_root(source)
|
35
|
+
end
|
36
|
+
|
37
|
+
# @since 0.4.0
|
38
|
+
# @api private
|
39
|
+
def start
|
40
|
+
templates = {
|
41
|
+
'migration.rb.tt' => @destination
|
42
|
+
}
|
43
|
+
|
44
|
+
templates.each do |src, dst|
|
45
|
+
cli.template(source.join(src), target.join(dst), {})
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
# @since 0.4.0
|
52
|
+
# @api private
|
53
|
+
def name
|
54
|
+
Utils::String.new(app_name || super).underscore
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -10,9 +10,7 @@ module Lotus
|
|
10
10
|
def initialize(command)
|
11
11
|
super
|
12
12
|
|
13
|
-
@
|
14
|
-
@model_name = Utils::String.new(@model).classify
|
15
|
-
|
13
|
+
@model_name = Utils::String.new(name).classify
|
16
14
|
cli.class.source_root(source)
|
17
15
|
end
|
18
16
|
|
@@ -50,28 +48,33 @@ module Lotus
|
|
50
48
|
# @since 0.3.1
|
51
49
|
# @api private
|
52
50
|
def _entity_path
|
53
|
-
model_root.join("entities", "#{
|
51
|
+
model_root.join("entities", "#{ name }.rb").to_s
|
54
52
|
end
|
55
53
|
|
56
54
|
# @since 0.3.1
|
57
55
|
# @api private
|
58
56
|
def _repository_path
|
59
|
-
model_root.join("repositories", "#{
|
57
|
+
model_root.join("repositories", "#{ name }_repository.rb").to_s
|
60
58
|
end
|
61
59
|
|
62
60
|
# @since 0.3.1
|
63
61
|
# @api private
|
64
62
|
def _entity_spec_path
|
65
|
-
spec_root.join(::File.basename(Dir.getwd), 'entities', "#{
|
63
|
+
spec_root.join(::File.basename(Dir.getwd), 'entities', "#{ name }_spec.rb")
|
66
64
|
end
|
67
65
|
|
68
66
|
# @since 0.3.1
|
69
67
|
# @api private
|
70
68
|
def _repository_spec_path
|
71
69
|
spec_root.join(::File.basename(Dir.getwd), 'repositories',
|
72
|
-
"#{
|
70
|
+
"#{ name }_repository_spec.rb")
|
73
71
|
end
|
74
72
|
|
73
|
+
# @since 0.4.0
|
74
|
+
# @api private
|
75
|
+
def name
|
76
|
+
Utils::String.new(app_name || super).underscore
|
77
|
+
end
|
75
78
|
end
|
76
79
|
end
|
77
80
|
end
|