eucalypt 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (21) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/lib/eucalypt/eucalypt-blog/namespaces/blog/cli/blog.rb +2 -2
  4. data/lib/eucalypt/eucalypt-blog/namespaces/blog-article/cli/article.rb +6 -6
  5. data/lib/eucalypt/eucalypt-core/cli/init.rb +7 -7
  6. data/lib/eucalypt/eucalypt-core/cli/launch.rb +5 -5
  7. data/lib/eucalypt/eucalypt-core/cli/test.rb +1 -1
  8. data/lib/eucalypt/eucalypt-core/templates/eucalypt/config/logging.rb +15 -13
  9. data/lib/eucalypt/eucalypt-core/templates/eucalypt/spec/spec_helper.rb +1 -1
  10. data/lib/eucalypt/eucalypt-generate/namespaces/generate/cli/generate-scaffold.rb +6 -2
  11. data/lib/eucalypt/eucalypt-generate/namespaces/generate-controller/cli/generate-controller.rb +2 -1
  12. data/lib/eucalypt/eucalypt-generate/namespaces/generate-controller/generators/controller.rb +3 -2
  13. data/lib/eucalypt/eucalypt-generate/namespaces/generate-controller/templates/controller/policy_rest_controller.tt +15 -8
  14. data/lib/eucalypt/eucalypt-security/namespaces/security-policy/cli/security-policy.rb +3 -2
  15. data/lib/eucalypt/eucalypt-security/namespaces/security-policy/generators/policy.rb +2 -2
  16. data/lib/eucalypt/eucalypt-security/namespaces/security-policy/templates/policy.tt +1 -1
  17. data/lib/eucalypt/eucalypt-security/namespaces/security-pundit/templates/pundit.tt +7 -0
  18. data/lib/eucalypt/eucalypt-security/namespaces/security-warden/templates/auth_controller.tt +2 -2
  19. data/lib/eucalypt/eucalypt-security/namespaces/security-warden/templates/warden.tt +6 -0
  20. data/lib/eucalypt/version.rb +1 -1
  21. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5fe72a6f8a63096db282ff0c7eebbd6719860893cd6dd99eb4c91a3d7cc163de
4
- data.tar.gz: 31c406116e711ebb9b5a94deaaaa909a560fa58cb78146ca1f4781205c5f669b
3
+ metadata.gz: e520c9680993730a49c3ec87c04f358ea17607420dce59d11b03dbcfb34c67a0
4
+ data.tar.gz: d20522c6f917515fe8762a6cdb72608d886fb7a0b1d8913f54b16f07da07d91a
5
5
  SHA512:
6
- metadata.gz: c1540c989e1c0774ef637782e65b433f3ee9d66ba9d6c350da7ffa98bfcd05046d1cf32a2c91ac6f7567ba82daa639866116e6239b7b5344225a542c09cf974b
7
- data.tar.gz: 042fd7143d19081383fd014f2f55504f01d37e404e08f797abf3830da606a878d531ea160ac98d0f32ffe394613894345b1f1174399ad422e3a482c3ccfd18ee
6
+ metadata.gz: 4f68cde88435a9368929ab30006c9248c131fc276286cfd42068b6dc52632feb8b952fefce41da41167c76b1c3c6b545968eb13bf5012c9adb32340d69428e6f
7
+ data.tar.gz: af70583560eadded293d15c7cea6f390d75494709d4ece3e6cb57232677eb34a2e7aa634202772c65c18e8cb3057ba253fc643913876bdee8384d590829e6ec1
data/README.md CHANGED
@@ -30,9 +30,9 @@ $ eucalypt init my-new-app
30
30
 
31
31
  Move into your new application's directory and run the top-level `eucalypt` command to display a list of all available commands.
32
32
 
33
- ## Documentation and help
33
+ ## Documentation
34
34
 
35
- The full documentation can be found [here](https://eucalypt.gitbook.io/eucalypt).
35
+ The full documentation of the CLI and micro-framework can be found [here](https://eucalypt.gitbook.io/eucalypt).
36
36
 
37
37
  ## Features
38
38
 
@@ -11,8 +11,8 @@ module Eucalypt
11
11
  include Eucalypt::Helpers::Gemfile
12
12
  using Colorize
13
13
 
14
- method_option :route, type: :string, aliases: '-r', default: 'blog', desc: "The route at which the blog lies"
15
- desc "setup", "Sets up the blog-aware environment".colorize(:grey)
14
+ option :route, type: :string, aliases: '-r', default: 'blog', desc: "The route at which the blog lies"
15
+ desc "setup", "Sets up the blog environment".colorize(:grey)
16
16
  def setup
17
17
  directory = File.expand_path('.')
18
18
  if Eucalypt.app? directory
@@ -13,12 +13,12 @@ module Eucalypt
13
13
  include Eucalypt::Blog::Helpers
14
14
  using Colorize
15
15
 
16
- method_option :descending, type: :boolean, aliases: '-d', default: true, desc: 'Descending chronological order'
17
- method_option :ascending, type: :boolean, aliases: '-a', default: false, desc: 'Ascending chronological order'
18
- method_option :tag, type: :string, aliases: '-t', default: String.new, desc: 'Search by blog article tag'
19
- method_option :year, type: :string, aliases: '-Y', desc: 'Search articles by year'
20
- method_option :month, type: :string, aliases: '-M', desc: 'Search articles by month'
21
- method_option :day, type: :string, aliases: '-D', desc: 'Search articles by day'
16
+ option :descending, type: :boolean, aliases: '-d', default: true, desc: 'Descending chronological order'
17
+ option :ascending, type: :boolean, aliases: '-a', default: false, desc: 'Ascending chronological order'
18
+ option :tag, type: :string, aliases: '-t', default: String.new, desc: 'Search by blog article tag'
19
+ option :year, type: :string, aliases: '-Y', desc: 'Search articles by year'
20
+ option :month, type: :string, aliases: '-M', desc: 'Search articles by month'
21
+ option :day, type: :string, aliases: '-D', desc: 'Search articles by day'
22
22
  desc "list", "Display the metadata of blog articles".colorize(:grey)
23
23
  def list
24
24
  directory = File.expand_path('.')
@@ -5,13 +5,13 @@ module Eucalypt
5
5
  include Eucalypt::Helpers::Messages
6
6
  using String::Builder
7
7
  using Colorize
8
- method_option :git, type: :boolean, default: true, desc: 'Initialize a Git repository'
9
- method_option :bundle, type: :boolean, default: true, desc: 'Install gems after application generation'
10
- method_option :blog, type: :boolean, default: false, aliases: '-b', desc: 'Set up the blog environment'
11
- method_option :route, type: :string, default: 'blog', aliases: '-r', desc: 'Specify a route for the blog application'
12
- method_option :silence, type: :boolean, default: false, aliases: '-s', desc: 'Silence `git init` and `bundle install` commands'
13
- method_option :warden, type: :boolean, default: false, aliases: '-w', desc: 'Set up Warden authentication'
14
- method_option :pundit, type: :boolean, default: false, aliases: '-p', desc: 'Set up Pundit authorization'
8
+ option :git, type: :boolean, default: true, desc: 'Initialize a Git repository'
9
+ option :bundle, type: :boolean, default: true, desc: 'Install gems after application generation'
10
+ option :blog, type: :boolean, default: false, aliases: '-b', desc: 'Set up the blog environment'
11
+ option :route, type: :string, default: 'blog', aliases: '-r', desc: 'Specify a route for the blog application'
12
+ option :silence, type: :boolean, default: false, aliases: '-s', desc: 'Silence `git init` and `bundle install` commands'
13
+ option :warden, type: :boolean, default: false, aliases: '-w', desc: 'Set up Warden authentication'
14
+ option :pundit, type: :boolean, default: false, aliases: '-p', desc: 'Set up Pundit authorization'
15
15
  desc "init [NAME]", "Sets up your application".colorize(:grey)
16
16
  def init(name)
17
17
  current_directory = File.expand_path ?.
@@ -3,11 +3,11 @@ module Eucalypt
3
3
  class CLI < Thor
4
4
  using Colorize
5
5
  include Eucalypt::Helpers::Messages
6
- method_option :port, type: :numeric, aliases: '-p', desc: 'Port to serve the application on'
7
- method_option :rerun, type: :boolean, aliases: '-r', desc: 'Rerun (watch for file changes and restart server)'
8
- method_option :quiet, type: :boolean, aliases: '-q', desc: 'Silences rerun (runs less verbosely)'
6
+ option :port, type: :numeric, aliases: '-p', desc: 'Port to serve the application on'
7
+ option :rerun, type: :boolean, aliases: '-r', desc: 'Rerun (watch for file changes and restart server)'
8
+ option :quiet, type: :boolean, aliases: '-q', desc: 'Silences rerun (runs less verbosely)'
9
9
  desc "launch [ENV]", "Launches your application".colorize(:grey)
10
- def launch(env = ENV['RACK_ENV']||'development')
10
+ def launch(env = ENV['APP_ENV']||'development')
11
11
  directory = File.expand_path('.')
12
12
  if Eucalypt.app? directory
13
13
  unless %w[p production d development t test].include? env
@@ -26,7 +26,7 @@ module Eucalypt
26
26
 
27
27
  puts "Running command: #{cmd.colorize(:bold)}"
28
28
  puts "Rack environment: #{env.colorize(:bold)}"
29
- exec "env RACK_ENV=#{env} #{cmd}"
29
+ exec "env APP_ENV=#{env} #{cmd}"
30
30
  else
31
31
  Eucalypt::Error.wrong_directory
32
32
  end
@@ -2,7 +2,7 @@ require_relative '__base__'
2
2
  module Eucalypt
3
3
  class CLI < Thor
4
4
  using Colorize
5
- method_option :summarized, type: :boolean, default: false, aliases: '-s', desc: 'rspec -fd spec'
5
+ option :summarized, type: :boolean, default: false, aliases: '-s', desc: 'rspec -fd spec'
6
6
  desc "test", "Run all application tests".colorize(:grey)
7
7
  def test
8
8
  directory = File.expand_path('.')
@@ -1,22 +1,24 @@
1
1
  class ApplicationController < Sinatra::Base
2
2
  set :logger, Lumberjack::Logger.new
3
3
 
4
- configure :production do
5
- require 'fileutils'
6
- use Rack::CommonLogger, $stdout
4
+ require 'fileutils'
5
+ %i[production test].each do |environment|
6
+ configure environment do
7
+ use Rack::CommonLogger, $stdout
7
8
 
8
- log_path = Eucalypt.path 'log', Time.now.strftime("%Y-%m-%dT%H-%M-%S_%z").sub(/_\+/, ?p).sub(/_\-/, ?m)
9
- FileUtils.mkdir_p log_path
9
+ log_path = Eucalypt.path 'log', Time.now.strftime("%Y-%m-%dT%H-%M-%S_%z").sub(/_\+/, ?p).sub(/_\-/, ?m)
10
+ FileUtils.mkdir_p log_path
10
11
 
11
- # STDERR logger
12
- stderr_log = File.new File.join(log_path, 'stderr.log'), 'a+'
13
- $stderr.reopen stderr_log
14
- $stderr.sync = true
12
+ # STDERR logger
13
+ stderr_log = File.new File.join(log_path, "#{settings.environment}.stderr.log"), 'a+'
14
+ $stderr.reopen stderr_log
15
+ $stderr.sync = true
15
16
 
16
- # STDOUT logger
17
- stdout_log = File.new File.join(log_path, 'stdout.log'), 'a+'
18
- $stdout.reopen stdout_log
19
- $stdout.sync = true
17
+ # STDOUT logger
18
+ stdout_log = File.new File.join(log_path, "#{settings.environment}.stdout.log"), 'a+'
19
+ $stdout.reopen stdout_log
20
+ $stdout.sync = true
21
+ end
20
22
  end
21
23
 
22
24
  helpers do
@@ -1,7 +1,7 @@
1
1
  require './app'
2
2
  Bundler.require :test
3
3
 
4
- ENV['RACK_ENV'] = 'test'
4
+ ENV['APP_ENV'] = 'test'
5
5
 
6
6
  Shoulda::Matchers.configure do |config|
7
7
  config.integrate do |with|
@@ -10,6 +10,7 @@ module Eucalypt
10
10
  option :no, aliases: '-n', type: :array, default: [], enum: %w[m ms c cs h hs], desc: "Omit specified scaffold files"
11
11
  option :rest, aliases: '-r', type: :boolean, default: false, desc: "Generate REST routes for the controller"
12
12
  option :policy, aliases: '-p', type: :boolean, default: false, desc: "Generate a policy with the scaffold"
13
+ option :headless, type: :boolean, aliases: '-H', default: false, desc: "Policy with no associated model"
13
14
  option :table, type: :boolean, default: true, desc: "Generate a table migration"
14
15
  desc "scaffold [NAME] *[COLUMN∶TYPE]", "Generates a scaffold".colorize(:grey)
15
16
  def scaffold(name, *columns)
@@ -40,17 +41,20 @@ module Eucalypt
40
41
  controller = Eucalypt::Generators::Controller.new
41
42
  controller.destination_root = directory
42
43
  policy = options[:rest] && options[:policy]
44
+ headless = options[:policy] && options[:headless]
43
45
  controller.generate(
44
46
  name: name,
45
47
  spec: controller_spec,
46
48
  rest: options[:rest],
47
- policy: policy
49
+ policy: policy,
50
+ headless: headless
48
51
  )
49
52
  end
50
53
 
51
54
  if options[:policy]
52
55
  args = ['security', 'policy', 'generate', name]
53
- args << %w[-p create edit delete] if options[:rest]
56
+ args << '--headless' if options[:headless]
57
+ args << %w[-p add edit delete] if options[:rest]
54
58
  args.flatten!
55
59
  Eucalypt::CLI.start(args)
56
60
  end
@@ -19,7 +19,8 @@ module Eucalypt
19
19
  name: name,
20
20
  spec: options[:spec],
21
21
  rest: options[:rest],
22
- policy: false
22
+ policy: false,
23
+ headless: false
23
24
  )
24
25
  else
25
26
  Eucalypt::Error.wrong_directory
@@ -14,7 +14,7 @@ module Eucalypt
14
14
  File.join File.dirname(__dir__), 'templates'
15
15
  end
16
16
 
17
- def generate(spec: true, rest: false, policy: false, name:)
17
+ def generate(spec: true, rest: false, policy: false, headless: false, name:)
18
18
  controller = Inflect.new(:controller, name)
19
19
 
20
20
  route = '/' << (rest ? controller.route_name.pluralize : controller.route_name)
@@ -34,7 +34,8 @@ module Eucalypt
34
34
  class_name: controller.class_name,
35
35
  helper_class_name: helper.class_name,
36
36
  resource: controller.resource,
37
- resources: controller.resources
37
+ resources: controller.resources,
38
+ headless: headless
38
39
  }
39
40
 
40
41
  template(controller_template, controller.file_path, config)
@@ -1,17 +1,24 @@
1
1
  class <%= config[:class_name] %> < Eucalypt::Controller(route: '<%= config[:route] %>')
2
2
  helpers <%= config[:helper_class_name] %> if defined? <%= config[:helper_class_name] %>
3
3
 
4
- # You can use the `current_user` helper provided by Warden in your views.
4
+ # You can use the following authentication helper methods in your views:
5
+ # `current_user` - The User model object for the current user.
6
+ # `authenticated?` (alias `logged_in?`) - Whether or not a user is logged in.
5
7
 
6
- # You can also use authorization helpers provided by Pundit in your views.
8
+ # You can also use authorization helpers in your views.
7
9
  # These are useful for conditional displays to users with the correct permissions.
8
10
  # - e.g. Showing a form for editing <%= config[:resources] %>
9
-
10
- # Pundit authorization helpers are used in the following way:
11
- # - `policy(<%= config[:constant] %>).add?`
12
- # - `policy(<%= config[:constant] %>).edit?`
13
- # - `policy(<%= config[:constant] %>).delete?`
14
-
11
+ <% if config[:headless] %>
12
+ # Authorization helpers are used in the following way (if using headless policies):
13
+ # - `authorized?(:<%= config[:resource] %>, :add?)`
14
+ # - `authorized?(:<%= config[:resource] %>, :edit?)`
15
+ # - `authorized?(:<%= config[:resource] %>, :delete?)`
16
+ <% else %>
17
+ # Authorization helpers are used in the following way:
18
+ # - `authorized?(<%= config[:constant] %>, :add?)`
19
+ # - `authorized?(<%= config[:constant] %>, :edit?)`
20
+ # - `authorized?(<%= config[:constant] %>, :delete?)`
21
+ <% end %>
15
22
  # GET - Browse
16
23
  get '/' do
17
24
  @<%= config[:resources] %> = <%= config[:constant] %>.all
@@ -11,7 +11,8 @@ module Eucalypt
11
11
  include Eucalypt::Helpers
12
12
  using Colorize
13
13
 
14
- method_option :permissions, type: :array, aliases: '-p', default: [], desc: "Permissions to generate along with the policy"
14
+ option :headless, type: :boolean, aliases: '-H', default: false, desc: "Policy with no associated model"
15
+ option :permissions, type: :array, aliases: '-p', default: [], desc: "Permissions to generate along with the policy"
15
16
  desc "generate [NAME]", "Create a new Pundit policy".colorize(:grey)
16
17
  def generate(name)
17
18
  directory = File.expand_path('.')
@@ -37,7 +38,7 @@ module Eucalypt
37
38
  policy_generator.destination_root = directory
38
39
 
39
40
  # Generate policy file
40
- policy_generator.generate(name: name)
41
+ policy_generator.generate(headless: options[:headless], name: name)
41
42
 
42
43
  # Create policy roles table
43
44
  policy_generator.generate_policy_roles_migration(policy: policy.resource)
@@ -13,9 +13,9 @@ module Eucalypt
13
13
  File.join File.dirname(__dir__), 'templates'
14
14
  end
15
15
 
16
- def generate(name:)
16
+ def generate(headless:, name:)
17
17
  policy = Inflect.new(:policy, name)
18
- config = {class_name: policy.class_name, resource: policy.resource, constant: policy.constant}
18
+ config = {class_name: policy.class_name, resource: policy.resource, constant: policy.constant, headless: headless}
19
19
  template('policy.tt', policy.file_path, config)
20
20
  end
21
21
 
@@ -1,4 +1,4 @@
1
- class <%= config[:class_name] %>
1
+ class <%= config[:class_name] %><%= " < Struct.new(:user, :#{config[:resource]})" if config[:headless] %>
2
2
  attr_reader :user, :<%= config[:resource] %>
3
3
 
4
4
  def initialize(user, <%= config[:resource] %>)
@@ -1,4 +1,11 @@
1
1
  class ApplicationController < Sinatra::Base
2
2
  # Include Pundit for authorization
3
3
  include Pundit
4
+
5
+ helpers do
6
+ def authorized?(policy, permission)
7
+ return false unless authenticated?
8
+ policy(policy).send permission
9
+ end
10
+ end
4
11
  end
@@ -2,12 +2,12 @@ class AuthenticationController < Eucalypt::Controller(route: '/auth')
2
2
  helpers AuthenticationHelper if defined? AuthenticationHelper
3
3
 
4
4
  get '/login' do
5
- redirect '/' if current_user
5
+ redirect '/' if authenticated?
6
6
  erb :'authentication/login', layout: false
7
7
  end
8
8
 
9
9
  post '/login' do
10
- redirect '/' if current_user
10
+ redirect '/' if authenticated?
11
11
  authenticate
12
12
  redirect session[:return_to] || '/'
13
13
  end
@@ -28,8 +28,14 @@ class ApplicationController < Sinatra::Base
28
28
  env['warden'].user
29
29
  end
30
30
 
31
+ def authenticated?
32
+ !!current_user
33
+ end
34
+
31
35
  def authenticate
32
36
  env['warden'].authenticate!
33
37
  end
38
+
39
+ alias_method :logged_in?, :authenticated?
34
40
  end
35
41
  end
@@ -1,3 +1,3 @@
1
1
  module Eucalypt
2
- VERSION = '0.1.3'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eucalypt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edwin Onuonga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-21 00:00:00.000000000 Z
11
+ date: 2018-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler