delegate_all_for 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -6
- data/lib/delegate_all_for.rb +1 -0
- data/lib/delegate_all_for/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
#
|
1
|
+
# delegate_all_for
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
the getter, setter, and predicate for each column.
|
3
|
+
The primary driver for creating this gem was to create an easy way to accomplish the
|
4
|
+
[Multiple Table Inheritance](http://techspry.com/ruby_and_rails/multiple-table-inheritance-in-rails-3/)
|
5
|
+
pattern in active record. delegate_all_for allows for easy [delegation](http://apidock.com/rails/Module/delegate)
|
6
|
+
of all the columns of an ActiveRecord association, including the getter, setter, and predicate for each column.
|
7
7
|
|
8
8
|
## Usage
|
9
9
|
|
@@ -11,7 +11,7 @@ the getter, setter, and predicate for each column.
|
|
11
11
|
class Parent < ActiveRecord::Base
|
12
12
|
has_one :child
|
13
13
|
# columns: name
|
14
|
-
delegate_all_for :child, except: [:sort], also_include: [:extra_method]
|
14
|
+
delegate_all_for :child, except: [:sort], also_include: [:extra_method], allow_nil: true
|
15
15
|
end
|
16
16
|
|
17
17
|
class Child < ActiveRecord::Base
|
@@ -49,3 +49,7 @@ Or install it yourself as:
|
|
49
49
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
50
50
|
4. Push to the branch (`git push origin my-new-feature`)
|
51
51
|
5. Create new Pull Request
|
52
|
+
|
53
|
+
## Credits
|
54
|
+
|
55
|
+
* Inspiration for how to do it came from [Delegating Your Attributes](http://killswitchcollective.com/articles/21_delegating_your_attributes)
|
data/lib/delegate_all_for.rb
CHANGED
@@ -21,6 +21,7 @@ module DelegateAllFor
|
|
21
21
|
# [:allow_nil]
|
22
22
|
# Allows accessor to be nil. See the <tt>delegate</tt> documentation.
|
23
23
|
def delegate_all_for(*attr_names)
|
24
|
+
return unless self.table_exists?
|
24
25
|
options = { except: [], also_include: [], prefix: false, allow_nil: false }
|
25
26
|
options.update(attr_names.extract_options!)
|
26
27
|
options.assert_valid_keys(:except, :also_include, :prefix, :allow_nil)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 9
|
9
|
+
version: 0.0.9
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jason Rust
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2013-03-13 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|