active_attr 0.14.0 → 0.15.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.
Potentially problematic release.
This version of active_attr might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +5 -0
- data/README.md +2 -2
- data/active_attr.gemspec +1 -1
- data/lib/active_attr/attributes.rb +1 -0
- data/lib/active_attr/typecasting/big_decimal_typecaster.rb +3 -0
- data/lib/active_attr/typecasting/float_typecaster.rb +3 -1
- data/lib/active_attr/typecasting/integer_typecaster.rb +3 -1
- data/lib/active_attr/version.rb +1 -1
- data/spec/unit/active_attr/typecasting/big_decimal_typecaster_spec.rb +7 -3
- data/spec/unit/active_attr/typecasting/float_typecaster_spec.rb +10 -2
- data/spec/unit/active_attr/typecasting/integer_typecaster_spec.rb +10 -2
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e652baf798884f7fdb18b8d87e67d651263e66bed733d8bd1f4e790d8420f464
|
4
|
+
data.tar.gz: 62c19ff44b88e6f456f15c78eda8f4ad5f67bcd931d15a3d356f4db995afd467
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d9568e271cf14d699024f8f464898acb2f6b62dba6e3226f5c3c6183bd4aed19199cfbd969840422fbd4a638fd27dc08b5f7cd7d80e10dee4b85aca2f48aec7
|
7
|
+
data.tar.gz: 1d637b5566727fd7ee4476fd487e81ec3a0fa05dc53cd170a64e36a0fe1c7ed12ded40463f235d218c019aa9c60a8bee09e4eb1090e72f4b2fd3d08b17fa8f61
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -3,11 +3,11 @@
|
|
3
3
|
[![Build History][travis badge]][travis]
|
4
4
|
[![Code Climate][codeclimate badge]][codeclimate]
|
5
5
|
|
6
|
-
ActiveAttr is a set of modules that makes it easy to create plain old
|
6
|
+
ActiveAttr is a set of modules that makes it easy to create plain old Ruby
|
7
7
|
models with functionality found in ORMs, like ActiveRecord, without
|
8
8
|
reinventing the wheel. Think of ActiveAttr as the stuff ActiveModel left out.
|
9
9
|
|
10
|
-
ActiveAttr is distributed as a
|
10
|
+
ActiveAttr is distributed as a Ruby gem [on rubygems.org][rubygems].
|
11
11
|
|
12
12
|
[![ActiveAttr Railscast][railscast poster]][railscast]
|
13
13
|
|
data/active_attr.gemspec
CHANGED
@@ -4,7 +4,7 @@ require File.expand_path("../lib/active_attr/version", __FILE__)
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Chris Griego", "Ben Poweski"]
|
6
6
|
gem.email = ["cgriego@gmail.com", "bpoweski@gmail.com"]
|
7
|
-
gem.description = %q{Create plain old
|
7
|
+
gem.description = %q{Create plain old Ruby models without reinventing the wheel.}
|
8
8
|
gem.summary = %q{What ActiveModel left out}
|
9
9
|
gem.homepage = "https://github.com/cgriego/active_attr"
|
10
10
|
gem.license = "MIT"
|
@@ -3,6 +3,7 @@ require "active_attr/dangerous_attribute_error"
|
|
3
3
|
require "active_attr/unknown_attribute_error"
|
4
4
|
require "active_model"
|
5
5
|
require "active_support/concern"
|
6
|
+
require "active_support/core_ext/class/attribute"
|
6
7
|
require "active_support/hash_with_indifferent_access"
|
7
8
|
|
8
9
|
begin
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require "bigdecimal"
|
2
2
|
require "bigdecimal/util"
|
3
3
|
require "active_support/core_ext/big_decimal/conversions"
|
4
|
+
require "active_support/core_ext/object/blank"
|
4
5
|
|
5
6
|
module ActiveAttr
|
6
7
|
module Typecasting
|
@@ -29,6 +30,8 @@ module ActiveAttr
|
|
29
30
|
value
|
30
31
|
elsif value.is_a? Rational
|
31
32
|
value.to_f.to_d
|
33
|
+
elsif value.blank?
|
34
|
+
nil
|
32
35
|
elsif value.respond_to? :to_d
|
33
36
|
value.to_d
|
34
37
|
else
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "active_support/core_ext/object/blank"
|
2
|
+
|
1
3
|
module ActiveAttr
|
2
4
|
module Typecasting
|
3
5
|
# Typecasts an Object to a Float
|
@@ -20,7 +22,7 @@ module ActiveAttr
|
|
20
22
|
#
|
21
23
|
# @since 0.5.0
|
22
24
|
def call(value)
|
23
|
-
value.to_f if value.respond_to?
|
25
|
+
value.to_f if value.present? && value.respond_to?(:to_f)
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "active_support/core_ext/object/blank"
|
2
|
+
|
1
3
|
module ActiveAttr
|
2
4
|
module Typecasting
|
3
5
|
# Typecasts an Object to an Integer
|
@@ -21,7 +23,7 @@ module ActiveAttr
|
|
21
23
|
#
|
22
24
|
# @since 0.5.0
|
23
25
|
def call(value)
|
24
|
-
value.to_i if value.respond_to?
|
26
|
+
value.to_i if value.present? && value.respond_to?(:to_i)
|
25
27
|
rescue FloatDomainError
|
26
28
|
end
|
27
29
|
end
|
data/lib/active_attr/version.rb
CHANGED
@@ -12,15 +12,19 @@ module ActiveAttr
|
|
12
12
|
typecaster.call(value).should equal value
|
13
13
|
end
|
14
14
|
|
15
|
-
it "casts nil to
|
16
|
-
typecaster.call(nil).should eql
|
15
|
+
it "casts nil to nil" do
|
16
|
+
typecaster.call(nil).should eql nil
|
17
17
|
end
|
18
18
|
|
19
19
|
it "casts a numeric String to a BigDecimal" do
|
20
20
|
typecaster.call("2").should eql BigDecimal("2.0")
|
21
21
|
end
|
22
22
|
|
23
|
-
it "casts
|
23
|
+
it "casts an empty String to nil" do
|
24
|
+
typecaster.call("").should eql nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "casts an alpha String to a zero BigDecimal" do
|
24
28
|
typecaster.call("bob").should eql BigDecimal("0.0")
|
25
29
|
end
|
26
30
|
|
@@ -12,14 +12,22 @@ module ActiveAttr
|
|
12
12
|
typecaster.call(value).should equal value
|
13
13
|
end
|
14
14
|
|
15
|
-
it "casts nil to
|
16
|
-
typecaster.call(nil).should eql
|
15
|
+
it "casts nil to nil" do
|
16
|
+
typecaster.call(nil).should eql nil
|
17
17
|
end
|
18
18
|
|
19
19
|
it "returns the float version of a String" do
|
20
20
|
typecaster.call("2").should eql 2.0
|
21
21
|
end
|
22
22
|
|
23
|
+
it "casts an empty String to nil" do
|
24
|
+
typecaster.call("").should eql nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "casts an alpha String to a zero Float" do
|
28
|
+
typecaster.call("bob").should eql 0.0
|
29
|
+
end
|
30
|
+
|
23
31
|
it "returns nil for an object that does not respond to #to_f" do
|
24
32
|
typecaster.call(Object.new).should be_nil
|
25
33
|
end
|
@@ -12,14 +12,22 @@ module ActiveAttr
|
|
12
12
|
typecaster.call(value).should equal value
|
13
13
|
end
|
14
14
|
|
15
|
-
it "casts nil to
|
16
|
-
typecaster.call(nil).should eql
|
15
|
+
it "casts nil to nil" do
|
16
|
+
typecaster.call(nil).should eql nil
|
17
17
|
end
|
18
18
|
|
19
19
|
it "returns the integer version of a String" do
|
20
20
|
typecaster.call("2").should eql 2
|
21
21
|
end
|
22
22
|
|
23
|
+
it "casts an empty String to nil" do
|
24
|
+
typecaster.call("").should eql nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "casts an alpha String to a zero Integer" do
|
28
|
+
typecaster.call("bob").should eql 0
|
29
|
+
end
|
30
|
+
|
23
31
|
it "returns nil for an object that does not respond to #to_i" do
|
24
32
|
typecaster.call(Object.new).should be_nil
|
25
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_attr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Griego
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-06-
|
12
|
+
date: 2019-06-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -161,7 +161,7 @@ dependencies:
|
|
161
161
|
- - "<"
|
162
162
|
- !ruby/object:Gem::Version
|
163
163
|
version: '2.0'
|
164
|
-
description: Create plain old
|
164
|
+
description: Create plain old Ruby models without reinventing the wheel.
|
165
165
|
email:
|
166
166
|
- cgriego@gmail.com
|
167
167
|
- bpoweski@gmail.com
|
@@ -282,8 +282,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
282
282
|
- !ruby/object:Gem::Version
|
283
283
|
version: '0'
|
284
284
|
requirements: []
|
285
|
-
|
286
|
-
rubygems_version: 2.7.9
|
285
|
+
rubygems_version: 3.0.3
|
287
286
|
signing_key:
|
288
287
|
specification_version: 4
|
289
288
|
summary: What ActiveModel left out
|