Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
EppO committed Jun 3, 2011
0 parents commit fd9d4d6
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.gem
.bundle
Gemfile.lock
pkg/*
6 changes: 6 additions & 0 deletions Gemfile
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
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'bundler'
Bundler::GemHelper.install_tasks
Binary file not shown.
34 changes: 34 additions & 0 deletions lib/generators/rolify/role/role_generator.rb
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
15 changes: 15 additions & 0 deletions lib/generators/rolify/role/templates/migration.rb
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
3 changes: 3 additions & 0 deletions lib/generators/rolify/role/templates/role.rb
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
3 changes: 3 additions & 0 deletions lib/rolify.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Rolify
# Your code goes here...
end
3 changes: 3 additions & 0 deletions lib/rolify/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Rolify
VERSION = "0.0.1"
end
21 changes: 21 additions & 0 deletions rolify.gemspec
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 added spec/spec.opts
Empty file.
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
re 'rubygems'
require 'bundler/setup'

Bundler.require(:default)

0 comments on commit fd9d4d6

Please sign in to comment.