Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added for option to include from foreign scope

  • Loading branch information...
commit 688dd72fc6d191d21f5c61728acb5bc562ca5edc 1 parent 7f647e8
@kristianmandrup authored
View
12 README.md
@@ -64,6 +64,18 @@ FixtureUser.my_shared_concerns # => [:caching]
FixtureUser.all_my_shared_concerns # => [:scopes, :validations, :caching]
```
+You can even include concerns from another scope
+
+```ruby
+class FixtureUserFor
+ include Concerned
+ include_concerns :scopes, :validations, for: 'FixtureUser'
+ include_shared_concerns :caching
+end
+```
+
+Will include the `FixtureUser::Scopes` and `FixtureUser::Validations` into `FixtureUserFor` :)
+
## Global config
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!`
View
2  VERSION
@@ -1 +1 @@
-0.1.3
+0.1.4
View
7 lib/concerned/module_ext.rb
@@ -17,10 +17,13 @@ def shared_concerns(*concerns)
def include_concerns(*concerns)
options = concerns.extract_options!
+ scope_name = options[:for] ? options[:for] : name
concerns.flatten.each do |concern|
next if concern.blank?
- require_concern name, concern
- concern_ns = [name, concern.to_s.camelize].join('::')
+ require_concern scope_name, concern
+
+ concern_ns ||= [scope_name.to_s.camelize, concern.to_s.camelize].join('::')
+
self.send :include, concern_ns.constantize
if Concerned.extend_enabled?
View
11 spec/concerned_spec.rb
@@ -22,6 +22,17 @@ class FixtureUserNoMeta
include_concerns :validations
end
+class FixtureUserFor
+ include_concerns :foo, for: 'fixture_user'
+end
+
+describe "Concerned" do
+ describe "using :for" do
+ it 'should include Foo module' do
+ FixtureUserFor.new.should respond_to(:foo)
+ end
+ end
+end
describe "Concerned" do
describe "no meta" do
View
6 spec/fixture_user/foo.rb
@@ -0,0 +1,6 @@
+class FixtureUser
+ module Foo
+ def foo
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.