eucalypt 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +26 -0
- data/Rakefile +2 -0
- data/bin/eucalypt +3 -0
- data/eucalypt.gemspec +39 -0
- data/lib/eucalypt/app.rb +6 -0
- data/lib/eucalypt/controller.rb +10 -0
- data/lib/eucalypt/errors.rb +109 -0
- data/lib/eucalypt/eucalypt-blog/helpers.rb +106 -0
- data/lib/eucalypt/eucalypt-blog/namespaces/blog/__base__.rb +22 -0
- data/lib/eucalypt/eucalypt-blog/namespaces/blog/__require__.rb +1 -0
- data/lib/eucalypt/eucalypt-blog/namespaces/blog/cli/blog.rb +65 -0
- data/lib/eucalypt/eucalypt-blog/namespaces/blog/generators/article.rb +28 -0
- data/lib/eucalypt/eucalypt-blog/namespaces/blog/generators/controller.rb +14 -0
- data/lib/eucalypt/eucalypt-blog/namespaces/blog/generators/helper.rb +12 -0
- data/lib/eucalypt/eucalypt-blog/namespaces/blog/generators/list.rb +74 -0
- data/lib/eucalypt/eucalypt-blog/namespaces/blog/generators/views.rb +20 -0
- data/lib/eucalypt/eucalypt-blog/namespaces/blog/templates/controller/controller.tt +33 -0
- data/lib/eucalypt/eucalypt-blog/namespaces/blog/templates/controller/controller_spec.tt +43 -0
- data/lib/eucalypt/eucalypt-blog/namespaces/blog/templates/helper/helper.tt +5 -0
- data/lib/eucalypt/eucalypt-blog/namespaces/blog/templates/helper/helper_spec.tt +9 -0
- data/lib/eucalypt/eucalypt-blog/namespaces/blog/templates/views/article.erb +1 -0
- data/lib/eucalypt/eucalypt-blog/namespaces/blog/templates/views/article_layout.erb +10 -0
- data/lib/eucalypt/eucalypt-blog/namespaces/blog/templates/views/article_md.tt +9 -0
- data/lib/eucalypt/eucalypt-blog/namespaces/blog/templates/views/articles.erb +1 -0
- data/lib/eucalypt/eucalypt-blog/namespaces/blog/templates/views/articles_layout.erb +10 -0
- data/lib/eucalypt/eucalypt-blog/namespaces/blog/templates/views/search.erb +1 -0
- data/lib/eucalypt/eucalypt-blog/namespaces/blog-article/cli/article.rb +120 -0
- data/lib/eucalypt/eucalypt-blog/namespaces/blog-article-edit/cli/edit-datetime.rb +113 -0
- data/lib/eucalypt/eucalypt-blog/namespaces/blog-article-edit/cli/edit-urltitle.rb +75 -0
- data/lib/eucalypt/eucalypt-core/cli/__base__.rb +11 -0
- data/lib/eucalypt/eucalypt-core/cli/console.rb +15 -0
- data/lib/eucalypt/eucalypt-core/cli/core.rb +6 -0
- data/lib/eucalypt/eucalypt-core/cli/help.rb +11 -0
- data/lib/eucalypt/eucalypt-core/cli/init.rb +71 -0
- data/lib/eucalypt/eucalypt-core/cli/launch.rb +33 -0
- data/lib/eucalypt/eucalypt-core/cli/test.rb +16 -0
- data/lib/eucalypt/eucalypt-core/cli/version.rb +11 -0
- data/lib/eucalypt/eucalypt-core/templates/Gemfile.tt +35 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/.gitignore +48 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/.travis.yml +8 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/Procfile +1 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/Rakefile +7 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/assets/fonts/.empty_directory +0 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/assets/images/.empty_directory +0 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/assets/scripts/application.js +17 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/assets/stylesheets/__partials__.scss +16 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/assets/stylesheets/application.scss +17 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/assets/stylesheets/partials/_mixins.scss +54 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/controllers/application_controller.rb +7 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/helpers/application_helper.rb +3 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/models/.empty_directory +0 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/static/.empty_directory +0 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/static/readme.yml +34 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/views/index.erb +0 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/views/layouts/main.erb +9 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/views/partials/.empty_directory +0 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/app.rb +42 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/config/active_record.rb +6 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/config/asset_pipeline.rb +15 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/config/database.yml +16 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/config/initializers/.empty_directory +0 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/config/logging.rb +27 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/config/manifest.rb +15 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/config.ru +10 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/log/.empty_directory +0 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/spec/controllers/application_controller_spec.rb +9 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/spec/helpers/application_helper_spec.rb +9 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/spec/models/.empty_directory +0 -0
- data/lib/eucalypt/eucalypt-core/templates/eucalypt/spec/spec_helper.rb +18 -0
- data/lib/eucalypt/eucalypt-destroy/helpers.rb +77 -0
- data/lib/eucalypt/eucalypt-destroy/namespaces/destroy/cli/destroy-controller.rb +16 -0
- data/lib/eucalypt/eucalypt-destroy/namespaces/destroy/cli/destroy-helper.rb +16 -0
- data/lib/eucalypt/eucalypt-destroy/namespaces/destroy/cli/destroy-model.rb +16 -0
- data/lib/eucalypt/eucalypt-destroy/namespaces/destroy/cli/destroy-scaffold.rb +63 -0
- data/lib/eucalypt/eucalypt-destroy/namespaces/destroy/cli/destroy.rb +21 -0
- data/lib/eucalypt/eucalypt-generate/.gitkeep +0 -0
- data/lib/eucalypt/eucalypt-generate/namespaces/generate/cli/generate-scaffold.rb +62 -0
- data/lib/eucalypt/eucalypt-generate/namespaces/generate/cli/generate.rb +24 -0
- data/lib/eucalypt/eucalypt-generate/namespaces/generate-controller/cli/generate-controller.rb +29 -0
- data/lib/eucalypt/eucalypt-generate/namespaces/generate-controller/generators/controller.rb +45 -0
- data/lib/eucalypt/eucalypt-generate/namespaces/generate-controller/templates/controller/controller.tt +3 -0
- data/lib/eucalypt/eucalypt-generate/namespaces/generate-controller/templates/controller/policy_rest_controller.tt +71 -0
- data/lib/eucalypt/eucalypt-generate/namespaces/generate-controller/templates/controller/rest_controller.tt +28 -0
- data/lib/eucalypt/eucalypt-generate/namespaces/generate-controller/templates/controller_spec.tt +9 -0
- data/lib/eucalypt/eucalypt-generate/namespaces/generate-helper/cli/generate-helper.rb +23 -0
- data/lib/eucalypt/eucalypt-generate/namespaces/generate-helper/generators/helper.rb +24 -0
- data/lib/eucalypt/eucalypt-generate/namespaces/generate-helper/templates/helper.tt +3 -0
- data/lib/eucalypt/eucalypt-generate/namespaces/generate-helper/templates/helper_spec.tt +9 -0
- data/lib/eucalypt/eucalypt-generate/namespaces/generate-model/cli/generate-model.rb +26 -0
- data/lib/eucalypt/eucalypt-generate/namespaces/generate-model/generators/model.rb +25 -0
- data/lib/eucalypt/eucalypt-generate/namespaces/generate-model/templates/model.tt +3 -0
- data/lib/eucalypt/eucalypt-generate/namespaces/generate-model/templates/model_spec.tt +8 -0
- data/lib/eucalypt/eucalypt-migration/helpers.rb +93 -0
- data/lib/eucalypt/eucalypt-migration/migration_base.tt +4 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration/cli/migration.rb +39 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-add/cli/add-column.rb +25 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-add/cli/add-index.rb +25 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-add/cli/add.rb +18 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-add/generators/column.rb +46 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-add/generators/index.rb +52 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-blank/cli/blank.rb +22 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-blank/generators/blank.rb +28 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-change/cli/change-column.rb +23 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-change/cli/change.rb +17 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-change/generators/column.rb +46 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-create/cli/create-table.rb +25 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-create/cli/create.rb +17 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-create/generators/table.rb +53 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-drop/cli/drop-column.rb +22 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-drop/cli/drop-index.rb +23 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-drop/cli/drop-table.rb +22 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-drop/cli/drop.rb +19 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-drop/generators/column.rb +38 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-drop/generators/index.rb +48 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-drop/generators/table.rb +37 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-rename/cli/rename-column.rb +22 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-rename/cli/rename-index.rb +22 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-rename/cli/rename-table.rb +24 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-rename/cli/rename.rb +19 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-rename/generators/column.rb +39 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-rename/generators/index.rb +39 -0
- data/lib/eucalypt/eucalypt-migration/namespaces/migration-rename/generators/table.rb +38 -0
- data/lib/eucalypt/eucalypt-security/helpers.rb +22 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security/cli/security.rb +31 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security-policy/cli/security-policy.rb +91 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security-policy/generators/policy.rb +31 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security-policy/templates/create_policy_roles_migration.tt +11 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security-policy/templates/policy.tt +16 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security-policy-permission/cli/security-policy-permission.rb +62 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security-policy-permission/generators/policy-permission.rb +28 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security-policy-permission/templates/add_permission_to_policy_migration.tt +5 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security-policy-role/cli/security-policy-role.rb +66 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security-pundit/cli/security-pundit.rb +79 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security-pundit/generators/role.rb +24 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security-pundit/templates/create_roles_migration.tt +7 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security-pundit/templates/pundit.tt +4 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security-warden/cli/security-warden.rb +61 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security-warden/generators/auth_controller.rb +34 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security-warden/generators/user.rb +37 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security-warden/templates/auth_controller.tt +25 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security-warden/templates/auth_login.tt +1 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security-warden/templates/create_users_table_migration.tt +9 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security-warden/templates/user.tt +16 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security-warden/templates/warden.tt +35 -0
- data/lib/eucalypt/eucalypt-security/namespaces/security-warden/user_confirm.rb +38 -0
- data/lib/eucalypt/helpers/colorize.rb +27 -0
- data/lib/eucalypt/helpers/gemfile.rb +48 -0
- data/lib/eucalypt/helpers/inflect.rb +79 -0
- data/lib/eucalypt/helpers/messages.rb +31 -0
- data/lib/eucalypt/helpers/migration.rb +85 -0
- data/lib/eucalypt/helpers/numeric.rb +10 -0
- data/lib/eucalypt/helpers.rb +6 -0
- data/lib/eucalypt/list.rb +39 -0
- data/lib/eucalypt/static.rb +48 -0
- data/lib/eucalypt/version.rb +3 -0
- data/lib/eucalypt.rb +19 -0
- metadata +373 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'eucalypt/eucalypt-security/namespaces/security-warden/user_confirm'
|
2
|
+
class User < ActiveRecord::Base
|
3
|
+
validates :username, presence: true, uniqueness: true
|
4
|
+
validates :encrypted_password, presence: true
|
5
|
+
|
6
|
+
include BCrypt
|
7
|
+
|
8
|
+
def authenticate(attempt)
|
9
|
+
Password.new(self.encrypted_password) == attempt
|
10
|
+
end
|
11
|
+
|
12
|
+
def password=(entered_password)
|
13
|
+
@password = Password.create(entered_password)
|
14
|
+
self.encrypted_password = @password
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class ApplicationController < Sinatra::Base
|
2
|
+
# Configure Warden for authentication
|
3
|
+
enable :sessions
|
4
|
+
|
5
|
+
use Warden::Manager do |config|
|
6
|
+
config.serialize_into_session{|user| user.id}
|
7
|
+
config.serialize_from_session{|id| User.find(id)}
|
8
|
+
config.scope_defaults :default, strategies: [:password], action: 'auth/invalid'
|
9
|
+
config.failure_app = self
|
10
|
+
end
|
11
|
+
|
12
|
+
Warden::Manager.before_failure {|env,opts| env['REQUEST_METHOD'] = 'POST'}
|
13
|
+
Warden::Strategies.add(:password) do
|
14
|
+
def valid?
|
15
|
+
params['user'] && params['user']['username'] && params['user']['password']
|
16
|
+
end
|
17
|
+
def authenticate!
|
18
|
+
unless (user = User.find_by_username params['user']['username'])
|
19
|
+
fail! 'The username you entered does not exist'
|
20
|
+
else
|
21
|
+
user.authenticate(params['user']['password']) ? success!(user) : fail!('Could not log in')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
helpers do
|
27
|
+
def current_user
|
28
|
+
env['warden'].user
|
29
|
+
end
|
30
|
+
|
31
|
+
def authenticate
|
32
|
+
env['warden'].authenticate!
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class User < ActiveRecord::Base
|
2
|
+
def with_confirm(*fields)
|
3
|
+
return if fields.empty?
|
4
|
+
fields.map(&:to_sym).each {|field| instance_variable_set "@with_confirm_#{field}", true }
|
5
|
+
class_eval do
|
6
|
+
attr_accessor *fields.map {|field| "#{field}_confirmation".to_sym }
|
7
|
+
attr_reader *fields.map {|field| field.to_sym }.reject {|field| field != :password}
|
8
|
+
end
|
9
|
+
|
10
|
+
fields.each do |field|
|
11
|
+
confirm = "confirm_#{field}".to_sym
|
12
|
+
define_singleton_method confirm do
|
13
|
+
if instance_variable_get "@with_#{confirm}"
|
14
|
+
case field
|
15
|
+
when :password
|
16
|
+
return if @password.nil?
|
17
|
+
unless authenticate @password_confirmation
|
18
|
+
errors.add :password_confirmation, "Passwords don't match"
|
19
|
+
end
|
20
|
+
else
|
21
|
+
actual = self.send field
|
22
|
+
return if actual.nil?
|
23
|
+
confirmation = instance_variable_get "@#{field}_confirmation"
|
24
|
+
unless actual == confirmation
|
25
|
+
errors.add "#{field}_confirmation", "#{field.to_s.pluralize.capitalize} don't match"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class_eval do
|
32
|
+
private confirm
|
33
|
+
validate confirm
|
34
|
+
end
|
35
|
+
end
|
36
|
+
self
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Eucalypt
|
2
|
+
module Helpers
|
3
|
+
module Colorize
|
4
|
+
ANSI = {
|
5
|
+
bold: '1',
|
6
|
+
red: '91',
|
7
|
+
yellow: '93',
|
8
|
+
blue: '94',
|
9
|
+
magenta: '95',
|
10
|
+
pale_blue: '34',
|
11
|
+
underline: '4',
|
12
|
+
grey: '90'
|
13
|
+
}
|
14
|
+
|
15
|
+
refine String do
|
16
|
+
def colorize(*opts)
|
17
|
+
"\e[#{opts.map{|o| ANSI[o]}*?;}m#{self}\e[0m"
|
18
|
+
end
|
19
|
+
|
20
|
+
def uncolorize
|
21
|
+
result = self.gsub /\e(\[|\])[0-9]+[0-9;]*m/, ''
|
22
|
+
result.nil? ? self : result
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'eucalypt/errors'
|
3
|
+
|
4
|
+
module Eucalypt
|
5
|
+
module Helpers
|
6
|
+
module Gemfile
|
7
|
+
def gemfile_add(description, gems, directory)
|
8
|
+
gemfile = File.join(directory, 'Gemfile')
|
9
|
+
File.open gemfile do |f|
|
10
|
+
includes_gems = []
|
11
|
+
contents = f.read
|
12
|
+
gems.each do |gem, _|
|
13
|
+
includes_gems << true if contents.include? "gem '#{gem}'"
|
14
|
+
end
|
15
|
+
return unless includes_gems.empty?
|
16
|
+
end
|
17
|
+
|
18
|
+
append_to_file gemfile, "\n# #{description}\n"
|
19
|
+
gems.each_with_index do |gemdata, i|
|
20
|
+
gem, version = gemdata
|
21
|
+
gem_string = "gem '#{gem}', '#{version}'" << (i==gems.size-1 ? '' : "\n")
|
22
|
+
append_to_file gemfile, gem_string
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def include?(gems, directory)
|
28
|
+
includes_gems = []
|
29
|
+
gemfile = File.join(directory, 'Gemfile')
|
30
|
+
File.open gemfile do |f|
|
31
|
+
contents = f.read
|
32
|
+
gems.each {|gem| includes_gems << contents.include?("gem '#{gem}'") }
|
33
|
+
end
|
34
|
+
includes_gems.all? {|present| present == true}
|
35
|
+
end
|
36
|
+
|
37
|
+
def check(gems, command, directory)
|
38
|
+
if include?(gems, directory)
|
39
|
+
true
|
40
|
+
else
|
41
|
+
Eucalypt::Error.no_gems(gems, command)
|
42
|
+
false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext'
|
3
|
+
|
4
|
+
module Eucalypt
|
5
|
+
module Helpers
|
6
|
+
class Inflect
|
7
|
+
class << self
|
8
|
+
def route(string)
|
9
|
+
string.
|
10
|
+
underscore.
|
11
|
+
parameterize(separator: ?-).
|
12
|
+
gsub(?_,?-).
|
13
|
+
sub(/(^\-+?)(?=[A-Za-z0-9])/,'').
|
14
|
+
reverse.
|
15
|
+
sub(/(^\-+?)(?=[A-Za-z0-9])/,'').
|
16
|
+
reverse.
|
17
|
+
gsub(/\-\-+/,?-)
|
18
|
+
end
|
19
|
+
|
20
|
+
def resource(string)
|
21
|
+
route(string).gsub(?-,?_).singularize
|
22
|
+
end
|
23
|
+
|
24
|
+
def resources(string)
|
25
|
+
route(string).gsub(?-,?_).pluralize
|
26
|
+
end
|
27
|
+
|
28
|
+
def resource_keep_inflection(string)
|
29
|
+
route(string).gsub(?-,?_)
|
30
|
+
end
|
31
|
+
|
32
|
+
def constant(string)
|
33
|
+
resource(string).camelize
|
34
|
+
end
|
35
|
+
|
36
|
+
def constant_pluralize(string)
|
37
|
+
resources(string).camelize
|
38
|
+
end
|
39
|
+
|
40
|
+
%i[controller helper policy].each do |type|
|
41
|
+
define_method type do |string|
|
42
|
+
s = resource(string.singularize)
|
43
|
+
if s.end_with? "_#{type}"
|
44
|
+
name = s.split("_#{type}").first
|
45
|
+
"#{name.singularize}_#{type}"
|
46
|
+
else
|
47
|
+
"#{s.singularize}_#{type}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def model(string)
|
53
|
+
resource(string.singularize)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
attr_reader :name,
|
58
|
+
:file_name, :file_path,
|
59
|
+
:spec_name, :spec_path,
|
60
|
+
:class_name, :route_name,
|
61
|
+
:resource, :resources,
|
62
|
+
:constant
|
63
|
+
|
64
|
+
def initialize(type, name)
|
65
|
+
type = type
|
66
|
+
@name = Inflect.send(type, name.to_s)
|
67
|
+
@file_name = "#{@name}.rb"
|
68
|
+
@file_path = File.join('app', type.to_s.pluralize, file_name)
|
69
|
+
@spec_name = "#{@name}_spec.rb"
|
70
|
+
@spec_path = File.join('spec', type.to_s.pluralize, spec_name)
|
71
|
+
@class_name = Inflect.constant(@name)
|
72
|
+
@route_name = Inflect.route(@name.gsub "_#{type}", '')
|
73
|
+
@resource = Inflect.resource(@route_name)
|
74
|
+
@resources = Inflect.resources(@route_name)
|
75
|
+
@constant = Inflect.constant(@route_name)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'colorize'
|
2
|
+
module Eucalypt
|
3
|
+
module Helpers
|
4
|
+
module Messages
|
5
|
+
module Out
|
6
|
+
using Eucalypt::Helpers::Colorize
|
7
|
+
METHODS = {
|
8
|
+
warning: [:bold, :yellow],
|
9
|
+
error: [:bold, :red],
|
10
|
+
info: [:bold]
|
11
|
+
}
|
12
|
+
|
13
|
+
class << self
|
14
|
+
METHODS.each do |method, opts|
|
15
|
+
define_method "#{method}_message" do |message = String.new|
|
16
|
+
"#{method.to_s.upcase.colorize(*opts)}: #{message}"
|
17
|
+
end
|
18
|
+
|
19
|
+
define_method method do |message = String.new|
|
20
|
+
puts self.send("#{method}_message", message)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup(message = String.new)
|
25
|
+
puts "\n#{message.colorize(:bold, :blue)}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require_relative 'messages'
|
3
|
+
require 'eucalypt/errors'
|
4
|
+
require 'eucalypt/helpers'
|
5
|
+
|
6
|
+
module Eucalypt
|
7
|
+
module Helpers
|
8
|
+
class Migration < Thor
|
9
|
+
include Thor::Actions
|
10
|
+
include Eucalypt::Helpers
|
11
|
+
include Eucalypt::Helpers::Messages
|
12
|
+
using Colorize
|
13
|
+
attr_reader :title, :template, :file, :base, :file_path
|
14
|
+
|
15
|
+
class << self
|
16
|
+
alias_method :[], :new
|
17
|
+
end
|
18
|
+
|
19
|
+
no_tasks do
|
20
|
+
def initialize(title:, template:)
|
21
|
+
@title = title
|
22
|
+
@template = template
|
23
|
+
@file = Time.now.utc.strftime("%Y%m%d%H%M%S_#{title}.rb")
|
24
|
+
@base = File.join 'db', 'migrate'
|
25
|
+
@file_path = File.join @base, @file
|
26
|
+
end
|
27
|
+
|
28
|
+
def exists?
|
29
|
+
Dir[File.join @base, '*.rb'].any? {|f| f.include? @title}
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_anyway?
|
33
|
+
%w[y Y Yes YES].include? create_anyway_prompt
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Validation
|
38
|
+
attr_reader :invalid_declarations, :invalid_types
|
39
|
+
|
40
|
+
COLUMN_TYPES = %i[
|
41
|
+
binary boolean date datetime decimal float integer
|
42
|
+
bigint primary_key references string text time timestamp
|
43
|
+
]
|
44
|
+
|
45
|
+
DECLARATION_REGEX = /\A[A-Za-z0-9_]+\:[a-z_]+\Z/
|
46
|
+
|
47
|
+
def initialize(columns)
|
48
|
+
@invalid_declarations = []
|
49
|
+
@invalid_types = []
|
50
|
+
|
51
|
+
columns.each do |column|
|
52
|
+
if self.class.valid_declaration? column
|
53
|
+
col, type = column.split ?:
|
54
|
+
@invalid_types << {column: col, type: type} unless COLUMN_TYPES.include? type.to_sym
|
55
|
+
else
|
56
|
+
@invalid_declarations << column
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def any_invalid?
|
62
|
+
any_invalid = @invalid_declarations.any? || @invalid_types.any?
|
63
|
+
Eucalypt::Error.invalid_columns(@invalid_declarations, @invalid_types) if any_invalid
|
64
|
+
return any_invalid
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.valid_declaration?(column)
|
68
|
+
DECLARATION_REGEX.match? column
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.valid_type?(type)
|
72
|
+
valid_type = COLUMN_TYPES.include? type.to_sym
|
73
|
+
Eucalypt::Error.invalid_type(type) unless valid_type
|
74
|
+
return valid_type
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def create_anyway_prompt
|
81
|
+
ask Out.warning_message("A #{@title.colorize(:bold)} migration already exists. Create anyway?"), limited_to: %w[y Y Yes YES n N No NO]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'eucalypt/app'
|
3
|
+
require 'eucalypt/helpers/colorize'
|
4
|
+
|
5
|
+
module Eucalypt
|
6
|
+
module List
|
7
|
+
include Eucalypt::Helpers
|
8
|
+
using Colorize
|
9
|
+
|
10
|
+
INDENT = 2.freeze
|
11
|
+
|
12
|
+
def help(shell, subcommand = false)
|
13
|
+
list = printable_commands(true, subcommand)
|
14
|
+
Thor::Util.thor_classes_in(self).each do |klass|
|
15
|
+
list += klass.printable_commands(false)
|
16
|
+
end
|
17
|
+
|
18
|
+
list.reject! do |l|
|
19
|
+
cmd = l.first
|
20
|
+
cmd.include?('help') || cmd.include?('-H')
|
21
|
+
end
|
22
|
+
list.map {|l| l.last.sub!(?#, '·'.colorize(:pale_blue, :bold)+'›')}
|
23
|
+
|
24
|
+
if defined?(@package_name) && @package_name
|
25
|
+
shell.say "#{@package_name} commands:"
|
26
|
+
else
|
27
|
+
shell.say
|
28
|
+
shell.say "#{"Commands".colorize(:bold)}:"
|
29
|
+
end
|
30
|
+
|
31
|
+
shell.print_table(list, indent: INDENT, truncate: false)
|
32
|
+
shell.say
|
33
|
+
class_options_help(shell)
|
34
|
+
|
35
|
+
shell.say "For more information about a specific command, use #{"eucalypt -H".colorize(:pale_blue)}."
|
36
|
+
shell.say "Example: eucalypt -H generate scaffold".colorize(:grey)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'eucalypt/helpers/inflect'
|
2
|
+
require 'json'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module Eucalypt
|
6
|
+
class Static
|
7
|
+
include Eucalypt::Helpers
|
8
|
+
|
9
|
+
FILE_TYPES = {yaml: %w[yml yaml], json: %w[json geojson]}
|
10
|
+
|
11
|
+
def initialize(directory, symbolize: false)
|
12
|
+
contents = Dir[File.join directory, '*']
|
13
|
+
files = contents.select {|f| File.file? f}
|
14
|
+
subdirectories = contents.select {|f| File.directory? f}
|
15
|
+
files.each {|f| define_file_accessor f, symbolize}
|
16
|
+
subdirectories.each {|s| define_subdirectory_accessor s, symbolize}
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def define_file_accessor(file, symbolize)
|
22
|
+
file_name = File.basename file, '.*'
|
23
|
+
extension = File.extname(file).sub /\A./, ''
|
24
|
+
file_type = nil
|
25
|
+
FILE_TYPES.each {|t, e| file_type = t if e.include? extension}
|
26
|
+
raise TypeError.new("Unsupported extension: .#{extension}") if file_type.nil?
|
27
|
+
define_singleton_method Inflect.resource_keep_inflection(file_name) do
|
28
|
+
hash = parse(file_type, file)
|
29
|
+
hash = hash ? hash : {}
|
30
|
+
symbolize ? hash.deep_symbolize_keys : hash
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def define_subdirectory_accessor(subdirectory, symbolize)
|
35
|
+
subdirectory_name = subdirectory.split(File::SEPARATOR).last
|
36
|
+
define_singleton_method Inflect.resource_keep_inflection(subdirectory_name) do
|
37
|
+
Static.new subdirectory, symbolize: symbolize
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def parse(file_type, file)
|
42
|
+
case file_type
|
43
|
+
when :yaml then YAML.load_file(file)
|
44
|
+
when :json then JSON.parse(File.read file)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/eucalypt.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'eucalypt/version'
|
2
|
+
require 'eucalypt/eucalypt-core/cli/core'
|
3
|
+
require 'eucalypt/eucalypt-blog/namespaces/blog/cli/blog'
|
4
|
+
require 'eucalypt/eucalypt-generate/namespaces/generate/cli/generate'
|
5
|
+
require 'eucalypt/eucalypt-destroy/namespaces/destroy/cli/destroy'
|
6
|
+
require 'eucalypt/eucalypt-security/namespaces/security/cli/security'
|
7
|
+
require 'eucalypt/eucalypt-migration/namespaces/migration/cli/migration'
|
8
|
+
require 'eucalypt/static'
|
9
|
+
require 'eucalypt/controller'
|
10
|
+
require 'eucalypt/app'
|
11
|
+
|
12
|
+
module Eucalypt
|
13
|
+
class CLI < Thor
|
14
|
+
class << self
|
15
|
+
require 'eucalypt/list'
|
16
|
+
include Eucalypt::List
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|