present_object 1.0.0.pre.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1fb7f8a26850d53df311e3a1cce5735a2bd5ede3
4
+ data.tar.gz: 311ce1c3024bb309c191fbc0b9638f828fbca4c2
5
+ SHA512:
6
+ metadata.gz: 27a12cd150a7c8ca885a325b607870f66fd32bb74e682fb0a0adf1522a5b6687cf57d71a9d40cda0ab8d844a3a1c78de48731fe2e7af893027a407937f97b6b9
7
+ data.tar.gz: 81d842b9a9e6e732ba96e46c092e680be6cc5f05e645f425dcc6805fb7891203e477426b833b54446d588e39a8f51fa718e0565b7a5a4dfb86d9084e5cd85345
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,86 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ DisplayStyleGuide: true
4
+ DisplayCopNames: true
5
+
6
+ #################
7
+ # [i] Overrides #
8
+ #################
9
+
10
+ CollectionMethods:
11
+ # Mapping from undesired method to desired_method
12
+ # e.g. to use `detect` over `find`:
13
+ #
14
+ # CollectionMethods:
15
+ # PreferredMethods:
16
+ # find: detect
17
+ PreferredMethods:
18
+ reduce: 'inject'
19
+ find: 'detect'
20
+ each_with_index: 'each.with_index'
21
+
22
+ # Align ends correctly.
23
+ EndAlignment:
24
+ EnforcedStyleAlignWith: variable
25
+
26
+ LineLength:
27
+ Max: 120
28
+ Exclude:
29
+ - examples/**/*
30
+
31
+ BracesAroundHashParameters:
32
+ EnforcedStyle: context_dependent
33
+
34
+ StringLiterals:
35
+ EnforcedStyle: double_quotes
36
+
37
+ #################
38
+ # Disabled cops #
39
+ #################
40
+ Metrics/ClassLength:
41
+ Enabled: false
42
+
43
+ Metrics/CyclomaticComplexity:
44
+ Enabled: false
45
+
46
+ Metrics/MethodLength:
47
+ Enabled: false
48
+
49
+ Metrics/BlockLength:
50
+ Exclude:
51
+ - spec/**/*
52
+
53
+ Style/ClassAndModuleChildren:
54
+ Enabled: false
55
+
56
+ Style/Documentation:
57
+ Enabled: false
58
+
59
+ Style/Lambda:
60
+ Enabled: false
61
+
62
+ Style/DoubleNegation:
63
+ Enabled: false
64
+
65
+ Style/IfUnlessModifier:
66
+ Enabled: false
67
+
68
+ Style/TrailingCommaInLiteral:
69
+ Enabled: true
70
+ EnforcedStyleForMultiline: comma
71
+
72
+ Style/TrailingCommaInArguments:
73
+ Enabled: true
74
+ EnforcedStyleForMultiline: comma
75
+
76
+ Style/GuardClause:
77
+ Enabled: false
78
+
79
+ Lint/AmbiguousBlockAssociation:
80
+ Exclude:
81
+ - spec/**/*
82
+
83
+ # Increase minsize to prevent rubocop throwing warning on ActiveRecord/ActiveController Callbacks
84
+ # Ex after_action :some_action, on: [:update, :create]
85
+ Style/SymbolArray:
86
+ MinSize: 4
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ present_object
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.3
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - ruby-head
5
+ - 2.5.0
6
+ - 2.4.3
7
+ - 2.3.6
8
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ group :development, :test do
8
+ gem "rubocop", "~> 0.52", require: false
9
+ end
10
+
11
+ # Specify your gem's dependencies in present_object.gemspec
12
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ present_object (1.0.0.pre.rc1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ diff-lcs (1.3)
11
+ parallel (1.12.1)
12
+ parser (2.5.0.2)
13
+ ast (~> 2.4.0)
14
+ powerpack (0.1.1)
15
+ rainbow (3.0.0)
16
+ rake (10.5.0)
17
+ rspec (3.7.0)
18
+ rspec-core (~> 3.7.0)
19
+ rspec-expectations (~> 3.7.0)
20
+ rspec-mocks (~> 3.7.0)
21
+ rspec-core (3.7.1)
22
+ rspec-support (~> 3.7.0)
23
+ rspec-expectations (3.7.0)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.7.0)
26
+ rspec-mocks (3.7.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.7.0)
29
+ rspec-support (3.7.1)
30
+ rubocop (0.52.1)
31
+ parallel (~> 1.10)
32
+ parser (>= 2.4.0.2, < 3.0)
33
+ powerpack (~> 0.1)
34
+ rainbow (>= 2.2.2, < 4.0)
35
+ ruby-progressbar (~> 1.7)
36
+ unicode-display_width (~> 1.0, >= 1.0.1)
37
+ ruby-progressbar (1.9.0)
38
+ unicode-display_width (1.3.0)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ bundler (~> 1.16)
45
+ present_object!
46
+ rake (~> 10)
47
+ rspec (~> 3.4)
48
+ rubocop (~> 0.52)
49
+
50
+ BUNDLED WITH
51
+ 1.16.1
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ [![Build Status](https://travis-ci.org/GeorgeKaraszi/PresentObject.svg?branch=master)](https://travis-ci.org/GeorgeKaraszi/PresentObject) [![Maintainability](https://api.codeclimate.com/v1/badges/f447204e489f4ac23387/maintainability)](https://codeclimate.com/github/GeorgeKaraszi/PresentObject/maintainability)
2
+
3
+ # PresentObject
4
+
5
+ A copy of ActiveSupport's present and blank objects without the extra baggage.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'present_object'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install present_object
22
+
23
+ ## Usage
24
+
25
+ ```
26
+ require 'present_object'
27
+
28
+ ...
29
+
30
+ 1.blank? #=> false
31
+ 1.present? #=> true
32
+
33
+ [].blank? #=> true
34
+ [].present? #=> false
35
+
36
+ nil.blank? #=> true
37
+ nil.present? #=> false
38
+ ```
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Regexp
4
+ def multiline?
5
+ options & MULTILINE == MULTILINE
6
+ end
7
+
8
+ unless //.respond_to?(:match?)
9
+ def match?(string, pos = 0)
10
+ !!match(string, pos)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,150 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Credit to the Rails Team & Contributors:
4
+ # https://github.com/rails/rails/blob/aea0e5cd709e0fc53e1ba4e87235b8ee3f4bc155/activesupport/lib/active_support/core_ext/object/blank.rb
5
+
6
+ require "present_object/core_ext/regexp"
7
+
8
+ class Object
9
+ # An object is blank if it's false, empty, or a whitespace string.
10
+ # For example, +false+, '', ' ', +nil+, [], and {} are all blank.
11
+ #
12
+ # This simplifies
13
+ #
14
+ # !address || address.empty?
15
+ #
16
+ # to
17
+ #
18
+ # address.blank?
19
+ #
20
+ # @return [true, false]
21
+ def blank?
22
+ respond_to?(:empty?) ? !!empty? : !self
23
+ end
24
+
25
+ # An object is present if it's not blank.
26
+ #
27
+ # @return [true, false]
28
+ def present?
29
+ !blank?
30
+ end
31
+
32
+ # Returns the receiver if it's present otherwise returns +nil+.
33
+ # <tt>object.presence</tt> is equivalent to
34
+ #
35
+ # object.present? ? object : nil
36
+ #
37
+ # For example, something like
38
+ #
39
+ # state = params[:state] if params[:state].present?
40
+ # country = params[:country] if params[:country].present?
41
+ # region = state || country || 'US'
42
+ #
43
+ # becomes
44
+ #
45
+ # region = params[:state].presence || params[:country].presence || 'US'
46
+ #
47
+ # @return [Object]
48
+ def presence
49
+ self if present?
50
+ end
51
+ end
52
+
53
+ class NilClass
54
+ # +nil+ is blank:
55
+ #
56
+ # nil.blank? # => true
57
+ #
58
+ # @return [true]
59
+ def blank?
60
+ true
61
+ end
62
+ end
63
+
64
+ class FalseClass
65
+ # +false+ is blank:
66
+ #
67
+ # false.blank? # => true
68
+ #
69
+ # @return [true]
70
+ def blank?
71
+ true
72
+ end
73
+ end
74
+
75
+ class TrueClass
76
+ # +true+ is not blank:
77
+ #
78
+ # true.blank? # => false
79
+ #
80
+ # @return [false]
81
+ def blank?
82
+ false
83
+ end
84
+ end
85
+
86
+ class Array
87
+ # An array is blank if it's empty:
88
+ #
89
+ # [].blank? # => true
90
+ # [1,2,3].blank? # => false
91
+ #
92
+ # @return [true, false]
93
+ alias blank? empty?
94
+ end
95
+
96
+ class Hash
97
+ # A hash is blank if it's empty:
98
+ #
99
+ # {}.blank? # => true
100
+ # { key: 'value' }.blank? # => false
101
+ #
102
+ # @return [true, false]
103
+ alias blank? empty?
104
+ end
105
+
106
+ class String
107
+ BLANK_RE = /\A[[:space:]]*\z/
108
+
109
+ # A string is blank if it's empty or contains whitespaces only:
110
+ #
111
+ # ''.blank? # => true
112
+ # ' '.blank? # => true
113
+ # "\t\n\r".blank? # => true
114
+ # ' blah '.blank? # => false
115
+ #
116
+ # Unicode whitespace is supported:
117
+ #
118
+ # "\u00a0".blank? # => true
119
+ #
120
+ # @return [true, false]
121
+ def blank?
122
+ # The regexp that matches blank strings is expensive. For the case of empty
123
+ # strings we can speed up this method (~3.5x) with an empty? call. The
124
+ # penalty for the rest of strings is marginal.
125
+ empty? || BLANK_RE.match?(self)
126
+ end
127
+ end
128
+
129
+ class Numeric #:nodoc:
130
+ # No number is blank:
131
+ #
132
+ # 1.blank? # => false
133
+ # 0.blank? # => false
134
+ #
135
+ # @return [false]
136
+ def blank?
137
+ false
138
+ end
139
+ end
140
+
141
+ class Time #:nodoc:
142
+ # No Time is blank:
143
+ #
144
+ # Time.now.blank? # => false
145
+ #
146
+ # @return [false]
147
+ def blank?
148
+ false
149
+ end
150
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PresentObject
4
+ VERSION = "1.0.0-rc1"
5
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "present_object/version"
4
+
5
+ module PresentObject
6
+ end
7
+
8
+ require "present_object/object/blank" unless defined?(Rails)
@@ -0,0 +1,27 @@
1
+
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path("../lib", __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require "present_object/version"
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "present_object"
10
+ spec.version = PresentObject::VERSION
11
+ spec.authors = ["George Protacio-Karaszi"]
12
+ spec.email = ["georgekaraszi@gmail.com"]
13
+
14
+ spec.summary = "A copy of ActiveSupport's present and blank objects without the extra baggage."
15
+ spec.description = "A copy of ActiveSupport's present and blank objects without the extra baggage."
16
+ spec.homepage = "https://github.com/GeorgeKaraszi/PresentObject"
17
+ spec.license = "MIT"
18
+
19
+ spec.add_development_dependency("bundler", "~> 1.16")
20
+ spec.add_development_dependency("rake", "~> 10")
21
+ spec.add_development_dependency("rspec", "~> 3.4")
22
+
23
+ spec.files = `git ls-files`.split("\n")
24
+ spec.test_files = `git ls-files -- spec/*`.split("\n")
25
+ spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe PresentObject do
4
+ it "has a version number" do
5
+ expect(PresentObject::VERSION).not_to be nil
6
+ end
7
+
8
+ context "Strings" do
9
+ it "Requiring the gem allows the usage of blank and present" do
10
+ expect("".blank?).to be_truthy
11
+ expect(" ".blank?).to be_truthy
12
+ expect("a".blank?).to be_falsey
13
+
14
+ expect("".present?).to be_falsey
15
+ expect(" ".present?).to be_falsey
16
+ expect("a".present?).to be_truthy
17
+ end
18
+ end
19
+
20
+ context "Booleans" do
21
+ it "Requiring the gem allows the usage of blank and present" do
22
+ expect(false.blank?).to be_truthy
23
+ expect(true.blank?).to be_falsey
24
+
25
+ expect(false.present?).to be_falsey
26
+ expect(true.present?).to be_truthy
27
+ end
28
+ end
29
+
30
+ context "Numeric" do
31
+ it "Requiring the gem allows the usage of blank and present" do
32
+ expect(0.blank?).to be_falsey
33
+ expect(0.present?).to be_truthy
34
+ end
35
+ end
36
+
37
+ context "Array" do
38
+ it "Requiring the gem allows the usage of blank and present" do
39
+ expect([].blank?).to be_truthy
40
+ expect([1].blank?).to be_falsey
41
+
42
+ expect([].present?).to be_falsey
43
+ expect([1].present?).to be_truthy
44
+ end
45
+ end
46
+
47
+ context "Time" do
48
+ it "Requiring the gem allows the usage of blank and present" do
49
+ expect(Time.now.blank?).to be_falsey
50
+ expect(Time.now.present?).to be_truthy
51
+ end
52
+ end
53
+
54
+ context "Object" do
55
+ it "Requiring the gem allows the usage of blank and present" do
56
+ expect(nil.blank?).to be_truthy
57
+ expect(nil.present?).to be_falsey
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/setup"
4
+ require "present_object"
5
+
6
+ RSpec.configure do |config|
7
+ # Enable flags like --only-failures and --next-failure
8
+ config.example_status_persistence_file_path = ".rspec_status"
9
+
10
+ # Disable RSpec exposing methods globally on `Module` and `main`
11
+ config.disable_monkey_patching!
12
+
13
+ config.expect_with :rspec do |c|
14
+ c.syntax = :expect
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: present_object
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.pre.rc1
5
+ platform: ruby
6
+ authors:
7
+ - George Protacio-Karaszi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ description: A copy of ActiveSupport's present and blank objects without the extra
56
+ baggage.
57
+ email:
58
+ - georgekaraszi@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".rubocop.yml"
66
+ - ".ruby-gemset"
67
+ - ".ruby-version"
68
+ - ".travis.yml"
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - README.md
72
+ - Rakefile
73
+ - lib/present_object.rb
74
+ - lib/present_object/core_ext/regexp.rb
75
+ - lib/present_object/object/blank.rb
76
+ - lib/present_object/version.rb
77
+ - present_object.gemspec
78
+ - spec/present_object_spec.rb
79
+ - spec/spec_helper.rb
80
+ homepage: https://github.com/GeorgeKaraszi/PresentObject
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">"
96
+ - !ruby/object:Gem::Version
97
+ version: 1.3.1
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.6.14
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: A copy of ActiveSupport's present and blank objects without the extra baggage.
104
+ test_files:
105
+ - spec/present_object_spec.rb
106
+ - spec/spec_helper.rb