lotusrb 0.3.1 → 0.3.2

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: 7f32830cbb663112f677e1ab3a0d5f7ca80c67a7
4
- data.tar.gz: 3f789bd21edc08f3ddfdbaca0fadce257c93074f
3
+ metadata.gz: edf2469e81abaa0dfcfc75b88937f2cda3603a08
4
+ data.tar.gz: d065bb93dde49134fa3e44a21b845cd94db37522
5
5
  SHA512:
6
- metadata.gz: ede52cb5d932e0642ceeb92fab98f94f687a8f37234f23692a0ab53041039e45006824d8982025585ea1a8d16f4a437cf4b8e82f0850b293685eec10b5eefac3
7
- data.tar.gz: 2bab5576e9b6e04a75bcfa118e8da82ab7c87a5c0657ef568492bf542f63cc83ce49a5221df0f171c432a1aafa946dda62943f8e028023024e653e59fe0f5730
6
+ metadata.gz: 5624055463ef2a3413cc8e0e04cb7aec47a040f709ad733b0d7b5a81162b2c4738fc6f0cdbc3a47d9154578b72e119702cfcc001769eeb650b6c5cbbc5cc0a1e
7
+ data.tar.gz: 4d980f03c4f83489e083c0a0a1bfc5ad92ebd1d6a3ef89af710f5f00e0c1522d523608ab2a977e73c33ecec881380f1c5ca6e56544b5e0e39fa27d49dc0911fb
data/CHANGELOG.md CHANGED
@@ -1,6 +1,19 @@
1
1
  # Lotus
2
2
  A complete web framework for Ruby
3
3
 
4
+ ## v0.3.2 - 2015-05-22
5
+ ### Added
6
+ - [Alfonso Uceda Pompa] Automatic secure cookies if the current connection is using HTTPS.
7
+ - [Alfonso Uceda Pompa] Routing helpers for actions (via `#routes`).
8
+ - [My Mai] Introduced `Lotus.root`. It returns the top level directory of the project.
9
+
10
+ ### Fixed
11
+ - [Ngọc Nguyễn] Model generator should use new RSpec syntax.
12
+ - [Ngọc Nguyễn] Model generator must respect file name conventions for Ruby.
13
+ - [Ngọc Nguyễn] Action generator must respect file name conventions for Ruby.
14
+ - [Alfonso Uceda Pompa] Action generator must raise error if name isn't provided.
15
+ - [Luca Guidi] Container generator for RSpec let the application to be preloaded (discard `config.before(:suite)`)
16
+
4
17
  ## v0.3.1 - 2015-05-15
5
18
  ### Added
6
19
  - [Hiếu Nguyễn] Introduced application generator (eg. `bundle exec lotus generate app admin` creates `apps/admin`).
@@ -0,0 +1,40 @@
1
+ require 'lotus/utils/string'
2
+
3
+ module Lotus
4
+ module Action
5
+ # Routing helper for full stack Lotus web applications.
6
+ #
7
+ # For a given application called <tt>Web::Application</tt>, at runtime
8
+ # Lotus creates a routes factory called <tt>Web::Routes</tt>.
9
+ #
10
+ # Included by default in every controller.
11
+ #
12
+ # @since 0.3.2
13
+ #
14
+ # @example Usage in controller
15
+ # require 'lotus'
16
+ #
17
+ # module Web::Controllers::Protected
18
+ # class Index
19
+ # include Web::Action
20
+ #
21
+ # def call(params)
22
+ # redirect_to routes.root_path
23
+ # end
24
+ # end
25
+ # end
26
+ module RoutingHelpers
27
+ def self.included(base)
28
+ factory = "#{ Utils::String.new(base).namespace }::Routes"
29
+
30
+ base.class_eval <<-END_EVAL, __FILE__, __LINE__
31
+ private
32
+
33
+ def routes
34
+ #{ factory }
35
+ end
36
+ END_EVAL
37
+ end
38
+ end
39
+ end
40
+ end
@@ -20,17 +20,38 @@ module Lotus
20
20
  # Prevent attackers to steal cookies via JavaScript,
21
21
  # Eg. alert(document.cookie) will fail
22
22
  #
23
- # @param enabled [TrueClass, FalseClass] enable cookies
24
- # @param options [Hash] optional cookies options
23
+ # @param options [Hash, TrueClass, FalseClass] optional cookies options
24
+ # @param configuration [Lotus::Configuration] the application configuration
25
25
  #
26
26
  # @since 0.3.0
27
27
  # @api private
28
28
  #
29
29
  # @see https://github.com/rack/rack/blob/master/lib/rack/utils.rb #set_cookie_header!
30
30
  # @see https://www.owasp.org/index.php/HttpOnly
31
- def initialize(enabled = false, options = {})
32
- @enabled = enabled
33
- @default_options = { httponly: true }.merge(options)
31
+ #
32
+ # @example Enable cookies with boolean
33
+ # module Web
34
+ # class Application < Lotus::Application
35
+ # configure do
36
+ # # ...
37
+ # cookies true
38
+ # end
39
+ # end
40
+ # end
41
+ #
42
+ # @example Enable cookies with options
43
+ # module Web
44
+ # class Application < Lotus::Application
45
+ # configure do
46
+ # # ...
47
+ # cookies max_age: 300
48
+ # end
49
+ # end
50
+ # end
51
+ def initialize(configuration, options = {})
52
+ @options = options
53
+ @default_options = { httponly: true, secure: configuration.ssl? }
54
+ @default_options.merge!(options) if options.is_a?(::Hash)
34
55
  end
35
56
 
36
57
  # Return if cookies are enabled
@@ -40,7 +61,7 @@ module Lotus
40
61
  # @since 0.3.0
41
62
  # @api private
42
63
  def enabled?
43
- !!@enabled
64
+ @options.respond_to?(:empty?) ? !@options.empty? : !!@options
44
65
  end
45
66
  end
46
67
  end
@@ -465,10 +465,9 @@ module Lotus
465
465
  # an argument, it will set the corresponding instance variable. When
466
466
  # called without, it will return the already set value, or the default.
467
467
  #
468
- # @overload cookies(value, options)
468
+ # @overload cookies(options)
469
469
  # Sets the given value with their options.
470
- # @param value [TrueClass, FalseClass]
471
- # @param options [Hash]
470
+ # @param options [Hash, TrueClass, FalseClass]
472
471
  #
473
472
  # @overload cookies
474
473
  # Gets the value.
@@ -483,7 +482,7 @@ module Lotus
483
482
  # end
484
483
  #
485
484
  # Bookshelf::Application.configuration.cookies
486
- # # => #<Lotus::Config::Cookies:0x0000000329f880 @enabled=false, @default_options={:httponly=>true}>
485
+ # # => #<Lotus::Config::Cookies:0x0000000329f880 @options={}, @default_options={:httponly=>true, :secure=>false}>
487
486
  #
488
487
  # @example Setting the value
489
488
  # require 'lotus'
@@ -491,34 +490,18 @@ module Lotus
491
490
  # module Bookshelf
492
491
  # class Application < Lotus::Application
493
492
  # configure do
494
- # cookies true, { domain: 'lotusrb.org' }
493
+ # cookies domain: 'lotusrb.org'
495
494
  # end
496
495
  # end
497
496
  # end
498
497
  #
499
498
  # Bookshelf::Application.configuration.cookies
500
- # # => #<Lotus::Config::Cookies:0x0000000329f880 @enabled=true, @default_options={:domain=>'lotusrb.org', :httponly=>true}>
501
- #
502
- # @example Setting a new value after one is set.
503
- # require 'lotus'
504
- #
505
- # module Bookshelf
506
- # class Application < Lotus::Application
507
- # configure do
508
- # cookies false
509
- # cookies true
510
- # end
511
- # end
512
- # end
513
- #
514
- # Bookshelf::Application.configuration.cookies
515
- # # => #<Lotus::Config::Cookies:0x0000000329f880 @enabled=true, @default_options={:httponly=>true}>
516
- #
517
- def cookies(value = nil, options = {})
518
- if value.nil?
519
- @cookies ||= Config::Cookies.new
499
+ # # => #<Lotus::Config::Cookies:0x0000000329f880 @options={:domain=>'lotusrb.org'}, @default_options={:domain=>'lotusrb.org', :httponly=>true, :secure=>false}>
500
+ def cookies(options = nil)
501
+ if options.nil?
502
+ @cookies ||= Config::Cookies.new(self, options)
520
503
  else
521
- @cookies = Config::Cookies.new(value, options)
504
+ @cookies = Config::Cookies.new(self, options)
522
505
  end
523
506
  end
524
507
 
@@ -27,7 +27,8 @@ module Lotus
27
27
  def initialize(command)
28
28
  super
29
29
 
30
- @controller, @action = name.split(ACTION_SEPARATOR)
30
+ @name = Utils::String.new(name).underscore
31
+ @controller, @action = @name.split(ACTION_SEPARATOR)
31
32
  @controller_name = Utils::String.new(@controller).classify
32
33
  @action_name = Utils::String.new(@action).classify
33
34
 
@@ -38,6 +39,7 @@ module Lotus
38
39
  # @api private
39
40
  def start
40
41
  assert_existing_app!
42
+ assert_action!
41
43
 
42
44
  opts = {
43
45
  app: app,
@@ -88,6 +90,14 @@ module Lotus
88
90
  end
89
91
  end
90
92
 
93
+ # @since 0.3.2
94
+ # @api private
95
+ def assert_action!
96
+ if @action.nil?
97
+ raise Lotus::Commands::Generate::Error.new("Unknown action, please add action's name with this syntax controller_name#action_name")
98
+ end
99
+ end
100
+
91
101
  # @since 0.3.0
92
102
  # @api private
93
103
  def generate_route
@@ -98,7 +108,7 @@ module Lotus
98
108
 
99
109
  # Insert at the top of the file
100
110
  cli.insert_into_file _routes_path, before: /\A(.*)/ do
101
- "get '/#{ @controller }', to: '#{ name }'\n"
111
+ "get '/#{ @controller }', to: '#{ @name }'\n"
102
112
  end
103
113
  end
104
114
 
@@ -2,6 +2,7 @@
2
2
  ENV['LOTUS_ENV'] ||= 'test'
3
3
 
4
4
  require_relative '../config/environment'
5
+ Lotus::Application.preload!
5
6
 
6
7
  Dir[__dir__ + '/support/**/*.rb'].each { |f| require f }
7
8
 
@@ -24,9 +25,6 @@ Dir[__dir__ + '/support/**/*.rb'].each { |f| require f }
24
25
  #
25
26
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
26
27
  RSpec.configure do |config|
27
- # Preload application for testing in isolation components
28
- config.before(:suite) { Lotus::Application.preload! }
29
-
30
28
  # rspec-expectations config goes here. You can use an alternate
31
29
  # assertion/expectation library such as wrong or the stdlib/minitest
32
30
  # assertions if you prefer.
@@ -1,5 +1,3 @@
1
- require 'lotus/entity'
2
-
3
1
  class <%= config[:model_name] %>
4
2
  include Lotus::Entity
5
3
  end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe <%= config[:model_name] %> do
3
+ RSpec.describe <%= config[:model_name] %> do
4
4
  # place your tests here
5
5
  end
@@ -1,5 +1,3 @@
1
- require 'lotus/repository'
2
-
3
1
  class <%= config[:model_name] %>Repository
4
2
  include Lotus::Repository
5
3
  end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe <%= config[:model_name] %>Repository do
3
+ RSpec.describe <%= config[:model_name] %>Repository do
4
4
  # place your tests here
5
5
  end
@@ -10,7 +10,7 @@ module Lotus
10
10
  def initialize(command)
11
11
  super
12
12
 
13
- @model = app_name
13
+ @model = Utils::String.new(app_name).underscore
14
14
  @model_name = Utils::String.new(@model).classify
15
15
 
16
16
  cli.class.source_root(source)
@@ -63,7 +63,9 @@ module <%= config[:classified_slice_name] %>
63
63
  # See #scheme and #ssl?
64
64
  # :httponly - Prevent JavaScript access (Boolean - true by default)
65
65
  #
66
- # cookies true, {}
66
+ # cookies true
67
+ # or
68
+ # cookies max_age: 300
67
69
 
68
70
  # Enable sessions
69
71
  # Argument: Symbol the Rack session adapter
data/lib/lotus/loader.rb CHANGED
@@ -3,9 +3,9 @@ require 'lotus/utils/kernel'
3
3
  require 'lotus/utils/string'
4
4
  require 'lotus/routes'
5
5
  require 'lotus/routing/default'
6
- require 'lotus/action/cookies'
7
6
  require 'lotus/action/session'
8
7
  require 'lotus/config/security'
8
+ require 'lotus/action/routing_helpers'
9
9
 
10
10
  module Lotus
11
11
  # Load an application
@@ -56,10 +56,12 @@ module Lotus
56
56
  })
57
57
 
58
58
  if config.cookies.enabled?
59
+ require 'lotus/action/cookies'
59
60
  prepare { include Lotus::Action::Cookies }
60
61
  cookies config.cookies.default_options
61
62
  end
62
63
  prepare { include Lotus::Action::Session } if config.sessions.enabled?
64
+ prepare { include Lotus::Action::RoutingHelpers }
63
65
 
64
66
  config.controller.__apply(self)
65
67
  end
data/lib/lotus/root.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'lotus/environment'
2
+
3
+ module Lotus
4
+ def self.root
5
+ Lotus::Environment.new.root
6
+ end
7
+ 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.1'.freeze
5
+ VERSION = '0.3.2'.freeze
6
6
  end
data/lib/lotus.rb CHANGED
@@ -10,6 +10,17 @@ require 'lotus/environment'
10
10
  #
11
11
  # @see http://lotusrb.org
12
12
  module Lotus
13
+ # Return root of the project (top level directory).
14
+ #
15
+ # @return [Pathname] root path
16
+ #
17
+ # @since 0.3.2
18
+ #
19
+ # @example
20
+ # Lotus.root # => #<Pathname:/Users/luca/Code/bookshelf>
21
+ def self.root
22
+ environment.root
23
+ end
13
24
 
14
25
  # Return the current environment
15
26
  #
@@ -22,7 +33,7 @@ module Lotus
22
33
  # @example
23
34
  # Lotus.env => "development"
24
35
  def self.env
25
- Environment.new.environment
36
+ environment.environment
26
37
  end
27
38
 
28
39
  # Check to see if specified environment(s) matches the current environment.
@@ -50,6 +61,16 @@ module Lotus
50
61
  # Lotus.env?(:development, :test) # => true
51
62
  # Lotus.env?(:production, :staging) # => false
52
63
  def self.env?(*names)
53
- Environment.new.environment?(*names)
64
+ environment.environment?(*names)
65
+ end
66
+
67
+ # Return environment
68
+ #
69
+ # @return [Lotus::Environment] environment
70
+ #
71
+ # @api private
72
+ # @since 0.3.2
73
+ def self.environment
74
+ Environment.new
54
75
  end
55
76
  end
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.1
4
+ version: 0.3.2
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-05-15 00:00:00.000000000 Z
11
+ date: 2015-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lotus-utils
@@ -192,6 +192,7 @@ files:
192
192
  - README.md
193
193
  - bin/lotus
194
194
  - lib/lotus.rb
195
+ - lib/lotus/action/routing_helpers.rb
195
196
  - lib/lotus/application.rb
196
197
  - lib/lotus/application_name.rb
197
198
  - lib/lotus/cli.rb
@@ -271,6 +272,7 @@ files:
271
272
  - lib/lotus/lotusrc.rb
272
273
  - lib/lotus/middleware.rb
273
274
  - lib/lotus/rendering_policy.rb
275
+ - lib/lotus/root.rb
274
276
  - lib/lotus/routes.rb
275
277
  - lib/lotus/routing/default.rb
276
278
  - lib/lotus/setup.rb