wannabe_bool 0.0.3 → 0.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,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZmZjNTM1NDVmNDIxZGUwOWM3NDQwYTBhODZkZjYzMjI4NDkxZmJiNw==
5
- data.tar.gz: !binary |-
6
- N2Q0YTZlZTYyNDI2ODUxNGVmZDEwMWFjNGQ0ODQ5Y2FhZDIyZTM5ZA==
2
+ SHA1:
3
+ metadata.gz: e6b92e2945d1f43306a4fb58920d4f5e815cf3fe
4
+ data.tar.gz: f70d074ae35b2eb2ce8d500f56cfa90d4b683c00
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YWQ0NjBkOTdmMDk1MTNhZWI2MTAwZmNkY2FiNDI5Yzc3Yzk1MzU0ZTk0OTMx
10
- MTJhYmI4Yzg3YzUzZWM1ZTcxOGM0NjYxYzZmOGQwYWI1ZDI2MDg3MTc4ZTRh
11
- NzYzNzViYTYyNmNjMzhhZTAyOGY4Y2Y2ZDA0MTg2NzMzODdhZDk=
12
- data.tar.gz: !binary |-
13
- Njk4ZDA2NDljYTE4ZDJiNmM3ZmU5OWU4MWIyODBkYmY4M2IwMjczNjYwMTYx
14
- Y2FjMDhjNzRjNmMwZTkxNWM4NWE3YmYxZTNmYjY0YzI1NDg1MTQxMzBhY2Ew
15
- YmZiZGJiMzAyMTU5N2VlNGZmNzI2NGM2MmE0NGI5ZDE0NGQ1YjM=
6
+ metadata.gz: 5c8acc0229cdbd11f8580f1bca927848944d31990c6478fa09542b1f0a4b0d1926a510e2d0b95ba16bfc89522b2e9e127507e236124af3a07fbb0e40cf0f4f3d
7
+ data.tar.gz: 2f4fd09e9c015296deb828e9df171d79f4545b1d8ca4a2cf5b72a37e90615b46f671725d6ba6d48d2b73cc1b0233e932c44e4a7e91b21963f22cf280cf25f5d9
data/.rspec CHANGED
@@ -1 +1,2 @@
1
1
  --color
2
+ --require 'spec_helper'
data/.travis.yml CHANGED
@@ -2,6 +2,5 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
- - 2.1.2
6
- - 2.1.3
5
+ - 2.1.5
7
6
  script: bundle exec rspec
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,6 @@
1
+ == Version 0.1.0
2
+ - New <code>WannabeBool::Attributes</code> module to create predicate methods.
3
+
1
4
  == Version 0.0.2
2
5
  - Gemspec update.
3
6
 
data/README.rdoc CHANGED
@@ -1,6 +1,7 @@
1
1
  = Wannabe Bool
2
2
 
3
3
  If <b>string</b>, <b>integer</b>, <b>symbol</b> and <b>nil</b> values wanna be a <b>boolean</b> value, they can with the new <code>to_b</code> method.
4
+ Moreover, you can use <code>WannabeBool::Attributes</code> module to create predicate methods in your classes.
4
5
 
5
6
  {<img src="https://badge.fury.io/rb/wannabe_bool.png" alt="Gem Version" />}[http://badge.fury.io/rb/wannabe_bool]
6
7
  {<img src="https://travis-ci.org/prodis/wannabe_bool.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/prodis/wannabe_bool]
@@ -107,6 +108,31 @@ If <b>string</b>, <b>integer</b>, <b>symbol</b> and <b>nil</b> values wanna be a
107
108
  ==== NilClass
108
109
  nil.to_b # => false
109
110
 
111
+ Creating predicate methods:
112
+
113
+ class Fake
114
+ include WannabeBool::Attributes
115
+
116
+ attr_accessor :name, :main, :published
117
+ attr_wannabe_bool :main, :published
118
+ end
119
+
120
+ fake = Fake.new
121
+ fake.main? # => false
122
+ fake.published? # => false
123
+
124
+ fake.main = true
125
+ fake.main? # => true
126
+
127
+ fake.published = 1
128
+ fake.published? # => true
129
+
130
+ fake.main = 'true'
131
+ fake.main? # => true
132
+
133
+ fake.published = :true
134
+ fake.published? # => true
135
+
110
136
 
111
137
  == Author
112
138
  - {Fernando Hamasaki de Amorim (prodis)}[http://prodis.blog.br]
data/lib/wannabe_bool.rb CHANGED
@@ -3,3 +3,4 @@ require 'wannabe_bool/boolean'
3
3
  require 'wannabe_bool/integer'
4
4
  require 'wannabe_bool/nil'
5
5
  require 'wannabe_bool/object'
6
+ require 'wannabe_bool/attributes'
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ module WannabeBool
3
+ module Attributes
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+ def attr_wannabe_bool(*attributes)
10
+ attributes.each do |attr|
11
+ raise ArgumentError, "#{attr} method is not defined." unless method_defined?(attr)
12
+
13
+ next if method_defined?("#{attr}?")
14
+
15
+ define_method("#{attr}?") do
16
+ send(attr).to_b
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module WannabeBool
3
- VERSION = '0.0.3'
3
+ VERSION = '0.1.0'
4
4
  end
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+ class Fake
3
+ include WannabeBool::Attributes
4
+
5
+ attr_reader :main, :published, :migrated
6
+ attr_wannabe_bool :main, :published, :migrated
7
+
8
+ def initialize(main, published)
9
+ @main = main
10
+ @published = published
11
+ end
12
+
13
+ def migrated?
14
+ # Don't worry about the symbol in return, it is just to help in test expectation.
15
+ :original_method_return
16
+ end
17
+ end
18
+
19
+ describe WannabeBool::Attributes do
20
+ context 'when reader attribute exists' do
21
+ let(:subject_methods) do
22
+ fake = Fake.new(true, true)
23
+ fake.public_methods - Object.methods
24
+ end
25
+
26
+ it 'creates the predicate method' do
27
+ expect(subject_methods).to include(:main?)
28
+ expect(subject_methods).to include(:published?)
29
+ end
30
+
31
+ [ { type: 'string', value: 'true' },
32
+ { type: 'integer', value: 1 },
33
+ { type: 'symbol', value: :true },
34
+ { type: 'boolean', value: true }
35
+ ].each do |info|
36
+ context "with a #{info[:type]} value" do
37
+ subject { Fake.new(info[:value], info[:value]) }
38
+
39
+ it 'returns original value converted to boolean' do
40
+ expect(subject.main?).to be true
41
+ expect(subject.published?).to be true
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ context 'when reader attribute does not exist' do
48
+ it 'raise an ArgumentError' do
49
+ expect { Fake.send(:attr_wannabe_bool, :not_exist) }.to raise_error(ArgumentError, 'not_exist method is not defined.')
50
+ end
51
+ end
52
+
53
+ context 'when predicate method exists' do
54
+ subject { Fake.new(true, true) }
55
+
56
+ it 'does not overrides the original predicate method' do
57
+ expect(subject.migrated?).to eql :original_method_return
58
+ end
59
+ end
60
+ end
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'spec_helper'
3
-
4
2
  describe WannabeBool::Boolean do
5
3
  context TrueClass do
6
4
  subject { true }
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'spec_helper'
3
-
4
2
  describe WannabeBool::Integer do
5
3
  context Integer do
6
4
  describe '#to_b' do
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'spec_helper'
3
-
4
2
  describe WannabeBool::Nil do
5
3
  context NilClass do
6
4
  subject { nil }
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'spec_helper'
3
-
4
2
  describe WannabeBool::Object do
5
3
  context String do
6
4
  describe '#to_b' do
data/wannabe_bool.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.version = WannabeBool::VERSION
8
8
  spec.authors = ['Prodis a.k.a. Fernando Hamasaki de Amorim']
9
9
  spec.email = ['prodis@gmail.com']
10
- spec.summary = 'If string, integer, symbol and nil values wanna be a boolean value, they can with the new #to_b method.'
10
+ spec.summary = 'If string, integer, symbol and nil values wanna be a boolean value, they can with the new #to_b method (and more).'
11
11
  spec.description = spec.summary
12
12
  spec.homepage = 'https://github.com/prodis/wannabe_bool'
13
13
  spec.license = 'MIT'
metadata CHANGED
@@ -1,81 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wannabe_bool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Prodis a.k.a. Fernando Hamasaki de Amorim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-12 00:00:00.000000000 Z
11
+ date: 2014-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coveralls
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
- description: ! 'If string, integer, symbol and nil values wanna be a boolean value,
56
- they can with the new #to_b method.'
55
+ description: 'If string, integer, symbol and nil values wanna be a boolean value,
56
+ they can with the new #to_b method (and more).'
57
57
  email:
58
58
  - prodis@gmail.com
59
59
  executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - .gitignore
64
- - .rspec
65
- - .ruby-gemset.example
66
- - .ruby-version.example
67
- - .travis.yml
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".ruby-gemset.example"
66
+ - ".ruby-version.example"
67
+ - ".travis.yml"
68
68
  - CHANGELOG.rdoc
69
69
  - Gemfile
70
70
  - README.rdoc
71
71
  - Rakefile
72
72
  - lib/wannabe_bool.rb
73
+ - lib/wannabe_bool/attributes.rb
73
74
  - lib/wannabe_bool/boolean.rb
74
75
  - lib/wannabe_bool/integer.rb
75
76
  - lib/wannabe_bool/nil.rb
76
77
  - lib/wannabe_bool/object.rb
77
78
  - lib/wannabe_bool/version.rb
78
79
  - spec/spec_helper.rb
80
+ - spec/wannabe_bool/attributes_spec.rb
79
81
  - spec/wannabe_bool/boolean_spec.rb
80
82
  - spec/wannabe_bool/integer_spec.rb
81
83
  - spec/wannabe_bool/nil_spec.rb
@@ -85,30 +87,31 @@ homepage: https://github.com/prodis/wannabe_bool
85
87
  licenses:
86
88
  - MIT
87
89
  metadata: {}
88
- post_install_message: ! "\n Wannabe Bool installed!\n You have just gotten one more
90
+ post_install_message: "\n Wannabe Bool installed!\n You have just gotten one more
89
91
  gem from a Brazilian Ruby Developer.\n Enjoy it, Prodis.\n\n "
90
92
  rdoc_options: []
91
93
  require_paths:
92
94
  - lib
93
95
  required_ruby_version: !ruby/object:Gem::Requirement
94
96
  requirements:
95
- - - ! '>='
97
+ - - ">="
96
98
  - !ruby/object:Gem::Version
97
99
  version: 1.9.3
98
100
  required_rubygems_version: !ruby/object:Gem::Requirement
99
101
  requirements:
100
- - - ! '>='
102
+ - - ">="
101
103
  - !ruby/object:Gem::Version
102
104
  version: '0'
103
105
  requirements: []
104
106
  rubyforge_project:
105
- rubygems_version: 2.4.2
107
+ rubygems_version: 2.4.3
106
108
  signing_key:
107
109
  specification_version: 4
108
- summary: ! 'If string, integer, symbol and nil values wanna be a boolean value, they
109
- can with the new #to_b method.'
110
+ summary: 'If string, integer, symbol and nil values wanna be a boolean value, they
111
+ can with the new #to_b method (and more).'
110
112
  test_files:
111
113
  - spec/spec_helper.rb
114
+ - spec/wannabe_bool/attributes_spec.rb
112
115
  - spec/wannabe_bool/boolean_spec.rb
113
116
  - spec/wannabe_bool/integer_spec.rb
114
117
  - spec/wannabe_bool/nil_spec.rb