fabrik 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -0
- data/lib/fabrik/trait.rb +8 -0
- data/lib/fabrik/version.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d50882d05566d3149871ec470c38903cc312431
|
4
|
+
data.tar.gz: 6d3acb7860899bef215588d6b9ad5b0c2d49a3e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cceb98334b134370f30143d06fea88a9c2820f29aa68b82f0126bbea7f606dcd4f6d1b5a4091deccc9fe429269c750ec4092521a5f650a89759a12770f567ef
|
7
|
+
data.tar.gz: 749bf0cc72f504f847edc2240511fb1d8e7529bd93c5482f8bcb3273323f1caecbccd0d1d75f8125708b8dd70567e14b9e64bb0a575b74c6dd3d9ca487862db2
|
data/README.md
CHANGED
@@ -49,6 +49,15 @@ class Lion
|
|
49
49
|
end
|
50
50
|
```
|
51
51
|
|
52
|
+
Alternatively, a trait can be created with `Fabrik::Trait.build`.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
Lion = Fabrik::Trait.build do
|
56
|
+
def mother; :lioness end
|
57
|
+
def father; :lion end
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
52
61
|
A class uses traits by extending `Fabrik::Composer` and composing the traits.
|
53
62
|
|
54
63
|
```ruby
|
@@ -83,6 +92,25 @@ tigon.mother # => :lioness
|
|
83
92
|
tigon.father # => :tiger
|
84
93
|
```
|
85
94
|
|
95
|
+
Traits can be composed from other traits in the same way:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
class TigonTrait
|
99
|
+
extend Fabrik::Trait
|
100
|
+
compose Panthera,
|
101
|
+
Tiger[exclude: :mother],
|
102
|
+
Lion[exclude: :father]
|
103
|
+
end
|
104
|
+
```
|
105
|
+
|
106
|
+
Or by using `.build`:
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
TigonTrait = Fabrik::Trait.build(Panthera, Tiger[exclude: :mother], Lion[exclude: :father]) do
|
110
|
+
def scratch; :scratched end
|
111
|
+
end
|
112
|
+
```
|
113
|
+
|
86
114
|
View the specs for further examples, including composable traits and traits
|
87
115
|
that provide methods from shared modules.
|
88
116
|
|
data/lib/fabrik/trait.rb
CHANGED
@@ -9,6 +9,14 @@ module Fabrik
|
|
9
9
|
extend Forwardable
|
10
10
|
def_delegators :own, :instance_methods, :send
|
11
11
|
|
12
|
+
def self.build(*args, &blk)
|
13
|
+
Class.new do
|
14
|
+
extend Trait
|
15
|
+
compose(*args) if args.count > 0
|
16
|
+
provides(&blk) if blk
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
12
20
|
def methods(opts = {})
|
13
21
|
provides_from(own, *own.instance_methods)
|
14
22
|
dictionary.method_map(opts)
|
data/lib/fabrik/version.rb
CHANGED
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fabrik
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Corcoran
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
27
|
description: |
|
@@ -33,15 +33,15 @@ executables: []
|
|
33
33
|
extensions: []
|
34
34
|
extra_rdoc_files: []
|
35
35
|
files:
|
36
|
-
- LICENSE.txt
|
37
|
-
- README.md
|
38
|
-
- lib/fabrik.rb
|
39
36
|
- lib/fabrik/composer.rb
|
40
37
|
- lib/fabrik/dictionary.rb
|
41
38
|
- lib/fabrik/errors.rb
|
42
39
|
- lib/fabrik/resolver.rb
|
43
40
|
- lib/fabrik/trait.rb
|
44
41
|
- lib/fabrik/version.rb
|
42
|
+
- lib/fabrik.rb
|
43
|
+
- README.md
|
44
|
+
- LICENSE.txt
|
45
45
|
homepage: http://github.com/joecorcoran/fabrik
|
46
46
|
licenses:
|
47
47
|
- MIT
|
@@ -52,17 +52,17 @@ require_paths:
|
|
52
52
|
- lib
|
53
53
|
required_ruby_version: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
|
-
- -
|
55
|
+
- - '>='
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: '0'
|
58
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - '>='
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
requirements: []
|
64
64
|
rubyforge_project:
|
65
|
-
rubygems_version: 2.
|
65
|
+
rubygems_version: 2.0.14
|
66
66
|
signing_key:
|
67
67
|
specification_version: 4
|
68
68
|
summary: Traits for Ruby 2
|