acts_as 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/README.md +5 -7
- data/lib/acts_as/version.rb +1 -1
- data/lib/acts_as.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ba14af8fa70697f7fb73d98603803dba5d45960
|
4
|
+
data.tar.gz: af54cf74f118c481339507a63edc61e11583ea24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0749e06b1dd10faff18141970375ff3311940f50ba599cfaae50b0cbd15f5ce9e92ba976e73931a834a923d24aeb78c9c9cea0c17b5e8aaaec002f052b91df6
|
7
|
+
data.tar.gz: 23d6dbd8a70960c27ba5019c1fa14dc867c89103ea3112010775df02afaab10539829dd8e059f7fe9e5f18f175743b36e863aa23772d7f4cc2b3235c5722bd05
|
data/README.md
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# ActsAs
|
2
2
|
|
3
|
-
|
3
|
+
Essentially, this is just a wrapper around the usual [ActiveRecord::Assocations::Classmethods#belongs_to](http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-belongs_to) that inlines delegation of all active_record attribute setters/getters/helpers (with prefix support) and any additional methods, thus serving as a proxy for another table and model.
|
4
4
|
|
5
5
|
* Transparently write to multiple tables from one active record model by proxying attributes and their methods through a second model.
|
6
6
|
* Easily extract a new table from an existing table, but keep the existing API intact without breaking any consumers.
|
7
7
|
* When using STI to maintain easy joins, this is an easy way to proxy unique child attributes through to another table for that child
|
8
|
+
* Can help you enforce the [Law of Demeter](http://en.wikipedia.org/wiki/Law_of_Demeter)
|
8
9
|
|
9
10
|
This is designed for any belongs_to relationship where lifecycles are tightly coupled and proxying of attribute helpers from belongs_to -> has_one is desired.
|
10
11
|
|
@@ -16,14 +17,10 @@ Add this line to your application's Gemfile:
|
|
16
17
|
|
17
18
|
gem 'acts_as'
|
18
19
|
|
19
|
-
And then
|
20
|
+
And then:
|
20
21
|
|
21
22
|
$ bundle
|
22
23
|
|
23
|
-
Or install it yourself as:
|
24
|
-
|
25
|
-
$ gem install acts_as
|
26
|
-
|
27
24
|
## Usage
|
28
25
|
|
29
26
|
```ruby
|
@@ -93,7 +90,8 @@ How does the active record join hash-parsing stuff work? EX-
|
|
93
90
|
Rebel.joins(:clan).where(clan: {cool: true)
|
94
91
|
|
95
92
|
Can we make this work for ruby-sql autojoins? Is that even a good idea?
|
96
|
-
|
93
|
+
|
94
|
+
Rebel.where(cool: true) #auto-joins :clan and queries clans table
|
97
95
|
|
98
96
|
## Contributing
|
99
97
|
|
data/lib/acts_as/version.rb
CHANGED
data/lib/acts_as.rb
CHANGED
@@ -24,7 +24,7 @@ module ActsAs
|
|
24
24
|
belongs_to(association, **options.merge(autosave: true))
|
25
25
|
define_method(association) { |*args| super(*args) || send("build_#{association}", *args) }
|
26
26
|
|
27
|
-
if (association_class =
|
27
|
+
if (association_class = (options[:class_name] || association).to_s.camelcase.constantize).table_exists?
|
28
28
|
whitelist_and_delegate_fields(association_class, association, prefix, with)
|
29
29
|
override_method_missing
|
30
30
|
end
|