mm-concerns 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -26,6 +26,3 @@ DEPENDENCIES
26
26
  jeweler (~> 1.5.1)
27
27
  rcov
28
28
  rspec (~> 2.1.0)
29
-
30
- METADATA
31
- version: 1.0.6
data/README.rdoc CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  A very simple mongomapper plugin that lets you organise your models into subdirectories
4
4
 
5
+ this code is a modification of code I saw in in [teambox](https://github.com/teambox/teambox)
6
+ https://github.com/teambox/teambox/blob/master/config/initializers/concerns.rb
7
+
5
8
 
6
9
  == Usage
7
10
 
@@ -18,19 +21,19 @@ Or add it to your Gemfile
18
21
  The ConcernsPlugin is automatically included in all your mongomapper documents.
19
22
 
20
23
  All thats left is to split your fat models up at logical breaking points and tell your base models to require the pieces.
24
+ The concerned_with method requires files from subdirectories with the same name as your model
21
25
 
22
26
  app/models/user.rb
23
27
 
24
28
  class User
25
29
  include MongoMapper::Document
30
+
31
+ concerned_with :validations, :scopes
26
32
 
27
33
  key :email, String
28
34
  key :first_name, String
29
35
  key :last_name, String
30
-
31
36
  key :active, Boolean, :default => false
32
-
33
- concerned_with :validation, :scopes
34
37
  end
35
38
 
36
39
  app/models/user/validations.rb
@@ -39,6 +42,7 @@ app/models/user/validations.rb
39
42
  validates_presence_of :email
40
43
  validates_presence_of :first_name
41
44
  validates_presence_of :last_name
45
+ belongs_to :organization
42
46
  end
43
47
 
44
48
  app/models/user/scopes.rb
@@ -46,8 +50,42 @@ app/models/user/scopes.rb
46
50
  class User
47
51
  scope :active, where( :active => true )
48
52
  scope :inactive, where( :active => false )
53
+ scope :for_project, lambda { |project| where( :id => { :$in => project.user_ids } ) }
49
54
  end
50
-
55
+
56
+ == Why?
57
+
58
+ I find this system of organizing my functionality make my codebase much quicker and easier to maintain.
59
+
60
+ I use this plugin to organize my models like so:
61
+
62
+ app/models/
63
+ |
64
+ |-- ability.rb
65
+ |
66
+ |-- membership.rb
67
+ |
68
+ |-- organization.rb
69
+ |
70
+ |-- project.rb
71
+ |
72
+ |-- project
73
+ | |-- associations.rb
74
+ | |-- callbacks.rb
75
+ | |-- scopes.rb
76
+ | `-- validations.rb
77
+ |
78
+ |-- user.rb
79
+ |
80
+ |-- user
81
+ |-- associations.rb
82
+ |-- authentication.rb
83
+ |-- scopes.rb
84
+ `-- validations.rb
85
+
86
+
87
+ I'm be very interested to hear comments on this system, if this helps you out, or if you have a better way of organizing your code.
88
+
51
89
 
52
90
  == Contributing to mm-concerns
53
91
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
data/lib/mm-concerns.rb CHANGED
@@ -19,4 +19,5 @@ module ConcernsPluginAddition
19
19
  end
20
20
  end
21
21
 
22
- MongoMapper::Document.append_inclusions(ConcernsPluginAddition)
22
+ MongoMapper::Document.append_inclusions(ConcernsPluginAddition)
23
+ MongoMapper::EmbeddedDocument.append_inclusions(ConcernsPluginAddition)
data/mm-concerns.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mm-concerns}
8
- s.version = "1.0.0"
8
+ s.version = "1.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Luke Cunningham"]
12
- s.date = %q{2010-11-17}
12
+ s.date = %q{2010-12-18}
13
13
  s.description = %q{A very simple mongomapper plugin that lets you organise your models into subdirectories}
14
14
  s.email = %q{luke@icaruswings.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mm-concerns
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Luke Cunningham
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-17 00:00:00 +11:00
18
+ date: 2010-12-18 00:00:00 +11:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency