command_model 2.0.0 → 2.0.1
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/.ruby-version +1 -0
- data/README.md +2 -0
- data/lib/command_model/convert.rb +1 -1
- data/lib/command_model/model.rb +0 -8
- data/lib/command_model/version.rb +1 -1
- data/spec/convert_spec.rb +5 -4
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 894d328023ecf9f0a8935bfe2a198e2fa3d26a55d42b2a4c0178bfa390e9b4bf
|
4
|
+
data.tar.gz: c00d13c0db81fd1a1c9c49e3ff9fa473d62c0c8131ca449acf8f6dd695109a7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 016761f5657fd6b00664d0d8e3730d83055506314fa4a49a02194eaa6e7e7f680d8ae234590616a148c31ccc7ab5dfd613b63385121c8e10dafc96adc426cd9b
|
7
|
+
data.tar.gz: fc0b8d08827f71c8882697eeb2918f9bde7364aecd7f4796e9125727b73ceb0113022427ff76ed1ce96804c624780cc80be23823587828bcf549b6a0cc852d6b
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.1
|
data/README.md
CHANGED
@@ -130,6 +130,8 @@ integration of Rails form helpers and validations with CommandModel.
|
|
130
130
|
|
131
131
|
## Version History
|
132
132
|
|
133
|
+
* 2.0.1 - April 3, 2023
|
134
|
+
* Date parsing allows 5 digit years
|
133
135
|
* 2.0 - April 11, 2018
|
134
136
|
* Rename typecast parameter option to convert
|
135
137
|
* Any callable object can be used as a type converter
|
@@ -61,7 +61,7 @@ module CommandModel
|
|
61
61
|
return nil if value.blank?
|
62
62
|
return value if value.kind_of? Date
|
63
63
|
value = value.to_s
|
64
|
-
if value =~ /\A(\d
|
64
|
+
if value =~ /\A(\d{4,5})-(\d\d)-(\d\d)\z/
|
65
65
|
::Date.civil($1.to_i, $2.to_i, $3.to_i)
|
66
66
|
else
|
67
67
|
::Date.strptime(value, "%m/%d/%Y")
|
data/lib/command_model/model.rb
CHANGED
@@ -1,12 +1,4 @@
|
|
1
1
|
module CommandModel
|
2
|
-
class TypecastError < StandardError
|
3
|
-
attr_reader :original_error
|
4
|
-
|
5
|
-
def initialize(original_error)
|
6
|
-
@original_error = original_error
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
2
|
class Model
|
11
3
|
include ActiveModel::Validations
|
12
4
|
include ActiveModel::Conversion
|
data/spec/convert_spec.rb
CHANGED
@@ -30,7 +30,7 @@ describe "CommandModel::Convert" do
|
|
30
30
|
expect(subject.("")).to eq(nil)
|
31
31
|
end
|
32
32
|
|
33
|
-
it "raises
|
33
|
+
it "raises ConvertError when invalid string" do
|
34
34
|
expect { subject.("asdf") }.to raise_error(CommandModel::Convert::ConvertError)
|
35
35
|
expect { subject.("0.1") }.to raise_error(CommandModel::Convert::ConvertError)
|
36
36
|
end
|
@@ -52,7 +52,7 @@ describe "CommandModel::Convert" do
|
|
52
52
|
expect(subject.("")).to eq(nil)
|
53
53
|
end
|
54
54
|
|
55
|
-
it "raises
|
55
|
+
it "raises ConvertError when invalid string" do
|
56
56
|
expect { subject.("asdf") }.to raise_error(CommandModel::Convert::ConvertError)
|
57
57
|
end
|
58
58
|
end
|
@@ -81,7 +81,7 @@ describe "CommandModel::Convert" do
|
|
81
81
|
expect(subject.("")).to eq(nil)
|
82
82
|
end
|
83
83
|
|
84
|
-
it "raises
|
84
|
+
it "raises ConvertError when invalid string" do
|
85
85
|
expect { subject.("asdf") }.to raise_error(CommandModel::Convert::ConvertError)
|
86
86
|
end
|
87
87
|
end
|
@@ -93,6 +93,7 @@ describe "CommandModel::Convert" do
|
|
93
93
|
expect(subject.("01/01/2000")).to eq(Date.civil(2000,1,1))
|
94
94
|
expect(subject.("1/1/2000")).to eq(Date.civil(2000,1,1))
|
95
95
|
expect(subject.("2000-01-01")).to eq(Date.civil(2000,1,1))
|
96
|
+
expect(subject.("29000-01-01")).to eq(Date.civil(29000,1,1))
|
96
97
|
end
|
97
98
|
|
98
99
|
it "returns existing date unchanged" do
|
@@ -108,7 +109,7 @@ describe "CommandModel::Convert" do
|
|
108
109
|
expect(subject.("")).to eq(nil)
|
109
110
|
end
|
110
111
|
|
111
|
-
it "raises
|
112
|
+
it "raises ConvertError when invalid string" do
|
112
113
|
expect { subject.("asdf") }.to raise_error(CommandModel::Convert::ConvertError)
|
113
114
|
expect { subject.("3/50/1290") }.to raise_error(CommandModel::Convert::ConvertError)
|
114
115
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: command_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jack Christensen
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -61,6 +61,7 @@ extra_rdoc_files: []
|
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
63
|
- ".rspec"
|
64
|
+
- ".ruby-version"
|
64
65
|
- ".travis.yml"
|
65
66
|
- Gemfile
|
66
67
|
- LICENSE
|
@@ -139,7 +140,7 @@ files:
|
|
139
140
|
homepage: https://github.com/JackC/command_model
|
140
141
|
licenses: []
|
141
142
|
metadata: {}
|
142
|
-
post_install_message:
|
143
|
+
post_install_message:
|
143
144
|
rdoc_options: []
|
144
145
|
require_paths:
|
145
146
|
- lib
|
@@ -154,9 +155,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
155
|
- !ruby/object:Gem::Version
|
155
156
|
version: '0'
|
156
157
|
requirements: []
|
157
|
-
|
158
|
-
|
159
|
-
signing_key:
|
158
|
+
rubygems_version: 3.4.1
|
159
|
+
signing_key:
|
160
160
|
specification_version: 4
|
161
161
|
summary: CommandModel integrates Rails validations with command objects. This allows
|
162
162
|
errors from command execution to easily be handled with the familiar Rails validation
|