Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial

  • Loading branch information...
commit d6967de80735b0e4cb472a1dc91563e9d59c0764 1 parent ed20802
@kristianmandrup authored
View
2  .gitignore
@@ -13,6 +13,8 @@ doc
# jeweler generated
pkg
+.DS_Store
+*/.DS_Store
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
#
View
39 Gemfile
@@ -1,13 +1,34 @@
-source "http://rubygems.org"
-# Add dependencies required to use your gem here.
-# Example:
-# gem "activesupport", ">= 2.3.5"
+source :rubygems
+
+gem 'rails', '>= 3.1'
+gem 'cantango-core'
-# Add dependencies to develop your gem here.
-# Include everything needed to run rake, tests, features, etc.
group :development do
- gem "shoulda", ">= 0"
- gem "bundler", "~> 1.0.0"
- gem "jeweler", "~> 1.6.4"
+ gem "bundler", ">= 1.1.rc"
+ gem "jeweler", ">= 1.6.4"
gem "rcov", ">= 0"
end
+
+group :test do
+ gem 'require_all', '~> 1.2.0'
+
+ gem 'forgery'
+ gem 'sqlite3'
+ # Data
+ gem 'database_cleaner'
+ gem 'factory_girl'
+
+ # Specs
+ gem 'spork'
+
+ # Debug and performance tests
+ gem 'cutter'
+
+ # Adapters
+ gem 'sourcify'
+ gem 'dkastner-moneta', '>= 1.0'
+end
+
+group :test, :development do
+ gem "rspec", ">= 2.6.0"
+end
View
10 README.rdoc → README.mdown
@@ -1,8 +1,10 @@
-= cantango-roles
+# CanTango Roles
-Description goes here.
+Roles and Role groups extension for [CanTango](https://github.com/kristianmandrup/cantango)
-== Contributing to cantango-roles
+The Configuration DSL has now been almost fully "spec'ed".
+
+## Contributing to cantango-config
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
@@ -12,7 +14,7 @@ Description goes here.
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
-== Copyright
+## Copyright
Copyright (c) 2011 Kristian Mandrup. See LICENSE.txt for
further details.
View
4 Rakefile
@@ -17,8 +17,8 @@ Jeweler::Tasks.new do |gem|
gem.name = "cantango-roles"
gem.homepage = "http://github.com/kristianmandrup/cantango-roles"
gem.license = "MIT"
- gem.summary = %Q{TODO: one-line summary of your gem}
- gem.description = %Q{TODO: longer description of your gem}
+ gem.summary = %Q{Roles extension for CanTango}
+ gem.description = %Q{Roles and Role groups for CanTango}
gem.email = "kmandrup@gmail.com"
gem.authors = ["Kristian Mandrup"]
# dependencies defined in Gemfile
View
0  lib/cantango-roles.rb
No changes.
View
5 lib/cantango/configuration.rb
@@ -0,0 +1,5 @@
+module CanTango
+ class Configuration
+ autoload_modules :RoleGroups, :Roles, :RoleRegistry
+ end
+end
View
46 lib/cantango/configuration/role_groups.rb
@@ -0,0 +1,46 @@
+module CanTango
+ class Configuration
+ class RoleGroups < RoleRegistry
+ include Singleton
+
+ def role_group_system= name
+ raise ArgumentError, "Must be a label" if !name.kind_of_label?
+ @role_group_system = name.to_sym
+ end
+
+ def role_groups_list_map= role_systems_hash
+ raise ArgumentError, "Must be a hash fx :troles => :role_list, was: #{role_systems_hash}" if !role_systems_hash.kind_of?(Hash)
+ @role_groups_list_map = role_systems_hash
+ end
+
+ def role_group_system
+ @role_group_system ||= :troles
+ end
+
+ def add_role_group_system role_system_hash
+ raise ArgumentError, "Must be a hash fx :troles => :role_list, was: #{role_system_hash}" if !role_system_hash.kind_of?(Hash)
+ role_groups_list_map.merge! role_system
+ end
+
+ def default_has_method
+ role_group_methods[:has] || :in_role_group?
+ end
+
+ def default_list_method
+ role_group_methods[:list] || :role_groups_list
+ end
+
+ def role_group_methods
+ role_groups_list_map[role_group_system] || {}
+ end
+
+ def role_groups_list_map
+ @role_groups_list_map ||= {
+ :troles => {:list => :role_group_list}
+ }
+ end
+ end
+ end
+end
+
+
View
47 lib/cantango/configuration/role_registry.rb
@@ -0,0 +1,47 @@
+module CanTango
+ class Configuration
+ class RoleRegistry < Registry
+ attr_reader :has_method, :list_method
+
+ [:has_method, :list_method].each do |meth|
+ class_eval %{
+ def #{meth}
+ @#{meth} ||= default_#{meth}
+ end
+
+ def #{meth}= name
+ raise "Must be a label" if !name.kind_of_label?
+ @#{meth} = name
+ end
+ }
+ end
+
+ def only *names
+ @onlies = names.select_labels
+ end
+
+ def onlies
+ @onlies ||= []
+ end
+
+ def excluded
+ @excluded ||= []
+ end
+
+ def exclude *names
+ @excluded = names.select_labels
+ end
+
+ def filter?
+ !(excluded + onlies).empty?
+ end
+
+ def clear!
+ super
+ @excluded = []
+ @onlies = []
+ end
+ end
+ end
+end
+
View
45 lib/cantango/configuration/roles.rb
@@ -0,0 +1,45 @@
+module CanTango
+ class Configuration
+ class Roles < RoleRegistry
+ include Singleton
+
+ def role_system= name
+ raise ArgumentError, "Must be a label" if !name.kind_of_label?
+ @role_system = name.to_sym
+ end
+
+ def roles_list_map= role_systems_hash
+ raise ArgumentError, "Must be a hash fx :troles => :role_list, was: #{role_systems_hash}" if !role_systems_hash.kind_of?(Hash)
+ @roles_list_map = role_systems_hash
+ end
+
+ def role_system
+ @role_system ||= :simple_roles
+ end
+
+ def add_role_system role_system_hash
+ raise ArgumentError, "Must be a hash fx :troles => :role_list, was: #{role_system_hash}" if !role_system_hash.kind_of?(Hash)
+ roles_list_map.merge! role_system
+ end
+
+ def default_has_method
+ role_system_methods[:list] || :has_role?
+ end
+
+ def default_list_method
+ role_system_methods[:list] || :roles_list
+ end
+
+ def role_system_methods
+ roles_list_map[role_system] || {}
+ end
+
+ def roles_list_map
+ @roles_list_map ||= {
+ :troles => {:list => :role_list},
+ :simple_roles => {:list => :roles_list}
+ }
+ end
+ end
+ end
+end
View
1  lib/cantango/roles.rb
@@ -0,0 +1 @@
+require 'cantango/configuration'
View
15 specs/cantango/configuration/role_groups_spec.rb
@@ -0,0 +1,15 @@
+require 'rspec'
+require 'cantango'
+
+require 'cantango/configuration/role_registry_ex'
+
+describe CanTango::Configuration::RoleGroups do
+ subject { CanTango.config.role_groups }
+
+ it_should_behave_like "Role Registry" do
+ let (:has) { :in_role_group? }
+ let (:list) { :role_groups_list }
+ end
+end
+
+
View
22 specs/cantango/configuration/role_registry_ex.rb
@@ -0,0 +1,22 @@
+require 'cantango/configuration/shared/registry_ex'
+
+shared_examples_for 'Role Registry' do
+ it_should_behave_like "Registry"
+
+ describe 'default settings' do
+ its(:has_method) { should == has }
+ its(:list_method) { should == list }
+
+ its(:default_has_method) { should be_a Symbol }
+ its(:default_list_method) { should be_a Symbol }
+ end
+
+ describe "exclude" do
+ before do
+ subject.exclude :admin
+ end
+
+ its(:excluded) { should include(:admin) }
+ end
+end
+
View
15 specs/cantango/configuration/roles_spec.rb
@@ -0,0 +1,15 @@
+require 'rspec'
+require 'cantango'
+require 'cantango/configuration/role_registry_ex'
+
+describe CanTango::Configuration::Roles do
+ subject { CanTango.config.roles }
+
+ it_should_behave_like "Role Registry" do
+ let (:has) { :has_role? }
+ let (:list) { :roles_list }
+ end
+end
+
+
+
View
18 test/helper.rb
@@ -1,18 +0,0 @@
-require 'rubygems'
-require 'bundler'
-begin
- Bundler.setup(:default, :development)
-rescue Bundler::BundlerError => e
- $stderr.puts e.message
- $stderr.puts "Run `bundle install` to install missing gems"
- exit e.status_code
-end
-require 'test/unit'
-require 'shoulda'
-
-$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
-$LOAD_PATH.unshift(File.dirname(__FILE__))
-require 'cantango-roles'
-
-class Test::Unit::TestCase
-end
View
7 test/test_cantango-roles.rb
@@ -1,7 +0,0 @@
-require 'helper'
-
-class TestCantangoRoles < Test::Unit::TestCase
- should "probably rename this file and start testing for real" do
- flunk "hey buddy, you should probably rename this file and start testing for real"
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.