roleup 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c2266312a1c81b096065b9c49a265614b4fd6266
4
+ data.tar.gz: dd6150346601f09c9b42a1a32ef6a99569731414
5
+ SHA512:
6
+ metadata.gz: 0b59f407ade38daa8f21e76b5af4c6e8a2a8d715724bbcbbe0164c6ad74a2afc337b1567c7bee91347e73107aa08850cf6ffedfe9045313a22ed686d1c72a7e9
7
+ data.tar.gz: 1fe839cb648f7a18f3cc4635bb969d74099dcc70ec95947fc6fab09df16bab0b22293dc77c6ebf1895fc1a0180d73dda40a453c235cbeccb576569efd8acdb57
@@ -0,0 +1,17 @@
1
+ module Roleup
2
+ module HasRoles
3
+ attr_reader :roles
4
+
5
+ def roles
6
+ @roles ||= List.new
7
+ end
8
+
9
+ def set_roles(*roles)
10
+ @roles = List.new(*roles)
11
+ end
12
+
13
+ def has_role?(role)
14
+ roles.include? role
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ require "forwardable"
2
+
3
+ module Roleup
4
+ class List
5
+ extend Forwardable
6
+ include Enumerable
7
+ def_delegators :inner_list, :each
8
+
9
+ def initialize(*roles)
10
+ @inner_list = roles.map { |role| standardize(role) }.uniq.sort
11
+ end
12
+
13
+ def include?(role)
14
+ inner_list.include? standardize(role)
15
+ end
16
+
17
+ protected
18
+
19
+ attr_reader :inner_list
20
+
21
+ def standardize(role)
22
+ role.to_s.downcase.to_sym
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Roleup
2
+ VERSION = "0.0.1"
3
+ end
data/lib/roleup.rb ADDED
@@ -0,0 +1,6 @@
1
+ require_relative "roleup/version"
2
+ require_relative "roleup/list"
3
+ require_relative "roleup/has_roles"
4
+
5
+ module Roleup
6
+ end
@@ -0,0 +1,25 @@
1
+ require_relative "test_helper"
2
+
3
+ module Roleup
4
+ class HasRolesTest < MicroTest::Test
5
+
6
+ before do
7
+ class_with_roles = Class.new do
8
+ include HasRoles
9
+ end
10
+
11
+ @obj_with_roles = class_with_roles.new
12
+ @obj_with_roles.set_roles :admin, :editor
13
+ end
14
+
15
+ test "set_roles" do
16
+ assert @obj_with_roles.roles.to_a == [:admin, :editor]
17
+ end
18
+
19
+ test "has_role?" do
20
+ assert @obj_with_roles.has_role?(:admin)
21
+ assert @obj_with_roles.has_role?(:editor)
22
+ end
23
+
24
+ end
25
+ end
data/test/list_test.rb ADDED
@@ -0,0 +1,27 @@
1
+ require_relative "test_helper"
2
+
3
+ module Roleup
4
+ class ListTest < MicroTest::Test
5
+
6
+ before do
7
+ @roles = List.new("Admin", "Editor", "Viewer")
8
+ end
9
+
10
+ test "empty intialization" do
11
+ assert List.new.to_a.empty?
12
+ end
13
+
14
+ test "standardization" do
15
+ assert @roles.to_a == [:admin, :editor, :viewer]
16
+ end
17
+
18
+ test "include?" do
19
+ assert @roles.include?(:admin)
20
+ end
21
+
22
+ test "include? is case insensitive" do
23
+ assert @roles.include?("EDITOR")
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ require "simplecov"
2
+ SimpleCov.start
3
+ SimpleCov.command_name "mt"
4
+
5
+ require_relative "../lib/roleup"
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roleup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Hopkins
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: micro_test
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Simple role management
56
+ email:
57
+ - natehop@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/roleup.rb
63
+ - lib/roleup/has_roles.rb
64
+ - lib/roleup/list.rb
65
+ - lib/roleup/version.rb
66
+ - test/has_roles_test.rb
67
+ - test/list_test.rb
68
+ - test/test_helper.rb
69
+ homepage: https://github.com/hopsoft/roleup
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.2.2
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Simple role management
93
+ test_files:
94
+ - test/has_roles_test.rb
95
+ - test/list_test.rb
96
+ - test/test_helper.rb