hcast 0.2.1 → 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/Gemfile +0 -1
- data/Gemfile.lock +1 -9
- data/README.md +5 -24
- data/hcast.gemspec +2 -2
- data/lib/hcast/attributes_caster.rb +4 -1
- data/lib/hcast/version.rb +1 -1
- data/spec/hcast/caster_spec.rb +32 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04bee70c76ea3f3edb1aca7fcfac6d0e31ec8498
|
4
|
+
data.tar.gz: 0d51877c017d56a3fd486693d0a90414cccc896b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97e57dbfd1a2f741984dc6fccad7098b9a589a52f3c698586aa1070d0fed96253c73bc5ad370d0cd57e4652fe8211e1cf95c66266fca09be79d5040dd4b93236
|
7
|
+
data.tar.gz: faba0f058007e3f81b4aa7bb5170993e12c7372dd12fb306465384204d780a8a138b0c353312f22a1400a23606c7b48972022db69719e18150bfe9be417b214f
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,18 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hcast (0.
|
4
|
+
hcast (0.3.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
columnize (0.3.6)
|
10
|
-
debugger (1.6.5)
|
11
|
-
columnize (>= 0.3.1)
|
12
|
-
debugger-linecache (~> 1.2.0)
|
13
|
-
debugger-ruby_core_source (~> 1.3.1)
|
14
|
-
debugger-linecache (1.2.0)
|
15
|
-
debugger-ruby_core_source (1.3.1)
|
16
9
|
diff-lcs (1.2.5)
|
17
10
|
rake (10.1.1)
|
18
11
|
rspec (2.14.1)
|
@@ -29,7 +22,6 @@ PLATFORMS
|
|
29
22
|
|
30
23
|
DEPENDENCIES
|
31
24
|
bundler (~> 1.3)
|
32
|
-
debugger
|
33
25
|
hcast!
|
34
26
|
rake
|
35
27
|
rspec
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
HCast is a library for casting hash attributes
|
6
6
|
|
7
|
-
|
7
|
+
### Usage
|
8
8
|
|
9
9
|
Create caster class and declare hash attributes inside:
|
10
10
|
```ruby
|
@@ -59,7 +59,7 @@ ContactCaster.cast({
|
|
59
59
|
}
|
60
60
|
})
|
61
61
|
```
|
62
|
-
The
|
62
|
+
The caster will cast your hash attributes to:
|
63
63
|
```ruby
|
64
64
|
{
|
65
65
|
contact: {
|
@@ -87,27 +87,8 @@ The casted will cast your hash and output will be:
|
|
87
87
|
}
|
88
88
|
```
|
89
89
|
|
90
|
-
if some of the attributes can't be casted the HCast::Errors::CastingError
|
90
|
+
if some of the attributes can't be casted the HCast::Errors::CastingError is raised
|
91
91
|
|
92
92
|
|
93
|
-
##
|
94
|
-
|
95
|
-
Add this line to your application's Gemfile:
|
96
|
-
|
97
|
-
gem 'hcast'
|
98
|
-
|
99
|
-
And then execute:
|
100
|
-
|
101
|
-
$ bundle
|
102
|
-
|
103
|
-
Or install it yourself as:
|
104
|
-
|
105
|
-
$ gem install hcast
|
106
|
-
|
107
|
-
## Contributing
|
108
|
-
|
109
|
-
1. Fork it
|
110
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
111
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
112
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
113
|
-
5. Create new Pull Request
|
93
|
+
## Author
|
94
|
+
Albert Gazizov, [@deeper4k](https://twitter.com/deeper4k)
|
data/hcast.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = HCast::VERSION
|
9
9
|
spec.authors = ["Albert Gazizov"]
|
10
10
|
spec.email = ["deeper4k@gmail.com"]
|
11
|
-
spec.description = %q{Hash Caster
|
12
|
-
spec.summary = %q{Hash Caster
|
11
|
+
spec.description = %q{Declarative Hash Caster}
|
12
|
+
spec.summary = %q{Declarative Hash Caster}
|
13
13
|
spec.homepage = "http://github.com/AlbertGazizov/hcast"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
@@ -23,7 +23,10 @@ class HCast::AttributesCaster
|
|
23
23
|
raise HCast::Errors::MissingAttributeError.new("should be given", attribute.name)if attribute.required?
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
|
+
if !options[:skip_unexpected_attributes]
|
28
|
+
check_unexpected_attributes_not_given!(hash_keys, casted_hash.keys)
|
29
|
+
end
|
27
30
|
|
28
31
|
casted_hash
|
29
32
|
end
|
data/lib/hcast/version.rb
CHANGED
data/spec/hcast/caster_spec.rb
CHANGED
@@ -252,6 +252,38 @@ describe HCast::Caster do
|
|
252
252
|
end.to raise_error(HCast::Errors::UnexpectedAttributeError, "contact[wrong_attribute] is not valid attribute name")
|
253
253
|
end
|
254
254
|
|
255
|
+
it "shouldn't unexpected attributes error if skip_unexpected_attributes flag is set to true" do
|
256
|
+
input_hash = {
|
257
|
+
contact: {
|
258
|
+
wrong_attribute: 'foo',
|
259
|
+
name: "Jim",
|
260
|
+
weight: 65.5,
|
261
|
+
birthday: Date.today,
|
262
|
+
last_logged_in: DateTime.now,
|
263
|
+
last_visited_at: Time.now,
|
264
|
+
company: {
|
265
|
+
name: "MyCo",
|
266
|
+
},
|
267
|
+
emails: [ "test@example.com", "test2@example.com" ],
|
268
|
+
social_accounts: [
|
269
|
+
{
|
270
|
+
name: "john_smith",
|
271
|
+
type: :twitter,
|
272
|
+
},
|
273
|
+
{
|
274
|
+
name: "John",
|
275
|
+
type: :facebook,
|
276
|
+
},
|
277
|
+
]
|
278
|
+
}
|
279
|
+
}
|
280
|
+
|
281
|
+
expect do
|
282
|
+
ContactCaster.cast(input_hash, skip_unexpected_attributes: true)
|
283
|
+
end.not_to raise_error(HCast::Errors::UnexpectedAttributeError)
|
284
|
+
|
285
|
+
end
|
286
|
+
|
255
287
|
it "should convert accept hash with string keys and cast them to symbol keys" do
|
256
288
|
input_hash = {
|
257
289
|
'contact' => {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hcast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Albert Gazizov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
description: Hash Caster
|
41
|
+
description: Declarative Hash Caster
|
42
42
|
email:
|
43
43
|
- deeper4k@gmail.com
|
44
44
|
executables: []
|
@@ -99,7 +99,7 @@ rubyforge_project:
|
|
99
99
|
rubygems_version: 2.2.2
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
|
-
summary: Hash Caster
|
102
|
+
summary: Declarative Hash Caster
|
103
103
|
test_files:
|
104
104
|
- spec/hcast/caster_spec.rb
|
105
105
|
- spec/hcast/hcast_spec.rb
|