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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27d7a6a18d57befed3918f2bfff542bd99d9ef58fa7cfe68b028b6165cc2e001
4
- data.tar.gz: 050735d5e29e679f140f9521452dd75266116efd94c9b72a6215f4bb52834aff
3
+ metadata.gz: e652baf798884f7fdb18b8d87e67d651263e66bed733d8bd1f4e790d8420f464
4
+ data.tar.gz: 62c19ff44b88e6f456f15c78eda8f4ad5f67bcd931d15a3d356f4db995afd467
5
5
  SHA512:
6
- metadata.gz: '0648dc4bb4168744604929bdc7f32d3e5ba2a5ffea45e3e7c4c27f6cfa3ce2f7aafe220b09f0cb239363bf4197ae7bfde959c52173fed65d5fbfd2f4cdd7efcc'
7
- data.tar.gz: 92d9884debc077a14e90627eeef4fed79fb927467d1934cc7739198541f27b9da380cfcf2de3518c5c111113a6fbc9dbd1a83b3af413d421252a2829da5f4de5
6
+ metadata.gz: 9d9568e271cf14d699024f8f464898acb2f6b62dba6e3226f5c3c6183bd4aed19199cfbd969840422fbd4a638fd27dc08b5f7cd7d80e10dee4b85aca2f48aec7
7
+ data.tar.gz: 1d637b5566727fd7ee4476fd487e81ec3a0fa05dc53cd170a64e36a0fe1c7ed12ded40463f235d218c019aa9c60a8bee09e4eb1090e72f4b2fd3d08b17fa8f61
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
+ dist: trusty # for Ruby 1.9
2
3
  sudo: false
3
4
  rvm:
4
5
  - 1.9.2
@@ -1,3 +1,8 @@
1
+ # ActiveAttr 0.15.0 (June 12, 2019) #
2
+
3
+ * Add missing ActiveSupport require for Attributes
4
+ * Change numeric typecasters to cast nil and empty strings to nil
5
+
1
6
  # ActiveAttr 0.14.0 (June 10, 2019) #
2
7
 
3
8
  * Drop support for Ruby versions below 1.9.2
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 ruby
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 rubygem [on rubygems.org][rubygems].
10
+ ActiveAttr is distributed as a Ruby gem [on rubygems.org][rubygems].
11
11
 
12
12
  [![ActiveAttr Railscast][railscast poster]][railscast]
13
13
 
@@ -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 ruby models without reinventing the wheel.}
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? :to_f
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? :to_i
26
+ value.to_i if value.present? && value.respond_to?(:to_i)
25
27
  rescue FloatDomainError
26
28
  end
27
29
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveAttr
2
2
  # Complete version string
3
3
  # @since 0.1.0
4
- VERSION = "0.14.0"
4
+ VERSION = "0.15.0"
5
5
  end
@@ -12,15 +12,19 @@ module ActiveAttr
12
12
  typecaster.call(value).should equal value
13
13
  end
14
14
 
15
- it "casts nil to a zero BigDecimal" do
16
- typecaster.call(nil).should eql BigDecimal("0.0")
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 a alpha String to a zero BigDecimal" do
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 0.0" do
16
- typecaster.call(nil).should eql 0.0
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 0" do
16
- typecaster.call(nil).should eql 0
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.14.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-10 00:00:00.000000000 Z
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 ruby models without reinventing the wheel.
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
- rubyforge_project:
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