split_dmy 0.4.2 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b34c8cbbc1769056b91688ca7fefcab834137e04
4
- data.tar.gz: e5cd37c5b246628e2254c5d5a7d192ea70681d51
3
+ metadata.gz: 808596db7b93911fcd5c5522bb5a34549e872c6a
4
+ data.tar.gz: bbbef8861fd5194a9b62ec275ef934be2bdee761
5
5
  SHA512:
6
- metadata.gz: 116dd615d6ad43bcae21102c23638f11c14260cf39c5cd6d7ec470667218288d3659556b00a1958d94791b9d60ba28537586c9bf6d5d1d895873f00405de2d2d
7
- data.tar.gz: 0cd4556446e1365e3534df87c6f54a137808c14a90bc4c62d4dd8eab525df351541575b36100a90d5f17ef8e7ccce2a51852a7d0de9668b7115b1ab1791fcaff
6
+ metadata.gz: dc435c322a1f449afc4e4bfa1bb04f745067ee6abe1b582ce8a86655a4bd6c522ed297f11372ba2891b057e73f8a49c24fa7b8d89595db40d976dddba13d1cf6
7
+ data.tar.gz: 7f67b29a8418ca43764bfd483d0fbe86ce94273ba43985cee1403419a7352f73a8fd27993833c8f0ee6cf301ce1a3588fb899b3ddc84bd5f2c69fa708ac7aad7
@@ -1,18 +1,30 @@
1
1
  module SplitDmy
2
2
  module SplitAccessors
3
+ PARTS = %w[day month year].freeze
4
+
3
5
  def split_dmy_accessor(*attrs)
4
6
  require 'split_dmy/date_validator'
5
7
 
6
8
  attrs.each do |attr|
7
9
  override_builtin(attr)
8
10
  add_attr_accessors(attr)
11
+ add_virtus_attributes(attr)
9
12
  extend_validation(attr)
10
13
  end
11
14
  add_methods
15
+ override_permitted_attributes(attrs)
12
16
  end
13
17
 
14
18
  private
15
19
 
20
+ def override_permitted_attributes(attrs)
21
+ array = attrs.product(PARTS).map { |attr, part| "#{attr}_#{part}".to_sym }
22
+
23
+ define_method(:permitted_attributes) do
24
+ super().push(array)
25
+ end
26
+ end
27
+
16
28
  def extend_validation(attr)
17
29
  define_method("validate_#{attr}_partials") do
18
30
  dv = DateValidator.new(self, attr)
@@ -43,8 +55,14 @@ module SplitDmy
43
55
  end
44
56
  end
45
57
 
58
+ def add_virtus_attributes(attr)
59
+ PARTS.each do |part|
60
+ attribute "#{attr}_#{part}", String
61
+ end
62
+ end
63
+
46
64
  def add_attr_accessors(attr)
47
- %w[day month year].each do |part|
65
+ PARTS.each do |part|
48
66
  define_method("#{attr}_#{part}=") do |val|
49
67
  instance_variable_set("@#{attr}_#{part}", val)
50
68
  new = DateValidator.new(self, attr).partial_updated
@@ -1,3 +1,3 @@
1
1
  module SplitDmy
2
- VERSION = '0.4.2'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: split_dmy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin Bruce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-23 00:00:00.000000000 Z
11
+ date: 2016-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler