Skip to content

Commit

Permalink
more on setting up infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislaw committed Sep 2, 2011
1 parent 7917c0d commit 1d3ff0e
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -12,7 +12,7 @@ gem 'rake-kit'
gem 'require_all' gem 'require_all'


gem 'sugar-high' gem 'sugar-high'

gem 'sweetloader'
group :development, :test do group :development, :test do
gem 'cutter' gem 'cutter'
end end
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -20,7 +20,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_files.include('lib/**/*.rb') rdoc.rdoc_files.include('lib/**/*.rb')
end end


APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__) APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
load 'rails/tasks/engine.rake' load 'rails/tasks/engine.rake'




Expand Down
4 changes: 4 additions & 0 deletions app/models/role.rb
@@ -0,0 +1,4 @@
class Role < ActiveRecord::Base
has_many :user_roles
has_many :users, :through => :user_roles
end
6 changes: 6 additions & 0 deletions app/models/user.rb
@@ -0,0 +1,6 @@
class User < ActiveRecord::Base
serialize :roles

has_many :user_roles
has_many :roles, :through => :user_roles
end
4 changes: 4 additions & 0 deletions app/models/user_role.rb
@@ -0,0 +1,4 @@
class UserRole
belongs_to :user
belongs_to :role
end
15 changes: 15 additions & 0 deletions db/migrate/001_create_user_roles.rb
@@ -0,0 +1,15 @@
class CreateUserRoles < ActiveRecord::Migration
def up
create_table :user_roles do |t|
t.integer :user_id
t.integer :role_id

t.timestamps
end
add_index :user_roles, [:user_id, :role_id]
end

def down
drop_table :user_roles
end
end
12 changes: 12 additions & 0 deletions db/migrate/002_create_roles.rb
@@ -0,0 +1,12 @@
class CreateRoles < ActiveRecord::Migration
def up
create_table :roles do |t|
t.string :name
t.timestamps
end
end

def down
drop_table :roles
end
end
3 changes: 2 additions & 1 deletion lib/simple_roles.rb
@@ -1,4 +1,5 @@
require "simple_roles/engine" require "simple_roles/engine"

require "sweetloader"
module SimpleRoles module SimpleRoles
autoload_modules :Base
end end
13 changes: 13 additions & 0 deletions lib/simple_roles/base.rb
@@ -0,0 +1,13 @@
module SimpleRoles
module Base

def roles_list
roles
end

def role_groups_list
role_groups
end

end
end
2 changes: 1 addition & 1 deletion script/rails
Expand Up @@ -3,4 +3,4 @@
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.


ENGINE_PATH = File.expand_path('../..', __FILE__) ENGINE_PATH = File.expand_path('../..', __FILE__)
load File.expand_path('../../test/dummy/script/rails', __FILE__) load File.expand_path('../../spec/dummy/script/rails', __FILE__)
15 changes: 15 additions & 0 deletions spec/dummy/db/migrate/20110902230221_create_user_roles.rb
@@ -0,0 +1,15 @@
class CreateUserRoles < ActiveRecord::Migration
def up
create_table :user_roles do |t|
t.integer :user_id
t.integer :role_id

t.timestamps
end
add_index :user_roles, [:user_id, :role_id]
end

def down
drop_table :user_roles
end
end
12 changes: 12 additions & 0 deletions spec/dummy/db/migrate/20110902230222_create_roles.rb
@@ -0,0 +1,12 @@
class CreateRoles < ActiveRecord::Migration
def up
create_table :roles do |t|
t.string :name
t.timestamps
end
end

def down
drop_table :roles
end
end

0 comments on commit 1d3ff0e

Please sign in to comment.