yas 0.2.1 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d38c06826501ec1c464139ccab533d286df21f01
4
- data.tar.gz: 962be12bc93bf5fa738eaad7203f30d6f7e5bccf
3
+ metadata.gz: d2d1f54023a01907f599f48cca90bb9242a62089
4
+ data.tar.gz: 07c833f91eea25fcd26c65d07e2aa841a112e8a0
5
5
  SHA512:
6
- metadata.gz: bb6e122e9f6a92205983244ba3631c5e9fd529549a61896b2f5d8e8ff2bdb2f50ef3dada44ca12964930a5c3b3f340e167585303e53bf2b5076f9683b7b04aba
7
- data.tar.gz: d727f448c7a820f9a2c11173e7342ba27c2989c67ab4d5bb955e8fc8ecedb93f9c9102279627e50585eb49de5907c907dfeb0489080eb202b3668491068a8513
6
+ metadata.gz: 55eb0916f52e24c460bb6052694375ffb916f1428b3a700fca8d9c2ed98cf531818b2f2c8ad0638ddd81d41656b2ffe0bf6a46e209d45ee639747b66b1f255d0
7
+ data.tar.gz: 45f84dab4db77099310d49bf9236c4ee622bb6f98b113b53d7de1c2b17ad9b7d9f3b264cb25438f0026d6715d7d07f937bdf8c2667aead73f94b54d62a0f9e1d
@@ -0,0 +1,42 @@
1
+ # Duplicate value of a key
2
+ #
3
+ # Usage:
4
+ #
5
+ # duplicate :mykey => [:other_key, :another_key]
6
+ #
7
+
8
+ class YAS::DuplicateExt
9
+
10
+ module ClassMethods
11
+ def duplicate map
12
+ duplicate_keys.merge!(map)
13
+ end
14
+
15
+ def duplicate_keys
16
+ @duplicate_keys ||= {}
17
+ end
18
+ end
19
+
20
+
21
+ def self.when_used schema
22
+ schema.extend ClassMethods
23
+ end
24
+
25
+
26
+ def self.when_schema_inherited superschema, subschema
27
+ superschema.duplicate_keys.each do |from, to|
28
+ subschema.duplicate_keys[key] = to
29
+ end
30
+ end
31
+
32
+
33
+ def self.apply schema, hash
34
+ schema.duplicate_keys.each do |from, to|
35
+ if hash.has_key?(from)
36
+ to = Array(to)
37
+ to.each { |t| hash[t] = hash[from] }
38
+ end
39
+ end
40
+ end
41
+
42
+ end
data/lib/yas/schema.rb CHANGED
@@ -40,6 +40,7 @@ class YAS::Schema < YAS::SchemaBase
40
40
 
41
41
  use YAS::SymbolizeExt
42
42
  use YAS::RenameExt
43
+ use YAS::DuplicateExt
43
44
  use YAS::WhitelistExt
44
45
  use YAS::MigrateExt
45
46
  use YAS::AttributeExt
data/lib/yas/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module YAS
2
2
  GEM_NAME = "yas"
3
3
  NAME = "YAS"
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
data/lib/yas.rb CHANGED
@@ -5,6 +5,7 @@ require 'yas/errors'
5
5
 
6
6
  require 'yas/ext/symbolize'
7
7
  require 'yas/ext/rename'
8
+ require 'yas/ext/duplicate'
8
9
  require 'yas/ext/attribute'
9
10
  require 'yas/ext/migrate'
10
11
  require 'yas/ext/whitelist'
@@ -0,0 +1,27 @@
1
+ require './test/helper.rb'
2
+
3
+ class DuplicateSchema < YAS::Schema
4
+ duplicate :addr => :address
5
+ duplicate 'home' => ['office', :temp]
6
+ end
7
+
8
+
9
+
10
+ class TestDuplicateExt < Minitest::Test
11
+
12
+ def test_duplicate_ext
13
+ hash = {
14
+ addr: "Some address",
15
+ 'home' => 'home address',
16
+ untouched: "Nothing"
17
+ }
18
+ hash.validate! DuplicateSchema
19
+ assert_equal "Some address", hash[:addr]
20
+ assert_equal "Some address", hash[:address]
21
+ assert_equal "home address", hash['home']
22
+ assert_equal "home address", hash['office']
23
+ assert_equal "home address", hash[:temp]
24
+ assert_equal "Nothing", hash[:untouched]
25
+ end
26
+
27
+ end
data/yas.gemspec CHANGED
@@ -19,5 +19,5 @@ Gem::Specification.new do |s|
19
19
  s.add_development_dependency 'mocha', '~> 1.1'
20
20
  s.add_development_dependency 'rake', '~> 10.3'
21
21
 
22
- s.license = "Apache"
22
+ s.license = "Apache-2.0"
23
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Albert Tedja
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-05 00:00:00.000000000 Z
11
+ date: 2016-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -64,6 +64,7 @@ files:
64
64
  - lib/yas.rb
65
65
  - lib/yas/errors.rb
66
66
  - lib/yas/ext/attribute.rb
67
+ - lib/yas/ext/duplicate.rb
67
68
  - lib/yas/ext/migrate.rb
68
69
  - lib/yas/ext/rename.rb
69
70
  - lib/yas/ext/symbolize.rb
@@ -72,6 +73,7 @@ files:
72
73
  - lib/yas/schema.rb
73
74
  - lib/yas/version.rb
74
75
  - test/ext/test_attribute.rb
76
+ - test/ext/test_duplicate.rb
75
77
  - test/ext/test_migrate.rb
76
78
  - test/ext/test_rename.rb
77
79
  - test/ext/test_symbolize.rb
@@ -81,7 +83,7 @@ files:
81
83
  - yas.gemspec
82
84
  homepage: https://github.com/atedja/yas
83
85
  licenses:
84
- - Apache
86
+ - Apache-2.0
85
87
  metadata: {}
86
88
  post_install_message:
87
89
  rdoc_options: []
@@ -99,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
101
  version: '0'
100
102
  requirements: []
101
103
  rubyforge_project:
102
- rubygems_version: 2.4.8
104
+ rubygems_version: 2.5.2
103
105
  signing_key:
104
106
  specification_version: 4
105
107
  summary: Yet Another Schema for Ruby.