doorman 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 [name of plugin creator]
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.
data/README ADDED
@@ -0,0 +1,41 @@
1
+ Doorman
2
+ =======
3
+
4
+ Doorman it's a super simple (aka stupid) white/black list manager.
5
+
6
+ Doorman acts different depending on the kind of list you're asking:
7
+ If you ask if somenthing could pass based on the whitelist it would let throught only entities present on the whitelist.
8
+ If you ask if somenthing could pass based on the blacklist it would let throught everything except for entities present on the blacklist.
9
+
10
+ You'll define those list on a yaml file like this:
11
+
12
+ white: [vicentin@email.com, .*@simplelogica.net]
13
+
14
+ black: [loki@email.com, .*@comunistasnazis.net]
15
+
16
+ It allows ruby regular expresions as shown.
17
+
18
+ Configuration
19
+ =============
20
+
21
+ For Rails projects:
22
+
23
+ config.gem 'doorman'
24
+
25
+ Doorman::CONFIG_PATH = "path-to-your-yml"
26
+
27
+ Example
28
+ =======
29
+
30
+ Doorman::Whitelist.come_in?('vicentin@email.com') # => true
31
+ Doorman::Whitelist.come_in?('diego@simplelogica.net') # => true
32
+ Doorman::Whitelist.come_in?('someone@email.com') # => false
33
+
34
+ Doorman::Blacklist.come_in?('vicentin@email.com') # => true
35
+ Doorman::Blacklist.come_in?('diego@simplelogica.net') # => true
36
+ Doorman::Blacklist.come_in?('loki@email.com') # => false
37
+ Doorman::Blacklist.come_in?('rouco@comunistasnazis.net') # => false
38
+
39
+ I think you've got the idea.
40
+
41
+ Copyright (c) 2009 Diego Fernández, released under the MIT license
@@ -0,0 +1,45 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+ require 'rake/gempackagetask'
6
+
7
+ desc 'Default: run unit tests.'
8
+ task :default => :test
9
+
10
+ desc 'Test the doorman plugin.'
11
+ Rake::TestTask.new(:test) do |t|
12
+ t.libs << 'lib'
13
+ t.libs << 'test'
14
+ t.pattern = 'test/**/*_test.rb'
15
+ t.verbose = true
16
+ end
17
+
18
+ desc 'Generate documentation for the doorman plugin.'
19
+ Rake::RDocTask.new(:rdoc) do |rdoc|
20
+ rdoc.rdoc_dir = 'rdoc'
21
+ rdoc.title = 'Doorman'
22
+ rdoc.options << '--line-numbers' << '--inline-source'
23
+ rdoc.rdoc_files.include('README')
24
+ rdoc.rdoc_files.include('lib/**/*.rb')
25
+ end
26
+
27
+ PKG_FILES = FileList[ '[a-zA-Z]*', 'generators/**/*', 'lib/**/*', 'rails/**/*', 'tasks/**/*', 'test/**/*' ]
28
+ spec = Gem::Specification.new do |s|
29
+ s.name = "doorman"
30
+ s.version = "1.0.0"
31
+ s.author = "Diego Fernández"
32
+ s.email = "diego@simplelogica.net"
33
+ #s.homepage = "http://yafflers.example.com/"
34
+ s.platform = Gem::Platform::RUBY
35
+ s.summary = "Super simple (aka stupid) white/black list manager"
36
+ s.files = PKG_FILES.to_a
37
+ s.require_path = "lib"
38
+ s.has_rdoc = false
39
+ s.extra_rdoc_files = ["README"]
40
+ end
41
+
42
+ desc 'Turn this plugin into a gem.'
43
+ Rake::GemPackageTask.new(spec) do |pkg|
44
+ pkg.gem_spec = spec
45
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ ./script/generate doorman Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,8 @@
1
+ class DoormanGenerator < Rails::Generator::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ # m.directory "lib"
5
+ # m.template 'README', "README"
6
+ end
7
+ end
8
+ end
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ # Include hook code here
2
+ require 'rails/init.rb'
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,42 @@
1
+ # Doorman
2
+ module Doorman
3
+
4
+ CONFIG_FILE_PATH = ""
5
+
6
+ class Whitelist
7
+
8
+ def self.come_in?(item)
9
+ for rule in white_list do
10
+ return true if Regexp.new(rule).match(item.to_s)
11
+ end
12
+ false
13
+ end
14
+
15
+ private
16
+
17
+ def self.white_list
18
+ yaml = YAML.parse_file(CONFIG_FILE_PATH)
19
+ yaml['white'].transform
20
+ end
21
+
22
+ end
23
+
24
+ class Blacklist
25
+
26
+ def self.come_in?(item)
27
+ for rule in black_list do
28
+ return false if Regexp.new(rule).match(item.to_s)
29
+ end
30
+ true
31
+ end
32
+
33
+ private
34
+
35
+ def self.black_list
36
+ yaml = YAML.parse_file(CONFIG_FILE_PATH)
37
+ yaml['black'].transform
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1 @@
1
+ require 'doorman'
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :doorman do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,3 @@
1
+ white: [vicentin@email.com, .*@simplelogica.net]
2
+
3
+ black: [loki@email.com, .*@comunistasnazis.net]
@@ -0,0 +1,42 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require File.dirname(__FILE__) + '/../lib/doorman.rb'
3
+
4
+ class DoormanTest < ActiveSupport::TestCase
5
+ include Doorman
6
+
7
+ context "for values on the white list" do
8
+ setup do
9
+ # See test/doorman.yml to watch the rules defined
10
+ Doorman::CONFIG_FILE_PATH = "#{File.dirname(File.expand_path(__FILE__))}/../test/doorman.yml"
11
+ end
12
+
13
+ should 'let them pass' do
14
+ assert Doorman::Whitelist.come_in?('vicentin@email.com')
15
+ assert Doorman::Whitelist.come_in?('diego@simplelogica.net')
16
+ end
17
+
18
+ should 'not pass' do
19
+ assert !Doorman::Whitelist.come_in?('someone@email.com')
20
+ end
21
+
22
+ end
23
+
24
+ context "for values on the black list" do
25
+ setup do
26
+ # See test/doorman.yml to watch the rules defined
27
+ Doorman::CONFIG_FILE_PATH = "#{File.dirname(File.expand_path(__FILE__))}/../test/doorman.yml"
28
+ end
29
+
30
+ should 'let them pass' do
31
+ assert Doorman::Blacklist.come_in?('vicentin@email.com')
32
+ assert Doorman::Blacklist.come_in?('diego@simplelogica.net')
33
+ end
34
+
35
+ should 'not pass' do
36
+ assert !Doorman::Blacklist.come_in?('loki@email.com')
37
+ assert !Doorman::Blacklist.come_in?('rouco@comunistasnazis.net')
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/test_case'
4
+ require 'shoulda'
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: doorman
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - "Diego Fern\xC3\xA1ndez"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-20 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: diego@simplelogica.net
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - init.rb
26
+ - install.rb
27
+ - MIT-LICENSE
28
+ - Rakefile
29
+ - README
30
+ - uninstall.rb
31
+ - generators/doorman/doorman_generator.rb
32
+ - generators/doorman/USAGE
33
+ - lib/doorman.rb
34
+ - rails/init.rb
35
+ - tasks/doorman_tasks.rake
36
+ - test/doorman.yml
37
+ - test/doorman_test.rb
38
+ - test/test_helper.rb
39
+ has_rdoc: true
40
+ homepage:
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.5
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Super simple (aka stupid) white/black list manager
67
+ test_files: []
68
+