maybe_so 1.0.1 → 1.1.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: 961792b671a9c7a12cd2e3c930300b421ff001da
4
- data.tar.gz: 3aaf43a8af889c5fec7621031a9aa1346a811569
3
+ metadata.gz: 9a9d340ec26474b799607716977f7a68b141a90d
4
+ data.tar.gz: cb9d30400f642c1e36f2336824342ee5083899ac
5
5
  SHA512:
6
- metadata.gz: 7b9bdbaf236de2cdf5aa8eee9f971d266a6c2eac14857299a4912d6a9d4f23d36cec812f04a007b9af6aa838216d0fabc1c30ea4818b15fbb2464deb245177a1
7
- data.tar.gz: 2491a28268c8d3ab544cf06258c50c285211e540e038b07ce6ca5de030ad947c5495d3a61770af0d685189521cb3c0a6621fcc90faca2d7b7cf12c8a5739dde6
6
+ metadata.gz: 325cc9c084c81d68641533abdf62e64f6ba55f57acca5a70f5d6d1982a39e48ffb202816c4ef0a2ea34c189840263940faef348c6433895ddcb52e4a25ddacec
7
+ data.tar.gz: 07a1dc439450bfa782d922655f8ad7c8dccb4972d13e44ba61168c20b600b7678a14376e8e97fe982762ca09301fcf7dda2470d81540cb6be8faab06cb3467b0
@@ -1,5 +1,4 @@
1
1
  rvm:
2
- - 1.9.3
3
2
  - 2.0.0
4
3
  - 2.1.0
5
4
  - 2.1.1
@@ -0,0 +1,4 @@
1
+ # 1.0.2 (April 11, 2017)
2
+
3
+ * Add Rails 5.1 support
4
+ * Add a CHANGELOG
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 James Miller & Tanner Mares
1
+ Copyright (c) 2017 James Miller & Tanner Mares
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -4,7 +4,7 @@ Ever get annoyed that ActiveRecord blows up if you set a boolean column to nil?
4
4
 
5
5
  Maybe So handles this for you!
6
6
 
7
- Tested on the following Rubies: MRI 1.9.3, 2.0.0, 2.1.x, JRuby (1.7.2 and newer).
7
+ Tested on Ruby 2.x (MRI)
8
8
 
9
9
  [![Build Status](https://secure.travis-ci.org/ministrycentered/maybe_so.svg?branch=master)](http://travis-ci.org/ministrycentered/maybe_so)
10
10
 
@@ -61,7 +61,7 @@ end
61
61
  `boolean_attributes` accepts an options hash for the following:
62
62
 
63
63
  - `truthy_values`: array of values (will be coerced into strings when checking) to be considered truthy
64
- - `skip_validator`: this will not add the default `validates_inclusion_of` to ensure records are not valid unless they are set to `true` or `false`
64
+ - `skip_validator`: this will _omit_ adding the `validates_inclusion_of` to ensure records are not valid unless they are set to `true` or `false`. Note it does _not_ validate presence. If you want that, you'll need to add a separate validation.
65
65
 
66
66
  Example custom configuration:
67
67
 
@@ -71,6 +71,36 @@ class Product < ActiveRecord::Base
71
71
  end
72
72
  ```
73
73
 
74
+ ### #to_bool
75
+
76
+ `String`, `Integer`, `TrueClass`, `FalseClass`, `NilClass` all have `#to_bool` added.
77
+
78
+ ```ruby
79
+ "Yes".to_bool # Uses the same truthy values as shown above
80
+ # => true
81
+
82
+ "zing".to_bool
83
+ # => false
84
+
85
+ "1".to_bool
86
+ # => true
87
+
88
+ 1.to_bool
89
+ # => true
90
+
91
+ 42.to_bool
92
+ # => false
93
+
94
+ true.to_bool
95
+ # => true
96
+
97
+ false.to_bool
98
+ # => false
99
+
100
+ nil.to_bool
101
+ # => false
102
+ ```
103
+
74
104
  ## Copyright
75
105
 
76
- Copyright (c) 2014 James Miller and Tanner Mares
106
+ Copyright (c) 2017 James Miller and Tanner Mares
@@ -9,7 +9,8 @@ module ActiveModel
9
9
  include MaybeSo::ActiveModel::BooleanAttribute
10
10
  end
11
11
  end
12
- alias_method_chain :included, :boolean_attribute
12
+ alias_method :included_without_boolean_attribute, :included
13
+ alias_method :included, :included_with_boolean_attribute
13
14
  end
14
15
  end
15
16
  end
@@ -1,7 +1,6 @@
1
1
  module MaybeSo
2
2
  module ActiveModel
3
3
  module BooleanAttribute
4
-
5
4
  def self.included(base)
6
5
  base.extend(ClassMethods)
7
6
  end
@@ -1,5 +1,5 @@
1
1
  require "maybe_so/core_ext/string"
2
- require "maybe_so/core_ext/fixnum"
2
+ require "maybe_so/core_ext/integer"
3
3
  require "maybe_so/core_ext/true_class"
4
4
  require "maybe_so/core_ext/false_class"
5
5
  require "maybe_so/core_ext/nil_class"
@@ -1,5 +1,4 @@
1
1
  class FalseClass
2
-
3
2
  def to_i
4
3
  0
5
4
  end
@@ -7,5 +6,4 @@ class FalseClass
7
6
  def to_bool
8
7
  self
9
8
  end
10
-
11
9
  end
@@ -1,7 +1,5 @@
1
- class Fixnum
2
-
1
+ class Integer
3
2
  def to_bool
4
3
  self == 1
5
4
  end
6
-
7
5
  end
@@ -1,7 +1,5 @@
1
1
  class NilClass
2
-
3
2
  def to_bool
4
3
  false
5
4
  end
6
-
7
5
  end
@@ -1,7 +1,5 @@
1
1
  class String
2
-
3
2
  def to_bool
4
3
  MaybeSo::DEFAULT_TRUTHY_VALUES.include? self.downcase
5
4
  end
6
-
7
5
  end
@@ -1,5 +1,4 @@
1
1
  class TrueClass
2
-
3
2
  def to_i
4
3
  1
5
4
  end
@@ -7,5 +6,4 @@ class TrueClass
7
6
  def to_bool
8
7
  self
9
8
  end
10
-
11
9
  end
@@ -1,3 +1,3 @@
1
1
  module MaybeSo
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe Fixnum do
3
+ describe Integer do
4
4
  describe "#to_bool" do
5
5
  context "when 1" do
6
6
  it "returns true" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maybe_so
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Miller
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-29 00:00:00.000000000 Z
12
+ date: 2017-05-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -89,6 +89,7 @@ extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
91
  - ".travis.yml"
92
+ - CHANGELOG.md
92
93
  - Gemfile
93
94
  - LICENSE.txt
94
95
  - README.md
@@ -98,7 +99,7 @@ files:
98
99
  - lib/maybe_so/active_model/boolean_attribute.rb
99
100
  - lib/maybe_so/core_ext.rb
100
101
  - lib/maybe_so/core_ext/false_class.rb
101
- - lib/maybe_so/core_ext/fixnum.rb
102
+ - lib/maybe_so/core_ext/integer.rb
102
103
  - lib/maybe_so/core_ext/nil_class.rb
103
104
  - lib/maybe_so/core_ext/string.rb
104
105
  - lib/maybe_so/core_ext/true_class.rb
@@ -106,7 +107,7 @@ files:
106
107
  - maybe_so.gemspec
107
108
  - spec/boolean_attribute_spec.rb
108
109
  - spec/false_class_spec.rb
109
- - spec/fixnum_spec.rb
110
+ - spec/integer_spec.rb
110
111
  - spec/nil_class_spec.rb
111
112
  - spec/spec_helper.rb
112
113
  - spec/string_spec.rb
@@ -131,14 +132,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
132
  version: '0'
132
133
  requirements: []
133
134
  rubyforge_project:
134
- rubygems_version: 2.2.2
135
+ rubygems_version: 2.6.10
135
136
  signing_key:
136
137
  specification_version: 4
137
138
  summary: Ruby boolean type casting
138
139
  test_files:
139
140
  - spec/boolean_attribute_spec.rb
140
141
  - spec/false_class_spec.rb
141
- - spec/fixnum_spec.rb
142
+ - spec/integer_spec.rb
142
143
  - spec/nil_class_spec.rb
143
144
  - spec/spec_helper.rb
144
145
  - spec/string_spec.rb