fromage 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+ #
3
+ module Fromage
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+
3
+ require 'active_support/concern'
4
+ require 'mongoid'
5
+
6
+ module Mongoid
7
+ module Fromage
8
+ extend ::ActiveSupport::Concern
9
+
10
+ included do
11
+ field :roles, type: Array, default: []
12
+ validate :roles, :valid_roles?
13
+
14
+ scope :any_role, lambda {|*role| any_in(:roles => role)}
15
+ scope :all_role, lambda {|*role| all_in(:roles => role)}
16
+ end
17
+
18
+ module InstanceMethods
19
+ def add_role(*roles)
20
+ self.roles += roles
21
+ end
22
+
23
+ def add_role!(*args)
24
+ self.add_role(*args)
25
+ self.save
26
+ end
27
+
28
+ def remove_role(role)
29
+ self.roles = self.roles.tap {|roles| roles.delete(role)}
30
+ end
31
+
32
+ def remove_role!(role)
33
+ self.remove_role(role)
34
+ self.save
35
+ end
36
+
37
+ def has_role?(role)
38
+ self.roles.include? role
39
+ end
40
+
41
+ def has_roles?(*args)
42
+ args.all? {|role| self.has_role?(role) }
43
+ end
44
+
45
+ protected
46
+
47
+ def valid_roles?
48
+ unless self.roles.all? {|roles| self.class.roles.include? roles }
49
+ errors.add(:roles, :not_included)
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ module ClassMethods
56
+ attr_accessor :roles
57
+
58
+ def fromages(*argv)
59
+ self.roles = *argv
60
+
61
+ self.roles.each do |role|
62
+ define_method "#{role}?" do
63
+ self.has_role? role
64
+ end
65
+
66
+ define_method "#{role}!" do
67
+ self.add_role!(role)
68
+ end
69
+
70
+ define_method "un_#{role}!" do
71
+ self.remove_role!(role)
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,3 @@
1
+ # encoding: utf-8
2
+
3
+ require 'mongoid/fromage'
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fromage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - chatgris
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &17583480 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.7'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *17583480
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ requirement: &17582960 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.1'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *17582960
36
+ - !ruby/object:Gem::Dependency
37
+ name: mongoid
38
+ requirement: &17582400 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '2.3'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *17582400
47
+ - !ruby/object:Gem::Dependency
48
+ name: bson_ext
49
+ requirement: &17581860 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *17581860
58
+ description: Role model for mongoid.
59
+ email: jboyer@af83.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - lib/fromage/version.rb
65
+ - lib/mongoid/fromage.rb
66
+ - lib/mongoid_fromage.rb
67
+ homepage: https://github.com/chatgris/fromage
68
+ licenses: []
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 1.8.10
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Role model for mongoid.
91
+ test_files: []