lotusrb 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b55d7a5c85223bdd933991a7dd042bc9319346c4
4
- data.tar.gz: 64b71e0266d64d7ffcdf65af2f7d6309432dc673
3
+ metadata.gz: 7f32830cbb663112f677e1ab3a0d5f7ca80c67a7
4
+ data.tar.gz: 3f789bd21edc08f3ddfdbaca0fadce257c93074f
5
5
  SHA512:
6
- metadata.gz: b8fbd473ccaedb272a101587f25ed494cc1a6bd43d3dbd89971baef2520293398358153dc0d5d231fe2dd8ab4f06fcf50b242990b0ae95ec48064e2cf06d52e3
7
- data.tar.gz: 2365f2e8fb616a841d670adc1d29a59fc1004dc1e05fc9039ff9da52349407aecdbf245b392c9eb0bc6e8a21a061d8262f5115948540f5b34f221b7271a45955
6
+ metadata.gz: ede52cb5d932e0642ceeb92fab98f94f687a8f37234f23692a0ab53041039e45006824d8982025585ea1a8d16f4a437cf4b8e82f0850b293685eec10b5eefac3
7
+ data.tar.gz: 2bab5576e9b6e04a75bcfa118e8da82ab7c87a5c0657ef568492bf542f63cc83ce49a5221df0f171c432a1aafa946dda62943f8e028023024e653e59fe0f5730
data/CHANGELOG.md CHANGED
@@ -1,6 +1,16 @@
1
1
  # Lotus
2
2
  A complete web framework for Ruby
3
3
 
4
+ ## v0.3.1 - 2015-05-15
5
+ ### Added
6
+ - [Hiếu Nguyễn] Introduced application generator (eg. `bundle exec lotus generate app admin` creates `apps/admin`).
7
+ - [Ngọc Nguyễn] Introduced model generator (eg. `bundle exec lotus generate model user` creates entity, repository and test files).
8
+ - [Ngọc Nguyễn] Introduced `Lotus.env`, `Lotus.env?` for current environment introspection (eg. `Lotus.env?(:test)` or `Lotus.env?(:staging, :production)`)
9
+ - [Miguel Molina] Skip view creation when an action is generated via `--skip-view` CLI arg.
10
+
11
+ ### Fixed
12
+ - [Luca Guidi] Ensure routes to be loaded for unit tests
13
+
4
14
  ## v0.3.0 - 2015-03-23
5
15
  ### Added
6
16
  - [Luca Guidi] Introduced action generator. Eg. `bundle exec lotus generate action web dashboard#index`
data/FEATURES.md CHANGED
@@ -3,6 +3,17 @@
3
3
 
4
4
  ## Features
5
5
 
6
+ ## v0.3.1 - 2015-05-15
7
+
8
+ - CLI: `lotus generate app admin` creates a new application (`apps/admin`).
9
+ - CLI: `lotus generate model user`. It generates entity, repository and related unit test files.
10
+ - `Lotus.env` and `Lotus.env?` for current environment introspection (eg. `Lotus.env?(:test)` or `Lotus.env?(:staging, :production)`)
11
+ - Allow repositories to execute raw query/commands against database
12
+ - Automatic timestamps update for entities
13
+ – Dirty Tracking for entities (via `Lotus::Entity::DirtyTracking`)
14
+ - Nested RESTful resource(s)
15
+ - String pluralization and singularization
16
+
6
17
  ## v0.3.0 - 2015-03-23
7
18
 
8
19
  - CLI: `lotus generate action web dashboard#index`. It generates an action, a view, a template, a route and related unit test files.
data/README.md CHANGED
@@ -6,13 +6,12 @@ A complete web framework for Ruby
6
6
 
7
7
  Lotus combines small yet powerful frameworks:
8
8
 
9
- * [**Lotus::Utils**](https://github.com/lotus/utils) - Ruby core extentions and class utilities
9
+ * [**Lotus::Utils**](https://github.com/lotus/utils) - Ruby core extensions and class utilities
10
10
  * [**Lotus::Router**](https://github.com/lotus/router) - Rack compatible HTTP router for Ruby
11
11
  * [**Lotus::Validations**](https://github.com/lotus/validations) - Validation mixin for Ruby objects
12
12
  * [**Lotus::Helpers**](https://github.com/lotus/helpers) - View helpers for Ruby applications
13
13
  * [**Lotus::Model**](https://github.com/lotus/model) - Persistence with entities, repositories and data mapper
14
14
  * [**Lotus::View**](https://github.com/lotus/view) - Presentation with a separation between views and templates
15
- * [**Lotus::Helpers**](https://github.com/lotus/helpers) - Presentation helpers for views
16
15
  * [**Lotus::Controller**](https://github.com/lotus/controller) - Full featured, fast and testable actions for Rack
17
16
 
18
17
  These components are designed to be used independently or together in a Lotus application.
data/lib/lotus.rb CHANGED
@@ -2,6 +2,7 @@ require 'lotus/version'
2
2
  require 'lotus/application'
3
3
  require 'lotus/container'
4
4
  require 'lotus/logger'
5
+ require 'lotus/environment'
5
6
 
6
7
  # A complete web framework for Ruby
7
8
  #
@@ -9,4 +10,46 @@ require 'lotus/logger'
9
10
  #
10
11
  # @see http://lotusrb.org
11
12
  module Lotus
13
+
14
+ # Return the current environment
15
+ #
16
+ # @return [String] the current environment
17
+ #
18
+ # @since 0.3.1
19
+ #
20
+ # @see Lotus::Environment#environment
21
+ #
22
+ # @example
23
+ # Lotus.env => "development"
24
+ def self.env
25
+ Environment.new.environment
26
+ end
27
+
28
+ # Check to see if specified environment(s) matches the current environment.
29
+ #
30
+ # If multiple names are given, it returns true, if at least one of them
31
+ # matches the current environment.
32
+ #
33
+ # @return [TrueClass,FalseClass] the result of the check
34
+ #
35
+ # @since 0.3.1
36
+ #
37
+ # @see Lotus.env
38
+ #
39
+ # @example Single name
40
+ # puts ENV['LOTUS_ENV'] # => "development"
41
+ #
42
+ # Lotus.env?(:development) # => true
43
+ # Lotus.env?('development') # => true
44
+ #
45
+ # Lotus.env?(:production) # => false
46
+ #
47
+ # @example Multiple names
48
+ # puts ENV['LOTUS_ENV'] # => "development"
49
+ #
50
+ # Lotus.env?(:development, :test) # => true
51
+ # Lotus.env?(:production, :staging) # => false
52
+ def self.env?(*names)
53
+ Environment.new.environment?(*names)
54
+ end
12
55
  end
data/lib/lotus/cli.rb CHANGED
@@ -80,7 +80,9 @@ module Lotus
80
80
  end
81
81
 
82
82
  desc 'generate', 'generates a new action'
83
- method_option :path, desc: 'applications path', type: :string, default: 'apps'
83
+ method_option :application_base_url, desc: 'application base url', type: :string
84
+ method_option :path, desc: 'applications path', type: :string, default: 'apps'
85
+ method_option :skip_view, desc: 'skip the creation of view and templates (only for action)', type: :boolean, default: false
84
86
  method_option :help, aliases: '-h', desc: 'displays the usage method'
85
87
 
86
88
  # @since 0.3.0
@@ -10,6 +10,8 @@ module Lotus
10
10
  # @since 0.3.0
11
11
  # @api private
12
12
  GENERATORS_NAMESPACE = "Lotus::Generators::%s".freeze
13
+ APP = 'app'.freeze
14
+ SLICE_TYPE = 'slice'.freeze
13
15
 
14
16
  # @since 0.3.0
15
17
  # @api private
@@ -24,16 +26,15 @@ module Lotus
24
26
  # @api private
25
27
  def initialize(type, app_name, name, env, cli)
26
28
  @cli = cli
27
- @options = env.to_options.merge(cli.options)
28
-
29
- @app_name = app_name
30
- @app = Utils::String.new(@app_name).classify
31
-
32
29
  @name = name
33
- @type = type
34
30
 
31
+ @type = sanitize_type(type)
32
+ @app_name = app_name
35
33
  @source = Pathname.new(::File.dirname(__FILE__) + "/../generators/#{ @type }/").realpath
36
34
  @target = Pathname.pwd.realpath
35
+
36
+ @app = Utils::String.new(@app_name).classify
37
+ @options = sanitize_app_name_options(app_name).merge(env.to_options.merge(cli.options))
37
38
  end
38
39
 
39
40
  # @since 0.3.0
@@ -57,6 +58,13 @@ module Lotus
57
58
  @spec_root ||= Pathname.new('spec')
58
59
  end
59
60
 
61
+ # @since 0.3.1
62
+ # @api private
63
+ def model_root
64
+ @model_root ||= Pathname.new(['lib', ::File.basename(Dir.getwd)]
65
+ .join(::File::SEPARATOR))
66
+ end
67
+
60
68
  private
61
69
  # @since 0.3.0
62
70
  # @api private
@@ -65,6 +73,21 @@ module Lotus
65
73
  class_name = Utils::String.new(@type).classify
66
74
  Utils::Class.load!(GENERATORS_NAMESPACE % class_name).new(self)
67
75
  end
76
+
77
+ # @since 0.3.1
78
+ # @api private
79
+ def sanitize_app_name_options(app_name)
80
+ {
81
+ application: app_name,
82
+ application_base_url: "/#{app_name}"
83
+ }
84
+ end
85
+
86
+ # @since 0.3.1
87
+ # @api private
88
+ def sanitize_type(type)
89
+ type == APP ? SLICE_TYPE : type
90
+ end
68
91
  end
69
92
  end
70
93
  end
@@ -180,6 +180,13 @@ module Lotus
180
180
  @environment ||= ENV[LOTUS_ENV] || ENV[RACK_ENV] || DEFAULT_ENV
181
181
  end
182
182
 
183
+ # @since 0.3.1
184
+ #
185
+ # @see Lotus.env?(name)
186
+ def environment?(*names)
187
+ names.map(&:to_s).include?(environment)
188
+ end
189
+
183
190
  # A set of Bundler groups
184
191
  #
185
192
  # @return [Array] A set of groups
@@ -48,22 +48,27 @@ module Lotus
48
48
  template_path: _template_path,
49
49
  }
50
50
 
51
+ test_type = case options[:test]
52
+ when 'rspec'
53
+ 'rspec'
54
+ else
55
+ 'minitest'
56
+ end
57
+
51
58
  templates = {
52
- 'action.rb.tt' => _action_path,
53
- 'view.rb.tt' => _view_path,
54
- 'template.tt' => _template_path
59
+ "action_spec.#{test_type}.tt" => _action_spec_path,
55
60
  }
56
61
 
57
- case options[:test]
58
- when 'rspec'
62
+ if !options[:skip_view]
59
63
  templates.merge!({
60
- 'action_spec.rspec.tt' => _action_spec_path,
61
- 'view_spec.rspec.tt' => _view_spec_path,
64
+ 'action.rb.tt' => _action_path,
65
+ 'view.rb.tt' => _view_path,
66
+ 'template.tt' => _template_path,
67
+ "view_spec.#{test_type}.tt" => _view_spec_path,
62
68
  })
63
69
  else
64
70
  templates.merge!({
65
- 'action_spec.minitest.tt' => _action_spec_path,
66
- 'view_spec.minitest.tt' => _view_spec_path,
71
+ 'action_without_view.rb.tt' => _action_path,
67
72
  })
68
73
  end
69
74
 
@@ -0,0 +1,9 @@
1
+ module <%= config[:app] %>::Controllers::<%= config[:controller] %>
2
+ class <%= config[:action] %>
3
+ include <%= config[:app] %>::Action
4
+
5
+ def call(params)
6
+ self.body = 'OK'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,77 @@
1
+ require 'lotus/generators/abstract'
2
+ require 'lotus/utils/string'
3
+
4
+ module Lotus
5
+ module Generators
6
+ class Model < Abstract
7
+
8
+ # @since 0.3.1
9
+ # @api private
10
+ def initialize(command)
11
+ super
12
+
13
+ @model = app_name
14
+ @model_name = Utils::String.new(@model).classify
15
+
16
+ cli.class.source_root(source)
17
+ end
18
+
19
+ # @since 0.3.1
20
+ # @api private
21
+ def start
22
+ opts = {
23
+ model_name: @model_name
24
+ }
25
+
26
+ templates = {
27
+ 'entity.rb.tt' => _entity_path,
28
+ 'repository.rb.tt' => _repository_path
29
+ }
30
+
31
+ case options[:test]
32
+ when 'rspec'
33
+ templates.merge!({
34
+ 'entity_spec.rspec.tt' => _entity_spec_path,
35
+ 'repository_spec.rspec.tt' => _repository_spec_path,
36
+ })
37
+ else
38
+ templates.merge!({
39
+ 'entity_spec.minitest.tt' => _entity_spec_path,
40
+ 'repository_spec.minitest.tt' => _repository_spec_path,
41
+ })
42
+ end
43
+
44
+ templates.each do |src, dst|
45
+ cli.template(source.join(src), target.join(dst), opts)
46
+ end
47
+ end
48
+
49
+ private
50
+ # @since 0.3.1
51
+ # @api private
52
+ def _entity_path
53
+ model_root.join("entities", "#{@model}.rb").to_s
54
+ end
55
+
56
+ # @since 0.3.1
57
+ # @api private
58
+ def _repository_path
59
+ model_root.join("repositories", "#{@model}_repository.rb").to_s
60
+ end
61
+
62
+ # @since 0.3.1
63
+ # @api private
64
+ def _entity_spec_path
65
+ spec_root.join(::File.basename(Dir.getwd), 'entities', "#{ @model }_spec.rb")
66
+ end
67
+
68
+ # @since 0.3.1
69
+ # @api private
70
+ def _repository_spec_path
71
+ spec_root.join(::File.basename(Dir.getwd), 'repositories',
72
+ "#{ @model }_repository_spec.rb")
73
+ end
74
+
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,5 @@
1
+ require 'lotus/entity'
2
+
3
+ class <%= config[:model_name] %>
4
+ include Lotus::Entity
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= config[:model_name] %> do
4
+ # place your tests here
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= config[:model_name] %> do
4
+ # place your tests here
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'lotus/repository'
2
+
3
+ class <%= config[:model_name] %>Repository
4
+ include Lotus::Repository
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= config[:model_name] %>Repository do
4
+ # place your tests here
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= config[:model_name] %>Repository do
4
+ # place your tests here
5
+ end
@@ -58,13 +58,13 @@ module Lotus
58
58
  #
59
59
 
60
60
  # Add "require_relative '../apps/web/application'"
61
- cli.gsub_file target.join('config/environment.rb'), /require_relative (.*)/ do |match|
62
- match << "\nrequire_relative '../apps/#{ opts[:slice_name] }/application'"
61
+ cli.inject_into_file target.join('config/environment.rb'), after: /require_relative '\.\.\/lib\/(.*)'/ do
62
+ "\nrequire_relative '../apps/#{ opts[:slice_name] }/application'"
63
63
  end
64
64
 
65
65
  # Mount slice inside "Lotus::Container.configure"
66
- cli.gsub_file target.join('config/environment.rb'), /(mount (.*)|Lotus::Container.configure do)/ do |match|
67
- match << "\n mount #{ opts[:classified_slice_name] }::Application, at: '#{ opts[:slice_base_url] }'"
66
+ cli.inject_into_file target.join('config/environment.rb'), after: /Lotus::Container.configure do/ do |match|
67
+ "\n mount #{ opts[:classified_slice_name] }::Application, at: '#{ opts[:slice_base_url] }'"
68
68
  end
69
69
 
70
70
  ##
@@ -52,8 +52,18 @@ module <%= config[:classified_slice_name] %>
52
52
  # port 443
53
53
 
54
54
  # Enable cookies
55
+ # Argument: boolean to toggle the feature
56
+ # A Hash with options
57
+ #
58
+ # Options: :domain - The domain (String - nil by default, not required)
59
+ # :path - Restrict cookies to a relative URI (String - nil by default)
60
+ # :max_age - Cookies expiration expressed in seconds (Integer - nil by default)
61
+ # :secure - Restrict cookies to secure connections
62
+ # (Boolean - Automatically set on true if currenlty using a secure connection)
63
+ # See #scheme and #ssl?
64
+ # :httponly - Prevent JavaScript access (Boolean - true by default)
55
65
  #
56
- # cookies true
66
+ # cookies true, {}
57
67
 
58
68
  # Enable sessions
59
69
  # Argument: Symbol the Rack session adapter
data/lib/lotus/loader.rb CHANGED
@@ -138,11 +138,12 @@ module Lotus
138
138
  end
139
139
 
140
140
  def load_rack!
141
+ _assign_routes_to_application_module!
142
+
141
143
  return if application.is_a?(Class)
142
144
  _assign_rendering_policy!
143
145
  _assign_rack_routes!
144
146
  _load_rack_middleware!
145
- _assign_routes_to_application_module!
146
147
  end
147
148
 
148
149
  def _assign_rendering_policy!
@@ -150,17 +151,7 @@ module Lotus
150
151
  end
151
152
 
152
153
  def _assign_rack_routes!
153
- resolver = Lotus::Routing::EndpointResolver.new(pattern: configuration.controller_pattern, namespace: namespace)
154
- default_app = Lotus::Routing::Default.new
155
- application.routes = Lotus::Router.new(
156
- parsers: configuration.body_parsers,
157
- resolver: resolver,
158
- default_app: default_app,
159
- scheme: configuration.scheme,
160
- host: configuration.host,
161
- port: configuration.port,
162
- &configuration.routes
163
- )
154
+ application.routes = application_routes
164
155
  end
165
156
 
166
157
  def _load_rack_middleware!
@@ -169,7 +160,7 @@ module Lotus
169
160
 
170
161
  def _assign_routes_to_application_module!
171
162
  unless application_module.const_defined?('Routes')
172
- routes = Lotus::Routes.new(application.routes)
163
+ routes = Lotus::Routes.new(application_routes)
173
164
  application_module.const_set('Routes', routes)
174
165
  end
175
166
  end
@@ -180,6 +171,20 @@ module Lotus
180
171
  )
181
172
  end
182
173
 
174
+ def application_routes
175
+ resolver = Lotus::Routing::EndpointResolver.new(pattern: configuration.controller_pattern, namespace: namespace)
176
+ default_app = Lotus::Routing::Default.new
177
+ Lotus::Router.new(
178
+ parsers: configuration.body_parsers,
179
+ resolver: resolver,
180
+ default_app: default_app,
181
+ scheme: configuration.scheme,
182
+ host: configuration.host,
183
+ port: configuration.port,
184
+ &configuration.routes
185
+ )
186
+ end
187
+
183
188
  def namespace
184
189
  configuration.namespace || application_module
185
190
  end
data/lib/lotus/version.rb CHANGED
@@ -2,5 +2,5 @@ module Lotus
2
2
  # Defines the version
3
3
  #
4
4
  # @since 0.1.0
5
- VERSION = '0.3.0'.freeze
5
+ VERSION = '0.3.1'.freeze
6
6
  end
data/lotusrb.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.required_ruby_version = '>= 2.0.0'
21
21
 
22
22
  spec.add_dependency 'lotus-utils', '~> 0.4'
23
- spec.add_dependency 'lotus-router', '~> 0.3'
23
+ spec.add_dependency 'lotus-router', '~> 0.4'
24
24
  spec.add_dependency 'lotus-controller', '~> 0.4'
25
25
  spec.add_dependency 'lotus-view', '~> 0.4'
26
26
  spec.add_dependency 'lotus-helpers', '~> 0.1'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lotusrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-23 00:00:00.000000000 Z
11
+ date: 2015-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lotus-utils
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.3'
33
+ version: '0.4'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.3'
40
+ version: '0.4'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: lotus-controller
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -221,6 +221,7 @@ files:
221
221
  - lib/lotus/generators/action/action.rb.tt
222
222
  - lib/lotus/generators/action/action_spec.minitest.tt
223
223
  - lib/lotus/generators/action/action_spec.rspec.tt
224
+ - lib/lotus/generators/action/action_without_view.rb.tt
224
225
  - lib/lotus/generators/action/template.tt
225
226
  - lib/lotus/generators/action/view.rb.tt
226
227
  - lib/lotus/generators/action/view_spec.minitest.tt
@@ -248,6 +249,13 @@ files:
248
249
  - lib/lotus/generators/application/container/rspec.rspec.tt
249
250
  - lib/lotus/generators/application/container/spec_helper.rb.minitest.tt
250
251
  - lib/lotus/generators/application/container/spec_helper.rb.rspec.tt
252
+ - lib/lotus/generators/model.rb
253
+ - lib/lotus/generators/model/entity.rb.tt
254
+ - lib/lotus/generators/model/entity_spec.minitest.tt
255
+ - lib/lotus/generators/model/entity_spec.rspec.tt
256
+ - lib/lotus/generators/model/repository.rb.tt
257
+ - lib/lotus/generators/model/repository_spec.minitest.tt
258
+ - lib/lotus/generators/model/repository_spec.rspec.tt
251
259
  - lib/lotus/generators/slice.rb
252
260
  - lib/lotus/generators/slice/.gitkeep.tt
253
261
  - lib/lotus/generators/slice/action.rb.tt