concerned 0.1.1 → 0.1.2
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.
- data/README.md +18 -0
- data/VERSION +1 -1
- data/concerned.gemspec +2 -2
- data/lib/concerned/module_ext.rb +9 -0
- data/lib/concerned.rb +20 -0
- data/spec/concerned_spec.rb +7 -0
- data/spec/fixture_user/validations.rb +8 -0
- metadata +3 -3
data/README.md
CHANGED
@@ -46,6 +46,24 @@ class Project
|
|
46
46
|
end
|
47
47
|
```
|
48
48
|
|
49
|
+
## Concerns currently included
|
50
|
+
|
51
|
+
You can now include the Concerned module in your class or module and get acces to the meta-info: which concerns are currently included
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
class FixtureUser
|
55
|
+
include Concerned
|
56
|
+
include_concerns :scopes, :validations
|
57
|
+
include_shared_concerns :caching
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
FixtureUser.my_concerns # => [:scopes, :validations]
|
63
|
+
FixtureUser.my_shared_concerns # => [:caching]
|
64
|
+
FixtureUser.all_my_shared_concerns # => [:scopes, :validations, :caching]
|
65
|
+
```
|
66
|
+
|
49
67
|
## Global config
|
50
68
|
|
51
69
|
You can use the `Concerned.extend_enable!` to let the concern helpers also attempt to extend the host module/class with the ClassMethods module of the concerns module (if such exists). Disable it by using: `Concerned.extend_disable!`
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/concerned.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "concerned"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kristian Mandrup"]
|
12
|
-
s.date = "2012-05-
|
12
|
+
s.date = "2012-05-31"
|
13
13
|
s.description = "Makes it easy to apply the concerns pattern in any Ruby context"
|
14
14
|
s.email = "kmandrup@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/concerned/module_ext.rb
CHANGED
@@ -30,6 +30,11 @@ class Module
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
34
|
+
class_eval do
|
35
|
+
self.my_concerns += concerns.flatten if self.respond_to?(:my_concerns)
|
36
|
+
end
|
37
|
+
|
33
38
|
include_shared_concerns([options[:shared]].flatten.compact)
|
34
39
|
end
|
35
40
|
|
@@ -48,6 +53,10 @@ class Module
|
|
48
53
|
end
|
49
54
|
end
|
50
55
|
end
|
56
|
+
|
57
|
+
class_eval do
|
58
|
+
self.my_shared_concerns += concerns.flatten if self.respond_to?(:shared_concerns)
|
59
|
+
end
|
51
60
|
end
|
52
61
|
|
53
62
|
alias_method :shared_concern, :shared_concerns
|
data/lib/concerned.rb
CHANGED
@@ -1,6 +1,26 @@
|
|
1
1
|
require 'concerned/module_ext'
|
2
2
|
|
3
3
|
module Concerned
|
4
|
+
def self.included(base)
|
5
|
+
base.extend MetaMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module MetaMethods
|
9
|
+
attr_writer :my_concerns, :my_shared_concerns
|
10
|
+
|
11
|
+
def all_my_concerns
|
12
|
+
my_concerns + my_shared_concerns
|
13
|
+
end
|
14
|
+
|
15
|
+
def my_concerns
|
16
|
+
@my_concerns ||= []
|
17
|
+
end
|
18
|
+
|
19
|
+
def my_shared_concerns
|
20
|
+
@my_shared_concerns ||= []
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
4
24
|
class << self
|
5
25
|
def require_shared concern
|
6
26
|
require_method "shared/#{concern.to_s.underscore}"
|
data/spec/concerned_spec.rb
CHANGED
@@ -7,9 +7,12 @@ require 'active_support/dependencies'
|
|
7
7
|
$:.unshift File.dirname __FILE__
|
8
8
|
|
9
9
|
class FixtureUser
|
10
|
+
include Concerned
|
11
|
+
|
10
12
|
concerned_with :scopes, :validations
|
11
13
|
shared_concerns :associations
|
12
14
|
include_shared_concerns :caching
|
15
|
+
include_concerns :validations
|
13
16
|
end
|
14
17
|
|
15
18
|
describe "Concerned" do
|
@@ -18,6 +21,10 @@ describe "Concerned" do
|
|
18
21
|
[:scopes, :validations].each do |concern|
|
19
22
|
FixtureUser.new.should respond_to("method_from_#{concern}_concern")
|
20
23
|
end
|
24
|
+
|
25
|
+
FixtureUser.my_concerns.should include(:validations)
|
26
|
+
FixtureUser.my_shared_concerns.should include(:caching)
|
27
|
+
FixtureUser.all_my_concerns.should include(:caching, :validations)
|
21
28
|
end
|
22
29
|
end
|
23
30
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: concerned
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -131,7 +131,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
131
131
|
version: '0'
|
132
132
|
segments:
|
133
133
|
- 0
|
134
|
-
hash:
|
134
|
+
hash: 3508759223266208615
|
135
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
136
|
none: false
|
137
137
|
requirements:
|