disposable 0.0.6 → 0.0.7
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/CHANGES.md +4 -0
- data/README.md +40 -54
- data/database.sqlite3 +0 -0
- data/disposable.gemspec +5 -5
- data/gemfiles/Gemfile.rails-3.0.lock +8 -12
- data/gemfiles/Gemfile.rails-3.2.lock +5 -9
- data/gemfiles/Gemfile.rails-4.0 +1 -0
- data/gemfiles/Gemfile.rails-4.0.lock +16 -20
- data/gemfiles/Gemfile.rails-4.1.lock +19 -23
- data/lib/disposable/composition.rb +3 -0
- data/lib/disposable/twin.rb +24 -164
- data/lib/disposable/twin/composition.rb +27 -0
- data/lib/disposable/twin/new.rb +30 -0
- data/lib/disposable/twin/option.rb +2 -16
- data/lib/disposable/twin/representer.rb +29 -0
- data/lib/disposable/twin/save.rb +43 -0
- data/lib/disposable/twin/save_.rb +21 -0
- data/lib/disposable/twin/struct.rb +14 -0
- data/lib/disposable/version.rb +1 -1
- data/test/test_helper.rb +3 -3
- data/test/twin/composition_test.rb +35 -27
- data/test/twin/twin_test.rb +66 -85
- metadata +14 -52
- data/test/twin/active_record_test.rb +0 -227
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0961ea267a9adeeb55f33da903f0bd85e21070f4
|
4
|
+
data.tar.gz: f3ff1a24210acaaa96a933d3889ccee74c4db7b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb3cbf404ad41a23dd6b25aa6fc49029a5d0e1ec75d657eed33440c1acb8ee5c2915048ecf1b2bf3c2737d5abf8c285ded7770cff552f3c5205a73e897a307b0
|
7
|
+
data.tar.gz: c96c0291615cfe64633d8a155b417fcf506eb306b14e968fe36c6001166f2acecce25f9b1f60bc51f1206f71264e75907186c2eb6719e3a09768a96568f82f85
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Disposable
|
2
2
|
|
3
|
-
|
3
|
+
_Decorators on top of your ORM layer._
|
4
4
|
|
5
5
|
## Introduction
|
6
6
|
|
@@ -14,101 +14,87 @@ They give you an encapsulated alternative to delegators that many projects use t
|
|
14
14
|
|
15
15
|
## Why?
|
16
16
|
|
17
|
-
The goal is to have
|
18
|
-
|
19
|
-
Beyond that, twins can be used in form objects, cells view models, representers, contracts, and actually any Ruby code :)
|
17
|
+
The goal is to have one object that delegates reading and writing to underlying object(s). This is a fundamental concept for cells view models, representers, and reform form objects.
|
20
18
|
|
21
19
|
Twins may contain validations, nevertheless, in Trailblazer, validations (or "Contracts") sit one layer above. They still can be part of your domain, though.
|
22
20
|
|
23
21
|
## Twin
|
24
22
|
|
25
|
-
Twins implement light-weight
|
23
|
+
Twins implement light-weight decorators objects with a unified interface. They map objects, hashes, and compositions of objects, along with optional hashes to inject additional options.
|
26
24
|
|
27
|
-
|
25
|
+
Let me show you what I mean.
|
28
26
|
|
29
27
|
```ruby
|
30
|
-
|
31
|
-
belongs_to :album
|
32
|
-
end
|
28
|
+
song = Song.create(title: "Savior", length: 242)
|
33
29
|
```
|
34
30
|
|
35
|
-
|
31
|
+
## Definition
|
36
32
|
|
37
|
-
|
33
|
+
Twins need to define every field they expose.
|
38
34
|
|
39
35
|
```ruby
|
40
|
-
class Twin
|
41
|
-
model ::Song # the persistent ActiveRecord brother class
|
42
|
-
|
36
|
+
class Song::Twin < Disposable::Twin
|
43
37
|
property :title
|
44
|
-
property :
|
38
|
+
property :length
|
39
|
+
option :good?
|
40
|
+
end
|
45
41
|
```
|
46
42
|
|
43
|
+
## Creation
|
47
44
|
|
48
|
-
|
49
|
-
|
50
|
-
You can create fresh, blank-slate twins yourself. They will create a new persistent object automatically.
|
45
|
+
You need to pass model and the optional options to the twin constructor.
|
51
46
|
|
52
47
|
```ruby
|
53
|
-
|
54
|
-
|
55
|
-
#=> #<Twin::Song title: "Justified Black Eye">
|
48
|
+
twin = Song::Twin.new(song, good?: true)
|
56
49
|
```
|
57
50
|
|
58
|
-
|
51
|
+
## Reading
|
59
52
|
|
60
|
-
|
61
|
-
### Finders
|
62
|
-
|
63
|
-
You can use any finder/scope defined in your model to create twins.
|
64
|
-
|
65
|
-
Since `::find` is pretty common, it is defined directly on the twin class.
|
53
|
+
This will create a composition object of the actual model and the hash.
|
66
54
|
|
67
55
|
```ruby
|
68
|
-
|
69
|
-
|
70
|
-
#=> #<Twin::Song title: "Already Won" album: #<Twin::Album>>
|
56
|
+
twin.title #=> "Savior"
|
57
|
+
twin.good? #=> true
|
71
58
|
```
|
72
59
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
Any other scope or finder can be called on `finders`.
|
60
|
+
You can also override `property` values in the constructor:
|
77
61
|
|
78
62
|
```ruby
|
79
|
-
|
80
|
-
|
81
|
-
#=> [#<Twin::Song title: "3 O'Clock Shot" album: #<Twin::Album>>]
|
63
|
+
twin = Song::Twin.new(song, title: "Plasticash")
|
64
|
+
twin.title #=> "Plasticash"
|
82
65
|
```
|
83
66
|
|
67
|
+
Let's talk about what happens to the actual model when setting values?
|
84
68
|
|
69
|
+
## Writing
|
85
70
|
|
86
|
-
|
71
|
+
It doesn't happen. The model is only queried when _reading_ values. Writing only happens in additional modules: Syncing and Saving is where the values held in the twin are written to the model.
|
87
72
|
|
88
|
-
|
73
|
+
## Renaming
|
89
74
|
|
90
|
-
|
91
|
-
song.title #=> "Already Won"
|
75
|
+
## Structs
|
92
76
|
|
93
|
-
|
77
|
+
If you don't have a model but a simple hash, use `Struct`.
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
class Song::Twin < Disposable::Twin
|
81
|
+
include Struct
|
82
|
+
property :title
|
83
|
+
property :length
|
84
|
+
end
|
94
85
|
```
|
95
86
|
|
96
|
-
Note that
|
87
|
+
Note that a hash goes into the constructor now.
|
97
88
|
|
98
89
|
```ruby
|
99
|
-
|
90
|
+
twin = Song::Twin.new(title: "Savior", good?: true)
|
100
91
|
```
|
101
92
|
|
102
93
|
|
103
|
-
|
104
|
-
|
105
|
-
Calling `#save` will sync all properties to the brother object and advice the persistent brother to save. This works recursively, meaning that nested twins will do the same with their pendant.
|
94
|
+
## Compositions
|
106
95
|
|
107
|
-
|
108
|
-
song.save # write to DB.
|
109
|
-
```
|
96
|
+
## Overriding Accessors
|
110
97
|
|
111
|
-
|
98
|
+
super
|
112
99
|
|
113
|
-
|
114
|
-
* Lazy-loading TBI
|
100
|
+
## Used In
|
data/database.sqlite3
CHANGED
Binary file
|
data/disposable.gemspec
CHANGED
@@ -19,12 +19,12 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency "uber"
|
22
|
-
spec.add_dependency "representable", "~> 2.0
|
22
|
+
spec.add_dependency "representable", "~> 2.0"
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
25
25
|
spec.add_development_dependency "rake"
|
26
|
-
spec.add_development_dependency "minitest"
|
27
|
-
spec.add_development_dependency "activerecord"
|
28
|
-
spec.add_development_dependency "sqlite3"
|
29
|
-
spec.add_development_dependency "database_cleaner"
|
26
|
+
spec.add_development_dependency "minitest", "5.4.1"
|
27
|
+
# spec.add_development_dependency "activerecord"
|
28
|
+
# spec.add_development_dependency "sqlite3"
|
29
|
+
# spec.add_development_dependency "database_cleaner"
|
30
30
|
end
|
@@ -31,13 +31,12 @@ GEM
|
|
31
31
|
activesupport (3.0.20)
|
32
32
|
arel (2.0.10)
|
33
33
|
builder (2.1.2)
|
34
|
-
database_cleaner (1.3.0)
|
35
34
|
erubis (2.6.6)
|
36
35
|
abstract (>= 1.0.0)
|
37
|
-
i18n (0.5.
|
38
|
-
json (1.8.
|
36
|
+
i18n (0.5.4)
|
37
|
+
json (1.8.1)
|
39
38
|
mini_portile (0.6.0)
|
40
|
-
minitest (5.
|
39
|
+
minitest (5.4.1)
|
41
40
|
multi_json (1.10.1)
|
42
41
|
nokogiri (1.6.3.1)
|
43
42
|
mini_portile (= 0.6.0)
|
@@ -52,17 +51,16 @@ GEM
|
|
52
51
|
rake (>= 0.8.7)
|
53
52
|
rdoc (~> 3.4)
|
54
53
|
thor (~> 0.14.4)
|
55
|
-
rake (10.
|
54
|
+
rake (10.3.2)
|
56
55
|
rdoc (3.12.2)
|
57
56
|
json (~> 1.4)
|
58
|
-
representable (2.0.
|
57
|
+
representable (2.0.4)
|
59
58
|
multi_json
|
60
59
|
nokogiri
|
61
60
|
uber (~> 0.0.7)
|
62
|
-
sqlite3 (1.3.8)
|
63
61
|
thor (0.14.6)
|
64
|
-
tzinfo (0.3.
|
65
|
-
uber (0.0.
|
62
|
+
tzinfo (0.3.41)
|
63
|
+
uber (0.0.8)
|
66
64
|
|
67
65
|
PLATFORMS
|
68
66
|
ruby
|
@@ -70,9 +68,7 @@ PLATFORMS
|
|
70
68
|
DEPENDENCIES
|
71
69
|
activerecord (~> 3.0.11)
|
72
70
|
bundler (~> 1.3)
|
73
|
-
database_cleaner
|
74
71
|
disposable!
|
75
|
-
minitest
|
72
|
+
minitest (= 5.4.1)
|
76
73
|
railties (~> 3.0.11)
|
77
74
|
rake
|
78
|
-
sqlite3
|
@@ -31,14 +31,13 @@ GEM
|
|
31
31
|
multi_json (~> 1.0)
|
32
32
|
arel (3.0.3)
|
33
33
|
builder (3.0.4)
|
34
|
-
database_cleaner (1.3.0)
|
35
34
|
erubis (2.7.0)
|
36
35
|
hike (1.2.3)
|
37
36
|
i18n (0.6.11)
|
38
37
|
journey (1.0.4)
|
39
38
|
json (1.8.1)
|
40
39
|
mini_portile (0.6.0)
|
41
|
-
minitest (5.4.
|
40
|
+
minitest (5.4.1)
|
42
41
|
multi_json (1.10.1)
|
43
42
|
nokogiri (1.6.3.1)
|
44
43
|
mini_portile (= 0.6.0)
|
@@ -59,7 +58,7 @@ GEM
|
|
59
58
|
rake (10.3.2)
|
60
59
|
rdoc (3.12.2)
|
61
60
|
json (~> 1.4)
|
62
|
-
representable (2.0.
|
61
|
+
representable (2.0.4)
|
63
62
|
multi_json
|
64
63
|
nokogiri
|
65
64
|
uber (~> 0.0.7)
|
@@ -68,11 +67,10 @@ GEM
|
|
68
67
|
multi_json (~> 1.0)
|
69
68
|
rack (~> 1.0)
|
70
69
|
tilt (~> 1.1, != 1.3.0)
|
71
|
-
sqlite3 (1.3.9)
|
72
70
|
thor (0.19.1)
|
73
71
|
tilt (1.4.1)
|
74
|
-
tzinfo (0.3.
|
75
|
-
uber (0.0.
|
72
|
+
tzinfo (0.3.41)
|
73
|
+
uber (0.0.8)
|
76
74
|
|
77
75
|
PLATFORMS
|
78
76
|
ruby
|
@@ -80,9 +78,7 @@ PLATFORMS
|
|
80
78
|
DEPENDENCIES
|
81
79
|
activerecord (~> 3.2.0)
|
82
80
|
bundler (~> 1.3)
|
83
|
-
database_cleaner
|
84
81
|
disposable!
|
85
|
-
minitest
|
82
|
+
minitest (= 5.4.1)
|
86
83
|
railties (~> 3.2.0)
|
87
84
|
rake
|
88
|
-
sqlite3
|
data/gemfiles/Gemfile.rails-4.0
CHANGED
@@ -8,22 +8,22 @@ PATH
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actionpack (4.0.
|
12
|
-
activesupport (= 4.0.
|
11
|
+
actionpack (4.0.9)
|
12
|
+
activesupport (= 4.0.9)
|
13
13
|
builder (~> 3.1.0)
|
14
14
|
erubis (~> 2.7.0)
|
15
15
|
rack (~> 1.5.2)
|
16
16
|
rack-test (~> 0.6.2)
|
17
|
-
activemodel (4.0.
|
18
|
-
activesupport (= 4.0.
|
17
|
+
activemodel (4.0.9)
|
18
|
+
activesupport (= 4.0.9)
|
19
19
|
builder (~> 3.1.0)
|
20
|
-
activerecord (4.0.
|
21
|
-
activemodel (= 4.0.
|
20
|
+
activerecord (4.0.9)
|
21
|
+
activemodel (= 4.0.9)
|
22
22
|
activerecord-deprecated_finders (~> 1.0.2)
|
23
|
-
activesupport (= 4.0.
|
23
|
+
activesupport (= 4.0.9)
|
24
24
|
arel (~> 4.0.0)
|
25
25
|
activerecord-deprecated_finders (1.0.3)
|
26
|
-
activesupport (4.0.
|
26
|
+
activesupport (4.0.9)
|
27
27
|
i18n (~> 0.6, >= 0.6.9)
|
28
28
|
minitest (~> 4.2)
|
29
29
|
multi_json (~> 1.3)
|
@@ -31,32 +31,30 @@ GEM
|
|
31
31
|
tzinfo (~> 0.3.37)
|
32
32
|
arel (4.0.2)
|
33
33
|
builder (3.1.4)
|
34
|
-
database_cleaner (1.3.0)
|
35
34
|
erubis (2.7.0)
|
36
35
|
i18n (0.6.11)
|
37
36
|
mini_portile (0.6.0)
|
38
|
-
minitest (4.
|
37
|
+
minitest (4.2.0)
|
39
38
|
multi_json (1.10.1)
|
40
39
|
nokogiri (1.6.3.1)
|
41
40
|
mini_portile (= 0.6.0)
|
42
41
|
rack (1.5.2)
|
43
42
|
rack-test (0.6.2)
|
44
43
|
rack (>= 1.0)
|
45
|
-
railties (4.0.
|
46
|
-
actionpack (= 4.0.
|
47
|
-
activesupport (= 4.0.
|
44
|
+
railties (4.0.9)
|
45
|
+
actionpack (= 4.0.9)
|
46
|
+
activesupport (= 4.0.9)
|
48
47
|
rake (>= 0.8.7)
|
49
48
|
thor (>= 0.18.1, < 2.0)
|
50
49
|
rake (10.3.2)
|
51
|
-
representable (2.0.
|
50
|
+
representable (2.0.4)
|
52
51
|
multi_json
|
53
52
|
nokogiri
|
54
53
|
uber (~> 0.0.7)
|
55
|
-
sqlite3 (1.3.9)
|
56
54
|
thor (0.19.1)
|
57
55
|
thread_safe (0.3.4)
|
58
|
-
tzinfo (0.3.
|
59
|
-
uber (0.0.
|
56
|
+
tzinfo (0.3.41)
|
57
|
+
uber (0.0.8)
|
60
58
|
|
61
59
|
PLATFORMS
|
62
60
|
ruby
|
@@ -64,9 +62,7 @@ PLATFORMS
|
|
64
62
|
DEPENDENCIES
|
65
63
|
activerecord (~> 4.0.0)
|
66
64
|
bundler (~> 1.3)
|
67
|
-
database_cleaner
|
68
65
|
disposable!
|
69
|
-
minitest
|
66
|
+
minitest (~> 4.2.0)
|
70
67
|
railties (~> 4.0.0)
|
71
68
|
rake
|
72
|
-
sqlite3
|
@@ -8,23 +8,23 @@ PATH
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actionpack (4.1.
|
12
|
-
actionview (= 4.1.
|
13
|
-
activesupport (= 4.1.
|
11
|
+
actionpack (4.1.5)
|
12
|
+
actionview (= 4.1.5)
|
13
|
+
activesupport (= 4.1.5)
|
14
14
|
rack (~> 1.5.2)
|
15
15
|
rack-test (~> 0.6.2)
|
16
|
-
actionview (4.1.
|
17
|
-
activesupport (= 4.1.
|
16
|
+
actionview (4.1.5)
|
17
|
+
activesupport (= 4.1.5)
|
18
18
|
builder (~> 3.1)
|
19
19
|
erubis (~> 2.7.0)
|
20
|
-
activemodel (4.1.
|
21
|
-
activesupport (= 4.1.
|
20
|
+
activemodel (4.1.5)
|
21
|
+
activesupport (= 4.1.5)
|
22
22
|
builder (~> 3.1)
|
23
|
-
activerecord (4.1.
|
24
|
-
activemodel (= 4.1.
|
25
|
-
activesupport (= 4.1.
|
23
|
+
activerecord (4.1.5)
|
24
|
+
activemodel (= 4.1.5)
|
25
|
+
activesupport (= 4.1.5)
|
26
26
|
arel (~> 5.0.0)
|
27
|
-
activesupport (4.1.
|
27
|
+
activesupport (4.1.5)
|
28
28
|
i18n (~> 0.6, >= 0.6.9)
|
29
29
|
json (~> 1.7, >= 1.7.7)
|
30
30
|
minitest (~> 5.1)
|
@@ -32,34 +32,32 @@ GEM
|
|
32
32
|
tzinfo (~> 1.1)
|
33
33
|
arel (5.0.1.20140414130214)
|
34
34
|
builder (3.2.2)
|
35
|
-
database_cleaner (1.3.0)
|
36
35
|
erubis (2.7.0)
|
37
36
|
i18n (0.6.11)
|
38
37
|
json (1.8.1)
|
39
38
|
mini_portile (0.6.0)
|
40
|
-
minitest (5.4.
|
39
|
+
minitest (5.4.1)
|
41
40
|
multi_json (1.10.1)
|
42
41
|
nokogiri (1.6.3.1)
|
43
42
|
mini_portile (= 0.6.0)
|
44
43
|
rack (1.5.2)
|
45
44
|
rack-test (0.6.2)
|
46
45
|
rack (>= 1.0)
|
47
|
-
railties (4.1.
|
48
|
-
actionpack (= 4.1.
|
49
|
-
activesupport (= 4.1.
|
46
|
+
railties (4.1.5)
|
47
|
+
actionpack (= 4.1.5)
|
48
|
+
activesupport (= 4.1.5)
|
50
49
|
rake (>= 0.8.7)
|
51
50
|
thor (>= 0.18.1, < 2.0)
|
52
51
|
rake (10.3.2)
|
53
|
-
representable (2.0.
|
52
|
+
representable (2.0.4)
|
54
53
|
multi_json
|
55
54
|
nokogiri
|
56
55
|
uber (~> 0.0.7)
|
57
|
-
sqlite3 (1.3.9)
|
58
56
|
thor (0.19.1)
|
59
57
|
thread_safe (0.3.4)
|
60
|
-
tzinfo (1.2.
|
58
|
+
tzinfo (1.2.2)
|
61
59
|
thread_safe (~> 0.1)
|
62
|
-
uber (0.0.
|
60
|
+
uber (0.0.8)
|
63
61
|
|
64
62
|
PLATFORMS
|
65
63
|
ruby
|
@@ -67,9 +65,7 @@ PLATFORMS
|
|
67
65
|
DEPENDENCIES
|
68
66
|
activerecord (~> 4.1.0)
|
69
67
|
bundler (~> 1.3)
|
70
|
-
database_cleaner
|
71
68
|
disposable!
|
72
|
-
minitest
|
69
|
+
minitest (= 5.4.1)
|
73
70
|
railties (~> 4.1.0)
|
74
71
|
rake
|
75
|
-
sqlite3
|