scrivener 0.4.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72f2e838e6737f8f6e70ea7ec1d24858c4a314ac
4
- data.tar.gz: ee6290714b6ab3e9d103f76d18fb6a490af726e9
3
+ metadata.gz: d856e30f00eb2fbb898b1f436706d513921d7b6b
4
+ data.tar.gz: 2cee2565f0507e0ebf8177d2cb57626f683528c1
5
5
  SHA512:
6
- metadata.gz: b5381e070059513af9bac415be99757a0b21c54e77a8e52a3d309c97813a4d361dfcd1a11c99f0f935e7d5a992ed20150bfcd6ab1a21661f9720cc8cde1a97f3
7
- data.tar.gz: 12be078877cf6aeadcaf9a01896dfe7f3d826f71462664602e7314fe653d031dc3000acc3441e4ee94fda40db89319db673c0a0f0b82b8c45cc6e8cf0ec10775
6
+ metadata.gz: 068427019df2072dc56517932811d744dd8fcbc4ad9842880382c9e8a3dfc46f118e066d24b73a51364dbbf6dcce42e5ffeb3d1121b714acf61e8066acff9c56
7
+ data.tar.gz: c2acd1812ffc52b268d1294c2c744cda6e92f17c5a0011e8777400b39215f276ce5ff43fbae5d1f1e17dcc440aaad160a83b851c224a1bd7b51e62f5bacfe29d
@@ -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
- # If we try to change other fields...
113
+ # Extra fields are discarded
114
114
  publish = Publish.new(status: "published", title: "foo")
115
- #=> NoMethodError: undefined method `title=' for #<Publish...>
115
+ publish.attributes #=> { :status => "published" }
116
116
  ```
117
117
 
118
118
  Slices
@@ -1,12 +1,12 @@
1
1
  require_relative "scrivener/validations"
2
2
 
3
3
  class Scrivener
4
- VERSION = "0.4.1"
4
+ VERSION = "1.0.0"
5
5
 
6
6
  include Validations
7
7
 
8
8
  # Initialize with a hash of attributes and values.
9
- # If extra attributes are sent, a NoMethodError exception will be raised.
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
- send("#{key}=", val)
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
- instance_variables.each do |ivar|
47
- next if ivar == :@errors
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
@@ -6,12 +6,14 @@ class A < Scrivener
6
6
  end
7
7
 
8
8
  scope do
9
- test "raise when there are extra fields" do
9
+ test "ignore extra fields" do
10
10
  atts = { :a => 1, :b => 2, :c => 3 }
11
11
 
12
- assert_raise NoMethodError do
13
- filter = A.new(atts)
14
- end
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.1
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-17 00:00:00.000000000 Z
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