sentinel-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +24 -0
  5. data/app/assets/javascripts/sentinel/application.js +13 -0
  6. data/app/assets/stylesheets/sentinel/application.css +15 -0
  7. data/app/controllers/sentinel/application_controller.rb +4 -0
  8. data/app/controllers/sentinel/session_controller.rb +37 -0
  9. data/app/controllers/sentinel/users_controller.rb +30 -0
  10. data/app/helpers/sentinel/application_helper.rb +4 -0
  11. data/app/models/sentinel/db/connection.rb +10 -0
  12. data/app/models/sentinel/user.rb +9 -0
  13. data/app/views/layouts/sentinel/application.haml +1 -0
  14. data/app/views/sentinel/session/new.haml +0 -0
  15. data/app/views/sentinel/users/_form.haml +1 -0
  16. data/app/views/sentinel/users/edit.haml +1 -0
  17. data/app/views/sentinel/users/new.haml +1 -0
  18. data/config/database.yml.example +39 -0
  19. data/config/routes.rb +6 -0
  20. data/db/migrate/20150922214224_create_sentinel_users.rb +12 -0
  21. data/db/migrate/20150922214526_create_sentinel_groups.rb +10 -0
  22. data/db/migrate/20150922215516_create_sentinel_projects.rb +10 -0
  23. data/db/migrate/20150922215601_create_sentinel_controllers.rb +18 -0
  24. data/db/migrate/20150922215619_create_sentinel_actions.rb +18 -0
  25. data/db/migrate/20150922215724_create_sentinel_permissions.rb +23 -0
  26. data/db/migrate/20151001224349_sentinel_users_groups.rb +24 -0
  27. data/lib/generators/sentinel/config/database/database_generator.rb +21 -0
  28. data/lib/generators/sentinel/install/migrations_generator.rb +33 -0
  29. data/lib/sentinel-rails.rb +1 -0
  30. data/lib/sentinel/engine.rb +5 -0
  31. data/lib/sentinel/version.rb +3 -0
  32. data/lib/tasks/sentinel/config/database.rake +63 -0
  33. data/lib/tasks/sentinel/truncate/table.rake +37 -0
  34. metadata +90 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e73d5487a2c20a8aab7445e98294076588662aa3
4
+ data.tar.gz: a60250e68fc1c8ad485d08da5a4122d09e1f13b5
5
+ SHA512:
6
+ metadata.gz: 56d15c46b05f3f2e2675ca91fb070c4cb965db9eed605c48d88d6813a86fa3c2e4bbf6a86cf0db0a671f0336e8b7b3f5b88ff57c30b50817bff4609ae3a78100
7
+ data.tar.gz: 69b955689e4106b7cf1f42ae4e8fa0a626700dad44f9d3c834effb0d5bb808948efe55c402eb7bbbb94f0788dcb11080770aa7817cc84c5050047ba86a6049bb
@@ -0,0 +1,20 @@
1
+ Copyright 2015
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ = Sentinel
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,24 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Sentinel'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+ load 'rails/tasks/statistics.rake'
20
+
21
+
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module Sentinel
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,37 @@
1
+ module Sentinel
2
+ class SessionController < ApplicationController
3
+
4
+ respond_to :html, :js
5
+
6
+ def new
7
+ # session[:user_id] = nil
8
+ # session[:cart] = nil
9
+ if authenticated_user
10
+ redirect_to offers_path
11
+ else
12
+ @session = User.new
13
+ end
14
+ end
15
+
16
+ def create
17
+ @session = User.find_by_email(params[:user][:email])
18
+ if @session && User.authenticate(@session.email, params[:user][:password])
19
+ session[:user_id] = @session.id
20
+ if authenticated_user.admin
21
+ # o location somente redirecionará se o verbo HTTP for um POST ou PUT.
22
+ respond_with @session, location: products_path
23
+ else
24
+ redirect_to offers_path
25
+ end
26
+ else
27
+ respond_with @session, location: new_session_path
28
+ end
29
+ end
30
+
31
+ def destroy
32
+ session[:user_id] = nil
33
+ redirect_to new_session_path
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,30 @@
1
+ module Sentinel
2
+ class UsersController < Sentinel::ApplicationController
3
+ respond_to :html
4
+
5
+ def new
6
+ respond_with @user = User.new
7
+ end
8
+
9
+ def create
10
+ respond_with @user = User.create(params[:user])
11
+ end
12
+
13
+ def show
14
+ respond_with @user = User.find(params[:id])
15
+ end
16
+
17
+ def edit
18
+ @user = User.find(params[:id])
19
+ end
20
+
21
+ def update
22
+ respond_with @user = User.update(params[:id], params[:user])
23
+ end
24
+
25
+ def destroy
26
+ respond_with @user = User.destroy(params[:id])
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,4 @@
1
+ module Sentinel
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,10 @@
1
+ module Sentinel
2
+ module DB
3
+ class Connection < ActiveRecord::Base
4
+ # para que outro modelo herde deste, este deve ser definido como abstrato
5
+ self.abstract_class = true
6
+ module_name = Module.nesting.last.name.downcase
7
+ establish_connection "#{module_name}_#{Rails.env}".to_sym
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module Sentinel
2
+ class User < Sentinel::DB::Connection
3
+ # set_table_name
4
+ # self.table_name
5
+ # @initial_time = nil
6
+ # @final_time = nil
7
+ # attr_accessor :initial_time, :final_time
8
+ end
9
+ end
@@ -0,0 +1 @@
1
+ = render :template => 'layouts/application'
File without changes
@@ -0,0 +1 @@
1
+ Bla bla
@@ -0,0 +1 @@
1
+ = render "form"
@@ -0,0 +1 @@
1
+ = render "form"
@@ -0,0 +1,39 @@
1
+ # rake db:create db:migrate deve ser executado com o parâmetro RAILS_ENV=... para cada ambiente diferente. E os ambientes test e development devem estar configurados
2
+
3
+ common: &common
4
+ encoding: utf8
5
+
6
+ localhost: &localhost
7
+ host: localhost
8
+
9
+ sqlite3: &sqlite3
10
+ adapter: sqlite3
11
+ pool: 5
12
+ timeout: 5000
13
+
14
+ postgres: &postgres
15
+ adapter: postgresql
16
+ user: postgres
17
+
18
+ test:
19
+ <<: *common
20
+ <<: *localhost
21
+
22
+ # <<: *postgres
23
+ # <<: *sqlite3
24
+ # database: db/test.sqlite3
25
+
26
+
27
+ development:
28
+ <<: *common
29
+ <<: *localhost
30
+
31
+ # <<: *postgres
32
+ # <<: *sqlite3
33
+ # database: db/development.sqlite3
34
+
35
+ production:
36
+ <<: *common
37
+ <<: *postgres
38
+
39
+ # <<: *postgres
@@ -0,0 +1,6 @@
1
+ Sentinel::Engine.routes.draw do
2
+
3
+ resources :session, only: [ :new, :create, :destroy ]
4
+ resources :users, except: [ :index ]
5
+
6
+ end
@@ -0,0 +1,12 @@
1
+ class CreateSentinelUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :sentinel_users do |t|
4
+ t.string :login, index: true
5
+ t.string :password, null: false
6
+ t.string :email, null: false, index: true
7
+
8
+ t.timestamps null: false
9
+ # t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ class CreateSentinelGroups < ActiveRecord::Migration
2
+ def change
3
+ create_table :sentinel_groups do |t|
4
+ t.string :name, index: true
5
+
6
+ t.timestamps null: false
7
+ # t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class CreateSentinelProjects < ActiveRecord::Migration
2
+ def change
3
+ create_table :sentinel_projects do |t|
4
+ t.string :name, null: false, index: true
5
+
6
+ # t.timestamps null: false
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ class CreateSentinelControllers < ActiveRecord::Migration
2
+ def change
3
+ create_table :sentinel_controllers do |t|
4
+ t.string :name, null: false, index:true
5
+ t.integer :project_id, null: false, index: true
6
+
7
+ t.timestamps
8
+ end
9
+
10
+ add_foreign_key :sentinel_controllers, :sentinel_projects,
11
+ {
12
+ # o cascade deu problema ao ser passado como string ao invés de symbol
13
+ on_delete: :cascade,
14
+ primary_key: :id,
15
+ column: :project_id
16
+ }
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ class CreateSentinelActions < ActiveRecord::Migration
2
+ def change
3
+ create_table :sentinel_actions do |t|
4
+ t.string :name, null: false, index: true
5
+ t.integer :controller_id, null: false, index: true
6
+
7
+ t.timestamps null: false
8
+ # t.timestamps
9
+ end
10
+
11
+ add_foreign_key :sentinel_actions, :sentinel_controllers,
12
+ {
13
+ on_delete: :cascade,
14
+ primary_key: :id,
15
+ column: :controller_id
16
+ }
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ class CreateSentinelPermissions < ActiveRecord::Migration
2
+ def change
3
+ create_table :sentinel_permissions do |t|
4
+ t.integer :group_id, null: false, index: true
5
+ t.integer :action_id, null: false, index: true
6
+
7
+ t.timestamps null: false
8
+ # t.timestamps
9
+ end
10
+ add_foreign_key :sentinel_permissions, :sentinel_groups,
11
+ {
12
+ on_delete: :cascade,
13
+ primary_key: :id,
14
+ column: :group_id
15
+ }
16
+ add_foreign_key :sentinel_permissions, :sentinel_actions,
17
+ {
18
+ on_delete: :cascade,
19
+ primary_key: :id,
20
+ column: :action_id
21
+ }
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ class SentinelUsersGroups < ActiveRecord::Migration
2
+ def change
3
+ create_table :sentinel_users_groups do |t|
4
+ t.integer :user_id, null: false, index: true
5
+ t.integer :group_id, null: false, index: true
6
+
7
+ t.timestamps null: false
8
+ # t.timestamps
9
+ end
10
+
11
+ add_foreign_key :sentinel_users_groups, :sentinel_users,
12
+ {
13
+ on_delete: :cascade,
14
+ primary_key: :id,
15
+ column: :user_id
16
+ }
17
+ add_foreign_key :sentinel_users_groups, :sentinel_groups,
18
+ {
19
+ on_delete: :cascade,
20
+ primary_key: :id,
21
+ column: :group_id
22
+ }
23
+ end
24
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ module Sentinel
4
+ module Generators
5
+ module Config
6
+
7
+ class DatabaseGenerator < ::Rails::Generators::Base
8
+ include Rails::Generators
9
+
10
+ desc "Creates database.yml.example in folder config."
11
+
12
+ source_root File.expand_path("../../../../../../config", __FILE__)
13
+
14
+ def copy_database_config
15
+ copy_file "database.yml.example", "config/database.yml.example"
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ module Sentinel
4
+ module Generators
5
+ module Install
6
+ class MigrationsGenerator < ::Rails::Generators::Base
7
+ include Rails::Generators
8
+
9
+ ROOT_PATH = "../../../../.."
10
+
11
+ # if run as task
12
+ desc "Copy migrations with .sentinel to application"
13
+
14
+ source_root File.expand_path(ROOT_PATH, __FILE__)
15
+
16
+ def copy_migrations
17
+ paths = Dir["#{File.absolute_path("#{ROOT_PATH}/db/migrate", __FILE__)}/*.rb"]
18
+ module_name = Module.nesting.last.name.downcase
19
+
20
+ paths.each do |d|
21
+ ext = File.extname(d)
22
+ filename = File.basename(d, ext)
23
+ file = "#{filename}.#{module_name}#{ext}"
24
+ # uses source path
25
+ copy_file d, "db/migrate/#{file}"
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1 @@
1
+ require "sentinel/engine"
@@ -0,0 +1,5 @@
1
+ module Sentinel
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Sentinel
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Sentinel
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,63 @@
1
+ namespace :sentinel do
2
+ namespace :config do
3
+
4
+ desc "Adds adapter configs on database.yml file and generate the structure for the use."
5
+
6
+ task :database, [:dbms, :encoding, :username] => [:environment] do |t, params|
7
+
8
+ database_conf = "config/database.yml"
9
+ br3 = "\n\n\n"
10
+ br = "\n"
11
+
12
+ test = {
13
+ :sentinel_test => {
14
+ :adapter => params[:dbms],
15
+ :encoding => params[:encoding],
16
+ :host => "localhost",
17
+ :database => "sentinel_test",
18
+ :username => params[:username],
19
+ }
20
+ }
21
+
22
+ dev = {
23
+ :sentinel_development => {
24
+ :adapter => params[:dbms],
25
+ :encoding => params[:encoding],
26
+ :host => "localhost",
27
+ :database => "sentinel_development",
28
+ :username => params[:username]
29
+ }
30
+ }
31
+
32
+ production = {
33
+ :sentinel_production => {
34
+ :adapter => params[:dbms],
35
+ :encoding => params[:encoding],
36
+ :host => "localhost",
37
+ :database => "sentinel_production",
38
+ :username => params[:username],
39
+ :password => nil
40
+ }
41
+ }
42
+
43
+ File.open(database_conf, 'a+') do |f|
44
+
45
+ if f
46
+ f.write br3
47
+ # remova 4 caracteres do inicio, e imprima até -1(todos os caracteres restante)
48
+ f.write test.deep_stringify_keys.to_yaml[4..-1]
49
+ f.write br
50
+ f.write dev.deep_stringify_keys.to_yaml[4..-1]
51
+ f.write br
52
+ f.write production.deep_stringify_keys.to_yaml[4..-1]
53
+ puts "config/database.yml configurado com sucesso!"
54
+ else
55
+ puts "Um erro foi encontrado. Tente novamente, ou contate o desenvolvedor da gem."
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,37 @@
1
+ namespace :sentinel do
2
+ namespace :truncate do
3
+
4
+ desc "Truncate Table"
5
+
6
+ task :table, [:name, :adapter, :no_restart_keys] => [:environment] do |t, params|
7
+
8
+ ActiveRecord::Base.establish_connection(:sentinel_development)
9
+
10
+ if ["postgresql", "postgres"].include? params[:adapter]
11
+ unless params[:not_restart_keys]
12
+ # binding.pry
13
+ if ActiveRecord::Base.connection.exec_query("
14
+ TRUNCATE TABLE #{params[:name]}
15
+ RESTART IDENTITY
16
+ CASCADE
17
+ ")
18
+ p "A tabela #{params[:name]} foi truncada!"
19
+ else
20
+ p "Algo deu errado, tente novamente ou contate o desenvolvedor."
21
+ end
22
+ else
23
+ if ActiveRecord::Base.connection.execute("
24
+ TRUNCATE TABLE #{params[:name]}
25
+ CASCADE
26
+ ")
27
+ p "A tabela #{params[:name]} foi truncada!"
28
+ else
29
+ p "Algo deu errado, tente novamente ou contate o desenvolvedor."
30
+ end
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sentinel-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - home-labs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ description: Description of SentinelRails
28
+ email:
29
+ - home-labs@outlook.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.rdoc
36
+ - Rakefile
37
+ - app/assets/javascripts/sentinel/application.js
38
+ - app/assets/stylesheets/sentinel/application.css
39
+ - app/controllers/sentinel/application_controller.rb
40
+ - app/controllers/sentinel/session_controller.rb
41
+ - app/controllers/sentinel/users_controller.rb
42
+ - app/helpers/sentinel/application_helper.rb
43
+ - app/models/sentinel/db/connection.rb
44
+ - app/models/sentinel/user.rb
45
+ - app/views/layouts/sentinel/application.haml
46
+ - app/views/sentinel/session/new.haml
47
+ - app/views/sentinel/users/_form.haml
48
+ - app/views/sentinel/users/edit.haml
49
+ - app/views/sentinel/users/new.haml
50
+ - config/database.yml.example
51
+ - config/routes.rb
52
+ - db/migrate/20150922214224_create_sentinel_users.rb
53
+ - db/migrate/20150922214526_create_sentinel_groups.rb
54
+ - db/migrate/20150922215516_create_sentinel_projects.rb
55
+ - db/migrate/20150922215601_create_sentinel_controllers.rb
56
+ - db/migrate/20150922215619_create_sentinel_actions.rb
57
+ - db/migrate/20150922215724_create_sentinel_permissions.rb
58
+ - db/migrate/20151001224349_sentinel_users_groups.rb
59
+ - lib/generators/sentinel/config/database/database_generator.rb
60
+ - lib/generators/sentinel/install/migrations_generator.rb
61
+ - lib/sentinel-rails.rb
62
+ - lib/sentinel/engine.rb
63
+ - lib/sentinel/version.rb
64
+ - lib/tasks/sentinel/config/database.rake
65
+ - lib/tasks/sentinel/truncate/table.rake
66
+ homepage: https://rubygems.org/gems/sentinel-rails
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.2.2
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Summary of SentinelRails
90
+ test_files: []