classproxy 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +30 -1
- data/lib/classproxy/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class-proxy
|
2
2
|
===========
|
3
3
|
|
4
|
-
A generic (
|
4
|
+
A generic (ActiveRecord compatible) class proxy to setup proxy methods for your classes.
|
5
5
|
|
6
6
|
## Using
|
7
7
|
|
@@ -10,6 +10,35 @@ provided by this gem.
|
|
10
10
|
|
11
11
|
### Example
|
12
12
|
|
13
|
+
#### Basic example
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
class UserDb
|
17
|
+
include MongoMapper::Document
|
18
|
+
include ClassProxy
|
19
|
+
|
20
|
+
primary_fetch { |args| where(args).first or (raise NotFound) }
|
21
|
+
fallback_fetch { |args| Octokit.user(args[:login]) }
|
22
|
+
|
23
|
+
key :name, String
|
24
|
+
key :login, String
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
> user = UserDb.fetch(login: 'heelhook')
|
30
|
+
=> #<UserDb _id: 779813, name: "Pablo Fernandez", login: "heelhook">
|
31
|
+
```
|
32
|
+
|
33
|
+
In this example the database will be hit with a `where(login: 'heelhook')` and
|
34
|
+
if it comes back empty `Octokit` will be used to retrieve the information requested.
|
35
|
+
|
36
|
+
The default action (overwritten with `after_fallback_fetch`, not used in this example)
|
37
|
+
is to return a new object of the parent class (`UserDb`) with the proper keys set,
|
38
|
+
in this example `:id`, `:name` and `:login`.
|
39
|
+
|
40
|
+
#### Detailed example
|
41
|
+
|
13
42
|
```ruby
|
14
43
|
class UserDb
|
15
44
|
include MongoMapper::Document
|
data/lib/classproxy/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: classproxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
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-12-
|
12
|
+
date: 2012-12-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -55,7 +55,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
55
|
version: '0'
|
56
56
|
segments:
|
57
57
|
- 0
|
58
|
-
hash:
|
58
|
+
hash: 1986855267871768364
|
59
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
60
|
none: false
|
61
61
|
requirements:
|