scrivener 0.4.1 → 1.0.0
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/CHANGELOG.md +33 -0
- data/README.md +2 -2
- data/lib/scrivener.rb +15 -7
- data/test/scrivener_test.rb +6 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d856e30f00eb2fbb898b1f436706d513921d7b6b
|
4
|
+
data.tar.gz: 2cee2565f0507e0ebf8177d2cb57626f683528c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 068427019df2072dc56517932811d744dd8fcbc4ad9842880382c9e8a3dfc46f118e066d24b73a51364dbbf6dcce42e5ffeb3d1121b714acf61e8066acff9c56
|
7
|
+
data.tar.gz: c2acd1812ffc52b268d1294c2c744cda6e92f17c5a0011e8777400b39215f276ce5ff43fbae5d1f1e17dcc440aaad160a83b851c224a1bd7b51e62f5bacfe29d
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
## 1.0.0
|
2
|
+
|
3
|
+
* Extra attributes are ignored.
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
# Before:
|
7
|
+
|
8
|
+
publish = Publish.new(status: "published", title: "foo")
|
9
|
+
publis.attributes # => { :status => "published" }
|
10
|
+
# => NoMethodError: undefined method `title=' for #<Publish...>
|
11
|
+
|
12
|
+
# Now:
|
13
|
+
|
14
|
+
# Extra fields are discarded
|
15
|
+
publish = Publish.new(status: "published", title: "foo")
|
16
|
+
publish.attributes # => { :status => "published" }
|
17
|
+
```
|
18
|
+
|
19
|
+
## 0.4.1
|
20
|
+
|
21
|
+
* Fix creation of symbols for extra attributes.
|
22
|
+
|
23
|
+
## 0.4.0
|
24
|
+
|
25
|
+
* Fix `assert_email` and `assert_url` to support longer tld's.
|
26
|
+
|
27
|
+
## 0.3.0
|
28
|
+
|
29
|
+
* Add support for negative numbers.
|
30
|
+
|
31
|
+
## 0.2.0
|
32
|
+
|
33
|
+
* Add `assert_equal` validation.
|
data/README.md
CHANGED
@@ -110,9 +110,9 @@ publish.valid? #=> true
|
|
110
110
|
|
111
111
|
article.update_attributes(publish.attributes)
|
112
112
|
|
113
|
-
#
|
113
|
+
# Extra fields are discarded
|
114
114
|
publish = Publish.new(status: "published", title: "foo")
|
115
|
-
#=>
|
115
|
+
publish.attributes #=> { :status => "published" }
|
116
116
|
```
|
117
117
|
|
118
118
|
Slices
|
data/lib/scrivener.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require_relative "scrivener/validations"
|
2
2
|
|
3
3
|
class Scrivener
|
4
|
-
VERSION = "0.
|
4
|
+
VERSION = "1.0.0"
|
5
5
|
|
6
6
|
include Validations
|
7
7
|
|
8
8
|
# Initialize with a hash of attributes and values.
|
9
|
-
#
|
9
|
+
# Extra attributes are discarded.
|
10
10
|
#
|
11
11
|
# @example
|
12
12
|
#
|
@@ -36,17 +36,25 @@ class Scrivener
|
|
36
36
|
# post.save
|
37
37
|
def initialize(atts)
|
38
38
|
atts.each do |key, val|
|
39
|
-
|
39
|
+
accessor = "#{key}="
|
40
|
+
|
41
|
+
if respond_to?(accessor)
|
42
|
+
send(accessor, val)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def _accessors
|
48
|
+
public_methods(false).select do |name|
|
49
|
+
name[-1] == "="
|
40
50
|
end
|
41
51
|
end
|
42
52
|
|
43
53
|
# Return hash of attributes and values.
|
44
54
|
def attributes
|
45
55
|
Hash.new.tap do |atts|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
att = ivar[1..-1].to_sym
|
56
|
+
_accessors.each do |accessor|
|
57
|
+
att = accessor[0..-2].to_sym
|
50
58
|
atts[att] = send(att)
|
51
59
|
end
|
52
60
|
end
|
data/test/scrivener_test.rb
CHANGED
@@ -6,12 +6,14 @@ class A < Scrivener
|
|
6
6
|
end
|
7
7
|
|
8
8
|
scope do
|
9
|
-
test "
|
9
|
+
test "ignore extra fields" do
|
10
10
|
atts = { :a => 1, :b => 2, :c => 3 }
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
filter = A.new(atts)
|
13
|
+
|
14
|
+
atts.delete(:c)
|
15
|
+
|
16
|
+
assert_equal atts, filter.attributes
|
15
17
|
end
|
16
18
|
|
17
19
|
test "not raise when there are less fields" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scrivener
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Martens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cutest
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- .gems
|
36
36
|
- .gitignore
|
37
37
|
- AUTHORS
|
38
|
+
- CHANGELOG.md
|
38
39
|
- LICENSE
|
39
40
|
- README.md
|
40
41
|
- lib/scrivener.rb
|