fromage 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/lib/fromage/version.rb +1 -1
- data/lib/mongoid/fromage.rb +10 -1
- metadata +9 -9
data/README.md
CHANGED
@@ -13,7 +13,7 @@ Install it with rubygems:
|
|
13
13
|
With bundler, add it to your `Gemfile`:
|
14
14
|
|
15
15
|
``` ruby
|
16
|
-
gem "fromage"
|
16
|
+
gem "fromage", require: 'mongoid/fromage'
|
17
17
|
```
|
18
18
|
|
19
19
|
## Usage
|
@@ -26,7 +26,7 @@ class Person
|
|
26
26
|
include Mongoid::Document
|
27
27
|
include Mongoid::Fromage
|
28
28
|
|
29
|
-
fromages :time_lord, :companion
|
29
|
+
fromages :time_lord, :companion, defaults: [:time_lord]
|
30
30
|
end
|
31
31
|
```
|
32
32
|
|
data/lib/fromage/version.rb
CHANGED
data/lib/mongoid/fromage.rb
CHANGED
@@ -8,7 +8,8 @@ module Mongoid
|
|
8
8
|
extend ::ActiveSupport::Concern
|
9
9
|
|
10
10
|
included do
|
11
|
-
|
11
|
+
class_attribute :fromage_defaults
|
12
|
+
field :roles, type: Array, default: lambda { Array(self.fromage_defaults) }
|
12
13
|
validate :roles, :valid_roles?
|
13
14
|
|
14
15
|
scope :any_role, lambda {|*role| any_in(:roles => role)}
|
@@ -53,8 +54,12 @@ module Mongoid
|
|
53
54
|
attr_accessor :roles
|
54
55
|
|
55
56
|
def fromages(*argv)
|
57
|
+
if argv.last.is_a?(Hash)
|
58
|
+
options = argv.pop
|
59
|
+
end
|
56
60
|
self.roles = argv
|
57
61
|
|
62
|
+
# define helper methods for roles
|
58
63
|
self.roles.each do |role|
|
59
64
|
define_method "#{role}?" do
|
60
65
|
self.has_role? role
|
@@ -68,6 +73,10 @@ module Mongoid
|
|
68
73
|
self.remove_role!(role)
|
69
74
|
end
|
70
75
|
end
|
76
|
+
|
77
|
+
if options && options.has_key?(:defaults)
|
78
|
+
self.fromage_defaults = options[:defaults]
|
79
|
+
end
|
71
80
|
end
|
72
81
|
end
|
73
82
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fromage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,14 +9,14 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: '0'
|
38
38
|
type: :development
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
46
|
description: Role model for mongoid.
|
@@ -63,18 +63,18 @@ require_paths:
|
|
63
63
|
required_ruby_version: !ruby/object:Gem::Requirement
|
64
64
|
none: false
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
70
|
none: false
|
71
71
|
requirements:
|
72
|
-
- -
|
72
|
+
- - '>='
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
requirements: []
|
76
76
|
rubyforge_project:
|
77
|
-
rubygems_version: 1.8.
|
77
|
+
rubygems_version: 1.8.25
|
78
78
|
signing_key:
|
79
79
|
specification_version: 3
|
80
80
|
summary: Role model for mongoid.
|