forked from RolifyCommunity/rolify
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fd9d4d6
Showing
12 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.gem | ||
.bundle | ||
Gemfile.lock | ||
pkg/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
source "http://rubygems.org" | ||
|
||
gem "activerecord", :require => "active_record" | ||
|
||
# Specify your gem's dependencies in rolify.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'bundler' | ||
Bundler::GemHelper.install_tasks |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'rails/generators/migration' | ||
|
||
module Rolify | ||
module Generators | ||
class RoleGenerator < Rails::Generators::Base | ||
include Rails::Generators::Migration | ||
|
||
source_root File.expand_path('../templates', __FILE__) | ||
argument :role_cname, :type => :string, :default => "Role" | ||
argument :user_cname, :type => :string, :default => "User" | ||
|
||
desc "Generates a model with the given NAME and a migration file." | ||
|
||
def generate_role | ||
template "role.rb", "app/models/role.rb" | ||
inject_into_class(model_path, user_cname.camelize) do | ||
" has_and_belongs_to_many :#{role_cname.tableize}\n" | ||
end | ||
end | ||
|
||
def copy_role_file | ||
migration_template "migration.rb", "db/migrate/rolify_create_#{role_cname.tableize}" | ||
end | ||
|
||
def model_path | ||
File.join("app", "models", "#{user_cname.underscore}.rb") | ||
end | ||
|
||
def self.next_migration_number(path) | ||
Time.now.utc.strftime("%Y%m%d%H%M%S") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class RolifyCreate<%= role_cname.camelize %> < ActiveRecord::Migration | ||
def change | ||
create_table(<%= role_cname.tableize.to_sym %>) do |t| | ||
t.string :name | ||
t.references :resource, :polymorphic => true | ||
|
||
t.timestamps | ||
end | ||
|
||
create_table(<%= (user_cname.tableize + "_" + role_cname.tableize).to_sym %>, :id => false) do |t| | ||
t.references :<%= user_cname.underscore.singularize %> | ||
t.references :<%= role_cname.underscore.singularize %> | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class <%= role_cname.camelize %> < ActiveRecord::Base | ||
has_and_belongs_to_many :<%= user_cname.tableize %> | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Rolify | ||
# Your code goes here... | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Rolify | ||
VERSION = "0.0.1" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- encoding: utf-8 -*- | ||
$:.push File.expand_path("../lib", __FILE__) | ||
require "rolify/version" | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "rolify" | ||
s.version = Rolify::VERSION | ||
s.platform = Gem::Platform::RUBY | ||
s.authors = ["Florent Monbillard"] | ||
s.email = ["[email protected]"] | ||
s.homepage = "" | ||
s.summary = %q{Roles library with object scoping} | ||
s.description = %q{Very simple Roles library without any authorization enforcement (built to use with cancan) supporting scope on object: user.is_moderator?(Forum.first) => # return false if user is moderator of another Forum } | ||
|
||
s.rubyforge_project = s.name | ||
|
||
s.files = `git ls-files`.split("\n") | ||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
s.require_paths = ["lib"] | ||
end |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
re 'rubygems' | ||
require 'bundler/setup' | ||
|
||
Bundler.require(:default) |