acts_as_owner 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/README.md +85 -0
  2. data/VERSION.yml +1 -1
  3. data/acts_as_owner.gemspec +2 -2
  4. metadata +39 -34
  5. data/README.rdoc +0 -79
@@ -0,0 +1,85 @@
1
+ Acts as owner
2
+ =============
3
+
4
+ Acts as owner is a plugin for Ruby on Rails that provides to an owner object the
5
+ ability to self-query about the possession of an ownable object.
6
+
7
+ Ownable objects can be any objects belonging to the owner object and any objects
8
+ belonging to an ownable object.
9
+
10
+ Any ownable child, which belongs to an owned ownable parent, is also owned by
11
+ the owner.
12
+
13
+ Philosophy
14
+ ----------
15
+
16
+ General library that does only one thing, without any feature.
17
+
18
+ Installation
19
+ ------------
20
+
21
+ Include the gem in your `Gemfile`:
22
+
23
+ gem 'acts_as_owner'
24
+
25
+ And run the `bundle` command. Or as a plugin:
26
+
27
+ rails plugin install git://github.com/cyril/acts_as_owner.git
28
+
29
+ Getting started
30
+ ---------------
31
+
32
+ ### Configuring models
33
+
34
+ Owner models just have to be declared thanks to `acts_as_owner`, with each
35
+ ownable object passed through a block (using `owns_one` or `owns_many` method).
36
+
37
+ Example
38
+ -------
39
+
40
+ ``` ruby
41
+ class User < ActiveRecord::Base
42
+ acts_as_owner do |u|
43
+ u.owns_many :articles
44
+ u.owns_many :comments
45
+ end
46
+
47
+ with_options(dependent: :destroy) do |opts|
48
+ opts.has_many :articles
49
+ opts.has_many :comments
50
+ end
51
+ end
52
+
53
+ class Article < ActiveRecord::Base
54
+ belongs_to :user
55
+ has_many :comments, dependent: :destroy
56
+ end
57
+
58
+ class Comment < ActiveRecord::Base
59
+ belongs_to :article
60
+ belongs_to :user
61
+ end
62
+
63
+ # An article should be ownable by a user, so:
64
+ User.could_own_an?(:article) # => true
65
+
66
+ # Considering this one:
67
+ article = current_user.articles.first
68
+
69
+ # We can see that:
70
+ current_user.owns? article # => true
71
+
72
+ # Now, considering its first comment:
73
+ comment = article.comments.first
74
+
75
+ # Just like article, we can check that:
76
+ User.could_own_an? :comment # => true
77
+
78
+ # Let's see if the current user is the author:
79
+ current_user == comment.user # => false
80
+
81
+ # Never mind. It belongs to his article so that's also his one:
82
+ current_user.owns? comment # => true
83
+ ```
84
+
85
+ Copyright (c) 2009-2011 Cyril Wack, released under the MIT license
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 2
3
3
  :minor: 0
4
- :patch: 0
4
+ :patch: 1
@@ -1,9 +1,9 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "acts_as_owner"
3
- s.version = Psych.load_file("VERSION.yml").values.join('.')
3
+ s.version = YAML.load_file("VERSION.yml").values.join('.')
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ["Cyril Wack"]
6
- s.email = ["cyril@gosu.fr"]
6
+ s.email = ["contact@cyril.io"]
7
7
  s.homepage = "http://github.com/cyril/acts_as_owner"
8
8
  s.summary = %q{Simple ownership solution for Rails.}
9
9
  s.description = %q{Simple Rails plugin that allows to operate freely on objects which belong to us.}
metadata CHANGED
@@ -1,40 +1,43 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: acts_as_owner
3
- version: !ruby/object:Gem::Version
4
- version: 2.0.0
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
5
+ version: 2.0.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Cyril Wack
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-04-22 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
12
+
13
+ date: 2011-08-29 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
15
16
  name: railties
16
- requirement: &2153341400 !ruby/object:Gem::Requirement
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
17
19
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
21
23
  version: 3.0.0
22
24
  type: :runtime
23
- prerelease: false
24
- version_requirements: *2153341400
25
- description: Simple Rails plugin that allows to operate freely on objects which belong
26
- to us.
27
- email:
28
- - cyril@gosu.fr
25
+ version_requirements: *id001
26
+ description: Simple Rails plugin that allows to operate freely on objects which belong to us.
27
+ email:
28
+ - contact@cyril.io
29
29
  executables: []
30
+
30
31
  extensions: []
32
+
31
33
  extra_rdoc_files: []
32
- files:
34
+
35
+ files:
33
36
  - .gitignore
34
37
  - .rvmrc
35
38
  - Gemfile
36
39
  - MIT-LICENSE
37
- - README.rdoc
40
+ - README.md
38
41
  - Rakefile
39
42
  - VERSION.yml
40
43
  - acts_as_owner.gemspec
@@ -44,28 +47,30 @@ files:
44
47
  - test/test_helper.rb
45
48
  homepage: http://github.com/cyril/acts_as_owner
46
49
  licenses: []
50
+
47
51
  post_install_message:
48
52
  rdoc_options: []
49
- require_paths:
53
+
54
+ require_paths:
50
55
  - lib
51
- required_ruby_version: !ruby/object:Gem::Requirement
56
+ required_ruby_version: !ruby/object:Gem::Requirement
52
57
  none: false
53
- requirements:
54
- - - ! '>='
55
- - !ruby/object:Gem::Version
56
- version: '0'
57
- required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
63
  none: false
59
- requirements:
60
- - - ! '>='
61
- - !ruby/object:Gem::Version
62
- version: '0'
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
63
68
  requirements: []
69
+
64
70
  rubyforge_project: acts_as_owner
65
- rubygems_version: 1.7.2
71
+ rubygems_version: 1.8.9
66
72
  signing_key:
67
73
  specification_version: 3
68
74
  summary: Simple ownership solution for Rails.
69
- test_files:
70
- - test/owner_test.rb
71
- - test/test_helper.rb
75
+ test_files: []
76
+
@@ -1,79 +0,0 @@
1
- = Acts as owner
2
-
3
- Acts as owner is a plugin for Ruby on Rails that provides to an owner object the
4
- ability to self-query about the possession of an ownable object.
5
-
6
- Ownable objects can be any objects belonging to the owner object and any objects
7
- belonging to an ownable object.
8
-
9
- Any ownable child, which belongs to an owned ownable parent, is also owned by
10
- the owner.
11
-
12
- == Philosophy
13
-
14
- General library that does only one thing, without any feature.
15
-
16
- == Installation
17
-
18
- Include the gem in your <tt>Gemfile</tt>:
19
-
20
- gem 'acts_as_owner'
21
-
22
- And run the +bundle+ command. Or as a plugin:
23
-
24
- rails plugin install git://github.com/cyril/acts_as_owner.git
25
-
26
- == Getting started
27
-
28
- === Configuring models
29
-
30
- Owner models just have to be declared thanks to <tt>acts_as_owner</tt>, with
31
- each ownable object passed through a block (using <tt>owns_one</tt> or
32
- <tt>owns_many</tt> method).
33
-
34
- == Example
35
-
36
- class User < ActiveRecord::Base
37
- acts_as_owner do |u|
38
- u.owns_many :articles
39
- u.owns_many :comments
40
- end
41
-
42
- with_options :dependent => :destroy do |opts|
43
- opts.has_many :articles
44
- opts.has_many :comments
45
- end
46
- end
47
-
48
- class Article < ActiveRecord::Base
49
- belongs_to :user
50
- has_many :comments, :dependent => :destroy
51
- end
52
-
53
- class Comment < ActiveRecord::Base
54
- belongs_to :article
55
- belongs_to :user
56
- end
57
-
58
- # An article should be ownable by a user, so:
59
- User.could_own_an?(:article) # => true
60
-
61
- # Considering this one:
62
- article = current_user.articles.first
63
-
64
- # We can see that:
65
- current_user.owns? article # => true
66
-
67
- # Now, considering its first comment:
68
- comment = article.comments.first
69
-
70
- # Just like article, we can check that:
71
- User.could_own_an? :comment # => true
72
-
73
- # Let's see if the current user is the author:
74
- current_user == comment.user # => false
75
-
76
- # Never mind. It belongs to his article so that's also his one:
77
- current_user.owns? comment # => true
78
-
79
- Copyright (c) 2009-2011 Cyril Wack, released under the MIT license