positive_basic_support 0.2.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8718ef05ddc328cc6d6bf268ad9a6c87800e683e
4
+ data.tar.gz: 5429e080d812ea18f1f8fb967640c8903982bb21
5
+ SHA512:
6
+ metadata.gz: a9a2da450eabb484ef679953f8aad02d27b427e7b21c08aba558f456ad098060a3625ad29e1b0a563b455c77159fb729fa8d22d70d126823ffe5610205e8542f
7
+ data.tar.gz: c3871df7a6d9f80b9d0069a3bd23a90edbd8374b2300fe979a64708e54bffd2518ea2d768c196d828d95c9b6e98ba5a0a671b9339f65899e85bbd9acaa4e2859
data/.current_version ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+
12
+ /.latest_version
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/Capfile ADDED
@@ -0,0 +1,33 @@
1
+ # Load DSL and set up stages
2
+ require 'capistrano/setup'
3
+
4
+ # Include default deployment tasks
5
+ require 'capistrano/deploy'
6
+
7
+ require 'deplo'
8
+
9
+ # Include tasks from other gems included in your Gemfile
10
+ #
11
+ # For documentation on these, see for example:
12
+ #
13
+ # https://github.com/capistrano/rvm
14
+ # https://github.com/capistrano/rbenv
15
+ # https://github.com/capistrano/chruby
16
+ # https://github.com/capistrano/bundler
17
+ # https://github.com/capistrano/rails
18
+ # https://github.com/capistrano/passenger
19
+ #
20
+ # require 'capistrano/rvm'
21
+ # require 'capistrano/rbenv'
22
+ # require 'capistrano/chruby'
23
+ # require 'capistrano/bundler'
24
+ # require 'capistrano/rails/assets'
25
+ # require 'capistrano/rails/migrations'
26
+ # require 'capistrano/passenger'
27
+
28
+ # Load custom tasks from `lib/capistrano/tasks` if you have any defined
29
+ Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
30
+
31
+ Rake::Task[:production].invoke
32
+ invoke :production
33
+ set_cap_tasks_from_deplo
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in positive_basic_support.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Shu Fujita
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # PositiveBasicSupport
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/positive_basic_support`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'positive_basic_support'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install positive_basic_support
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec positive_basic_support` to use the code located in this directory, ignoring other installed copies of this gem.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/positive_basic_support/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "positive_basic_support"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/config/deploy.rb ADDED
@@ -0,0 +1,38 @@
1
+ # config valid only for current version of Capistrano
2
+ lock '3.4.0'
3
+
4
+ set :application, 'gem_positive_basic_support'
5
+ set :repo_url, 'https://github.com/osorubeki-fujita/positive_basic_support.git'
6
+
7
+ set :pj_dir , ::File.expand_path( "#{ ::File.dirname( __FILE__ ) }/.." )
8
+ set :github_remote_name , :origin
9
+
10
+ # Default branch is :master
11
+ # ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
12
+
13
+ # Default deploy_to directory is /var/www/my_app_name
14
+ set :deploy_to, '/'
15
+
16
+ # Default value for :scm is :git
17
+ # set :scm, :git
18
+
19
+ # Default value for :format is :pretty
20
+ # set :format, :pretty
21
+
22
+ # Default value for :log_level is :debug
23
+ # set :log_level, :debug
24
+
25
+ # Default value for :pty is false
26
+ # set :pty, true
27
+
28
+ # Default value for :linked_files is []
29
+ # set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')
30
+
31
+ # Default value for linked_dirs is []
32
+ # set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
33
+
34
+ # Default value for default_env is {}
35
+ # set :default_env, { path: "/opt/ruby/bin:$PATH" }
36
+
37
+ # Default value for keep_releases is 5
38
+ # set :keep_releases, 5
@@ -0,0 +1,61 @@
1
+ # server-based syntax
2
+ # ======================
3
+ # Defines a single server with a list of roles and multiple properties.
4
+ # You can define all roles on a single server, or split them:
5
+
6
+ # server 'example.com', user: 'deploy', roles: %w{app db web}, my_property: :my_value
7
+ # server 'example.com', user: 'deploy', roles: %w{app web}, other_property: :other_value
8
+ # server 'db.example.com', user: 'deploy', roles: %w{db}
9
+
10
+
11
+
12
+ # role-based syntax
13
+ # ==================
14
+
15
+ # Defines a role with one or multiple servers. The primary server in each
16
+ # group is considered to be the first unless any hosts have the primary
17
+ # property set. Specify the username and a domain or IP for the server.
18
+ # Don't use `:all`, it's a meta role.
19
+
20
+ # role :app, %w{deploy@example.com}, my_property: :my_value
21
+ # role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value
22
+ # role :db, %w{deploy@example.com}
23
+
24
+
25
+
26
+ # Configuration
27
+ # =============
28
+ # You can set any configuration variable like in config/deploy.rb
29
+ # These variables are then only loaded and set in this stage.
30
+ # For available Capistrano configuration variables see the documentation page.
31
+ # http://capistranorb.com/documentation/getting-started/configuration/
32
+ # Feel free to add new variables to customise your setup.
33
+
34
+
35
+
36
+ # Custom SSH Options
37
+ # ==================
38
+ # You may pass any option but keep in mind that net/ssh understands a
39
+ # limited set of options, consult the Net::SSH documentation.
40
+ # http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
41
+ #
42
+ # Global options
43
+ # --------------
44
+ # set :ssh_options, {
45
+ # keys: %w(/home/rlisowski/.ssh/id_rsa),
46
+ # forward_agent: false,
47
+ # auth_methods: %w(password)
48
+ # }
49
+ #
50
+ # The server-based syntax can be used to override options:
51
+ # ------------------------------------
52
+ # server 'example.com',
53
+ # user: 'user_name',
54
+ # roles: %w{web app},
55
+ # ssh_options: {
56
+ # user: 'user_name', # overrides user setting above
57
+ # keys: %w(/home/user_name/.ssh/id_rsa),
58
+ # forward_agent: false,
59
+ # auth_methods: %w(publickey password)
60
+ # # password: 'please use keys'
61
+ # }
@@ -0,0 +1,61 @@
1
+ # server-based syntax
2
+ # ======================
3
+ # Defines a single server with a list of roles and multiple properties.
4
+ # You can define all roles on a single server, or split them:
5
+
6
+ # server 'example.com', user: 'deploy', roles: %w{app db web}, my_property: :my_value
7
+ # server 'example.com', user: 'deploy', roles: %w{app web}, other_property: :other_value
8
+ # server 'db.example.com', user: 'deploy', roles: %w{db}
9
+
10
+
11
+
12
+ # role-based syntax
13
+ # ==================
14
+
15
+ # Defines a role with one or multiple servers. The primary server in each
16
+ # group is considered to be the first unless any hosts have the primary
17
+ # property set. Specify the username and a domain or IP for the server.
18
+ # Don't use `:all`, it's a meta role.
19
+
20
+ # role :app, %w{deploy@example.com}, my_property: :my_value
21
+ # role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value
22
+ # role :db, %w{deploy@example.com}
23
+
24
+
25
+
26
+ # Configuration
27
+ # =============
28
+ # You can set any configuration variable like in config/deploy.rb
29
+ # These variables are then only loaded and set in this stage.
30
+ # For available Capistrano configuration variables see the documentation page.
31
+ # http://capistranorb.com/documentation/getting-started/configuration/
32
+ # Feel free to add new variables to customise your setup.
33
+
34
+
35
+
36
+ # Custom SSH Options
37
+ # ==================
38
+ # You may pass any option but keep in mind that net/ssh understands a
39
+ # limited set of options, consult the Net::SSH documentation.
40
+ # http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
41
+ #
42
+ # Global options
43
+ # --------------
44
+ # set :ssh_options, {
45
+ # keys: %w(/home/rlisowski/.ssh/id_rsa),
46
+ # forward_agent: false,
47
+ # auth_methods: %w(password)
48
+ # }
49
+ #
50
+ # The server-based syntax can be used to override options:
51
+ # ------------------------------------
52
+ # server 'example.com',
53
+ # user: 'user_name',
54
+ # roles: %w{web app},
55
+ # ssh_options: {
56
+ # user: 'user_name', # overrides user setting above
57
+ # keys: %w(/home/user_name/.ssh/id_rsa),
58
+ # forward_agent: false,
59
+ # auth_methods: %w(publickey password)
60
+ # # password: 'please use keys'
61
+ # }
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "positive_basic_support"
@@ -0,0 +1,33 @@
1
+ require "positive_basic_support/version"
2
+
3
+ require "active_support"
4
+ require "active_support/core_ext"
5
+
6
+ require_relative "positive_basic_support/modules"
7
+ require_relative "positive_basic_support/modules/constants_as_class_methods"
8
+
9
+ require_relative "positive_basic_support/basic_object_ext"
10
+ require_relative "positive_basic_support/checker"
11
+ require_relative "positive_basic_support/checker/error_factory"
12
+
13
+ module PositiveBasicSupport
14
+
15
+ extend ::ActiveSupport::Concern
16
+
17
+ included do
18
+ ::BasicObject.class_eval do
19
+ include ::PositiveBasicSupport::BasicObjectExt
20
+ end
21
+
22
+ ::Module.class_eval do
23
+ include ::PositiveBasicSupport::BasicObjectExt::ClassMethods
24
+ end
25
+
26
+ ::BasicObject.class_eval do
27
+ include PositiveBasicSupport::Checker
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ include PositiveBasicSupport
@@ -0,0 +1,298 @@
1
+ module PositiveBasicSupport::BasicObjectExt
2
+
3
+ extend ::ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+
7
+ # @!group 名前空間に関するメソッド
8
+
9
+ # 上位の名前空間のリスト(すべて)
10
+ # @return [::Array]
11
+ # @example
12
+ # module UpperNamespaceTest
13
+ # module A
14
+ # module B
15
+ # module C
16
+ # end
17
+ # module C::D
18
+ # end
19
+ # end
20
+ # end
21
+ # end
22
+ #
23
+ # ::UpperNamespaceTest::A.upper_namespaces => [ ::UpperNamespaceTest ]
24
+ # ::UpperNamespaceTest::A::B.upper_namespaces => [ ::UpperNamespaceTest::A , ::UpperNamespaceTest ]
25
+ def upper_namespaces( _has_upper_namespaces = nil )
26
+ _has_upper_namespaces ||= has_upper_namespaces?
27
+ if _has_upper_namespaces
28
+ splited = self.name.split( "::" )[0..-2]
29
+ ary = ::Array.new
30
+ for i in 0..( splited.length - 1 )
31
+ ary << eval( splited[ 0..i ].join( "::" ) )
32
+ end
33
+ ary.reverse
34
+ else
35
+ nil
36
+ end
37
+ end
38
+
39
+ # 上位の名前空間が存在するか否かを判定するメソッド
40
+ # @return [Boolean]
41
+ # @example
42
+ # UpperNamespaceTest.has_upper_namespaces? => false
43
+ # UpperNamespaceTest::A.has_upper_namespaces? => true
44
+ # UpperNamespaceTest::A::B.has_upper_namespaces? => true
45
+ def has_upper_namespaces?
46
+ # upper_namespaces.length > 1
47
+ /\:\:/ === name
48
+ end
49
+
50
+ # 上位の名前空間のリスト(すぐ上のみ)
51
+ # @return [::Class (Const)]example
52
+ # UpperNamespaceTest.upper_namespace => nil
53
+ # UpperNamespaceTest::A.upper_namespace => UpperNamespaceTest
54
+ # UpperNamespaceTest::A::B.upper_namespace => UpperNamespaceTest::A
55
+ def upper_namespace
56
+ _has_upper_namespaces = has_upper_namespaces?
57
+ if _has_upper_namespaces
58
+ upper_namespaces( _has_upper_namespaces ).first
59
+ else
60
+ nil
61
+ end
62
+ end
63
+
64
+ # @!endgroup
65
+
66
+ end
67
+
68
+ alias :meaningful? :present?
69
+
70
+ # @!group クラスの判定 - 数値
71
+
72
+ # 数値か否かを判定するメソッド
73
+ # @return [Boolean]
74
+ # @example
75
+ # 2.number? => true
76
+ # -17.number? => true
77
+ # 3.5.number? => true
78
+ # -1.618.number? => true
79
+ #
80
+ # "abc".number? => false
81
+ # [1.5, 1.6, 1.7].number? => false
82
+ def number?
83
+ kind_of?( ::Numeric )
84
+ end
85
+
86
+ # 整数か否かを判定するメソッド
87
+ # @return [Boolean]
88
+ # @example
89
+ # 13.integer? => true
90
+ # -19.integer? => true
91
+ #
92
+ # 3.141592.integer? => false
93
+ # -2.71828.integer? => false
94
+ #
95
+ # "pqr".integer? => false
96
+ # [3, 4, 5].integer? => false
97
+ def integer?
98
+ kind_of?( ::Integer )
99
+ end
100
+
101
+
102
+ # 自然数か否かを判定するメソッド
103
+ # @param include_zero [Boolean] 0を含めるか否か(default: false)
104
+ # @return [Boolean]
105
+ # @example
106
+ # 7.natural_number? => true
107
+ # 7.natural_number?( include_zero: false ) => true
108
+ # 7.natural_number?( include_zero: true ) => true
109
+ #
110
+ # 0.natural_number? => false
111
+ # 0.natural_number?( include_zero: false ) => false
112
+ # 0.natural_number?( include_zero: true ) => true
113
+ #
114
+ # -5.natural_number? => false
115
+ # -5.natural_number?( include_zero: false ) => false
116
+ # -5.natural_number?( include_zero: true ) => false
117
+ #
118
+ # 1.7320508.natural_number? => false
119
+ # -2.2360979.natural_number? => false
120
+ #
121
+ # "あいうえお".natural_number? => false
122
+ # "かきくけこ".natural_number?( include_zero: false ) => false
123
+ # "さしすせそ".natural_number?( include_zero: true ) => false
124
+ #
125
+ # [3, 1, 4, 1, 5].natural_number? => false
126
+ # ["a", "b", "c"].natural_number?( include_zero: false ) => false
127
+ # [2, 7, 1, 8, 2, 8].natural_number?( include_zero: true ) => false
128
+ # @note 内部で {#natural_number_including_zero?} , {#natural_number_except_for_zero?} を利用している.
129
+ def natural_number?( include_zero: false )
130
+ include_zero.should_be( :boolean , variable_name: :include_zero )
131
+
132
+ if include_zero
133
+ natural_number_including_zero?
134
+ else
135
+ natural_number_except_for_zero?
136
+ end
137
+ end
138
+
139
+ # 「自然数または0」か否かを判定するメソッド(0 に対しても true を返す)
140
+ # @return [Boolean]
141
+ # @example
142
+ # 13.natural_number_including_zero? => true
143
+ #
144
+ # 0.natural_number_including_zero? => true
145
+ #
146
+ # 6.7.natural_number_including_zero? => false
147
+ # -2.236.natural_number_including_zero? => false
148
+ # -83.natural_number_including_zero? => false
149
+ #
150
+ # "あいうえお".natural_number_or_zero? => false
151
+ # [1, 1, 2, 3, 5, 8].natural_number_or_zero? => false
152
+ def natural_number_including_zero?
153
+ integer? and self >= 0
154
+ end
155
+ alias :natural_number_or_zero? :natural_number_including_zero?
156
+
157
+ # @!group クラスの判定 - 文字列
158
+
159
+ # 文字列(String クラスのインスタンス)か否かを判定するメソッド
160
+ # @return [Boolean]
161
+ # @example
162
+ # "Hello, World!".string? => true
163
+ # "あいうえお".string? => true
164
+ # "13".string? => true
165
+ # 13.string? => false
166
+ # 13.to_s.string? => true
167
+ # true.string? => false
168
+ # false.string? => false
169
+ # nil.string? => false
170
+ # [1, 1, 2, 3, 5, 8].string? => false
171
+ # [1, 1, 2, 3, 5, 8].map( &:to_s ).all?( &:string? ) => true
172
+ def string?( include_subclasses: false )
173
+ class_decision( ::String , include_subclasses )
174
+ end
175
+
176
+ # @!group クラスの判定 - シンボル
177
+
178
+ # Symbol クラスのインスタンスか否かを判定するメソッド
179
+ # @return [Boolean]
180
+ # @example
181
+ # "Hello, World!".symbol? => false
182
+ # :instance_method.symbol? => true
183
+ # :"Hello, World!".symbol? => true
184
+ # :instance_method.to_s.symbol? => false
185
+ # "あいうえお".symbol? => false
186
+ # "13".symbol? => false
187
+ # 13.symbol? => false
188
+ # true.symbol? => false
189
+ # false.symbol? => false
190
+ # nil.symbol? => false
191
+ # [1, 1, 2, 3, 5, 8].symbol? => false
192
+ # [1, 1, 2, 3, 5, 8].all?( &:symbol? ) => false
193
+ # [:a, :b, :c, :d, :e, :f].all?( &:symbol? ) => true
194
+ # [:a, :b, :c, :d, :e, :f].map( &:to_s ).all?( &:symbol? ) => false
195
+ def symbol?
196
+ instance_of?( ::Symbol )
197
+ end
198
+
199
+ # @!group クラスの判定 - 文字列・シンボル
200
+
201
+ # {String} クラスまたは {Symbol} クラスのインスタンスか否かを判定するメソッド
202
+ # @return [Boolean]
203
+ # :instance_method.string_or_symbol? => true
204
+ # :instance_method.to_s.string_or_symbol? => true
205
+ # "Hello, World!".string_or_symbol? => true
206
+ # :"Hello, World!".string_or_symbol? => true
207
+ # "あいうえお".string_or_symbol? => true
208
+ # "13".string_or_symbol? => true
209
+ # 13.string_or_symbol? => false
210
+ # 13.to_s.string_or_symbol? => true
211
+ # true.string_or_symbol? => false
212
+ # false.string_or_symbol? => false
213
+ # nil.string_or_symbol? => false
214
+ # [1, 1, 2, 3, 5, 8].string_or_symbol? => false
215
+ # [1, 1, 2, 3, 5, 8].map( &:to_s ).all?( &:string_or_symbol? ) => true
216
+ # [:a, :b, :c, :d, :e, :f].all?( &:string_or_symbol? ) => true
217
+ # [:a, :b, :c, :d, :e, :f].map( &:to_s ).all?( &:string_or_symbol? ) => true
218
+ # [:a, "b", :c, "d", "e", :f].map( &:to_s ).all?( &:string_or_symbol? ) => true
219
+ def string_or_symbol?( include_subclasses: false )
220
+ string?( include_subclasses: include_subclasses ) or symbol?
221
+ end
222
+
223
+ # @!group クラスの判定 - 正規表現
224
+ def regexp?
225
+ instance_of?( ::Regexp )
226
+ end
227
+
228
+ # @!group クラスの判定 - 配列
229
+
230
+ def array?( include_subclasses: false )
231
+ class_decision( ::Array , include_subclasses )
232
+ end
233
+
234
+ def hash?
235
+ instance_of?( ::Hash )
236
+ end
237
+
238
+ # @!group クラスの判定 - 真偽値
239
+
240
+ # 真偽値か否かを判定するメソッド
241
+ # @return [Boolean] self が真偽値(true または false)の場合に true,それ以外の場合に false を返す.
242
+ # @example
243
+ # true.boolean? => true
244
+ # false.boolean? => true
245
+ # nil.boolean? => false
246
+ #
247
+ # 2.boolean? => false
248
+ # "すべてのクレタ島人は嘘つきである。".boolean? => false
249
+ def boolean?
250
+ instance_of?( ::TrueClass ) or instance_of?( ::FalseClass )
251
+ end
252
+
253
+ # 「真偽値または nil 」か否かを判定するメソッド
254
+ # @return [Boolean] self が真偽値(true または false)または nil の場合に true ,それ以外の場合に false を返す.
255
+ # @example
256
+ # true.boolean_or_nil? => true
257
+ # false.boolean_or_nil? => true
258
+ # nil.boolean_or_nil? => true
259
+ #
260
+ # 3.boolean_or_nil? => false
261
+ # "王様は裸だ!".boolean_or_nil? => false
262
+ def boolean_or_nil?
263
+ boolean? or nil?
264
+ end
265
+
266
+ # @!endgroup
267
+
268
+ private
269
+
270
+ def class_decision( class_name , include_subclasses )
271
+ include_subclasses.should_be( :boolean , variable_name: :include_subclasses , variable_number: 2 )
272
+ if include_subclasses
273
+ kind_of?( class_name )
274
+ else
275
+ instance_of?( class_name )
276
+ end
277
+ end
278
+
279
+ # 自然数か否かを判定するメソッド(0 に対しては true を返さない)
280
+ # @return [Boolean]
281
+ # @note このメソッドは,{Object#error_message_of_class_sub_check_some_variables} と {Object#natural_number?} で使用するためのもの.
282
+ # 通常は{Object#natural_number?} を利用すること.
283
+ # @example
284
+ # 2.send( :natural_number_except_for_zero? => true
285
+ #
286
+ # 0.send( :natural_number_except_for_zero? => false
287
+ #
288
+ # 4.8.send( :natural_number_except_for_zero? => false
289
+ # -1.732.send( :natural_number_except_for_zero? => false
290
+ # -71.send( :natural_number_except_for_zero? => false
291
+ #
292
+ # "あいうえお".send( :natural_number_except_for_zero? => false
293
+ # [10, 20, 30].send( :natural_number_except_for_zero? => false
294
+ def natural_number_except_for_zero?
295
+ integer? and self > 0
296
+ end
297
+
298
+ end
@@ -0,0 +1,15 @@
1
+ module PositiveBasicSupport::Checker
2
+
3
+ def should_be( var , variable_number: nil , variable_name: nil )
4
+ send( "should_be_#{var}" , variable_number: variable_number , variable_name: variable_name )
5
+ end
6
+
7
+ private
8
+
9
+ def should_be_boolean( variable_number: nil , variable_name: nil )
10
+ unless boolean?
11
+ ::PositiveBasicSupport::Checker::ErrorFactory.change_paragraph_and_indent( "" )
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,14 @@
1
+ module PositiveBasicSupport::Checker::ErrorFactory
2
+
3
+ # エラーメッセージの書式を整えるためのメソッド
4
+ # @param str [String] エラーメッセージの基本部分
5
+ # @return [String]
6
+ def self.change_paragraph_and_indent( str , indent: 4 )
7
+ prefix = "\n" + " " * indent
8
+ unless str.string?
9
+ raise prefix + "The variable \'str\' should be an instance of \'String Class\'."
10
+ end
11
+ raise prefix + str
12
+ end
13
+
14
+ end
@@ -0,0 +1,2 @@
1
+ module PositiveBasicSupport::Modules
2
+ end
@@ -0,0 +1,35 @@
1
+ # 定数をクラスメソッドのように扱う機能を提供するモジュール
2
+ # @note このモジュールを include したクラスやモジュールでは、定数をクラスメソッドのように呼び出すことができる。
3
+ # @note クラスメソッドのように呼び出したくない定数がある場合は、include されたクラスの内部でその定数の名称(シンボル)のリスト(配列)を private なクラスメソッド constants_not_converted_by_method_missing で指定する。
4
+ # @note {TokyoMetro} に対しては、このモジュールが定義されているファイルで include している。
5
+ module PositiveBasicSupport::Modules::ConstantsAsClassMethods
6
+
7
+ extend ::ActiveSupport::Concern
8
+
9
+ module ClassMethods
10
+
11
+ def method_missing( method_name , *args )
12
+ if costants_converted_by_method_missing.include?( method_name.upcase )
13
+ return const_get( method_name.upcase )
14
+ else
15
+ super( method_name , *args )
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def costants_converted_by_method_missing
22
+ constants( false ) - constants_not_converted_by_method_missing
23
+ end
24
+
25
+ def constants_not_converted_by_method_missing
26
+ []
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+
33
+ ::PositiveBasicSupport.module_eval do
34
+ include ::PositiveBasicSupport::Modules::ConstantsAsClassMethods
35
+ end
@@ -0,0 +1,3 @@
1
+ module PositiveBasicSupport
2
+ VERSION = ::File.open( "#{ ::File.dirname( __FILE__ ) }/../../.current_version" , "r:utf-8" ).read.chomp
3
+ end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'positive_basic_support/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "positive_basic_support"
8
+ spec.version = PositiveBasicSupport::VERSION
9
+ spec.authors = ["Shu Fujita"]
10
+ spec.email = ["osorubeki.fujita@gmail.com"]
11
+
12
+ spec.summary = "This gem provides basic and useful extension to Ruby built-in classes."
13
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ spec.homepage = "https://github.com/osorubeki-fujita/positive_basic_support"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+ # else
21
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ # end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.9"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec"
32
+
33
+ spec.add_development_dependency "capistrano"
34
+ spec.add_development_dependency "deplo", ">= 0.1.4"
35
+
36
+ spec.add_runtime_dependency "activesupport" , ">= 4.2.1"
37
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: positive_basic_support
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Shu Fujita
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-20 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.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
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.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: capistrano
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: deplo
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.1.4
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.1.4
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 4.2.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 4.2.1
97
+ description:
98
+ email:
99
+ - osorubeki.fujita@gmail.com
100
+ executables:
101
+ - positive_basic_support
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".current_version"
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - Capfile
110
+ - Gemfile
111
+ - LICENSE
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - config/deploy.rb
117
+ - config/deploy/production.rb
118
+ - config/deploy/staging.rb
119
+ - exe/positive_basic_support
120
+ - lib/positive_basic_support.rb
121
+ - lib/positive_basic_support/basic_object_ext.rb
122
+ - lib/positive_basic_support/checker.rb
123
+ - lib/positive_basic_support/checker/error_factory.rb
124
+ - lib/positive_basic_support/modules.rb
125
+ - lib/positive_basic_support/modules/constants_as_class_methods.rb
126
+ - lib/positive_basic_support/version.rb
127
+ - positive_basic_support.gemspec
128
+ homepage: https://github.com/osorubeki-fujita/positive_basic_support
129
+ licenses: []
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.2.3
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: This gem provides basic and useful extension to Ruby built-in classes.
151
+ test_files: []
152
+ has_rdoc: