ecraft-extensions 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +7 -0
- data/.ruby-version +1 -1
- data/.travis.yml +1 -2
- data/Gemfile +0 -1
- data/README.md +13 -20
- data/bin/console +23 -0
- data/bin/setup +11 -0
- data/ecraft-extensions.gemspec +2 -2
- data/lib/ecraft/extensions/bigdecimal.rb +6 -6
- data/lib/ecraft/extensions/mixins/hashable.rb +7 -7
- data/lib/ecraft/extensions/ostruct.rb +1 -1
- data/lib/ecraft/extensions/string.rb +2 -28
- data/lib/ecraft/extensions/time.rb +2 -1
- data/lib/ecraft/extensions/version.rb +1 -1
- metadata +7 -6
- data/lib/ecraft/extensions/all.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3eedda0b4814dbad903bb2eb6cc867700c5c484a976a76b92a768c217b5d81b9
|
4
|
+
data.tar.gz: f635a3e21a66a8c0adaa62b2271870de37fe7ce1fb3251672ce2dc24afb3ff2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc5369edb007040cf10a5996cef0d821d8e81f8fc54a46c4f88d5d9fe9a83fac014b9cf0a4e0d22873b0e456edc7b9f23b30e9335f88ba92ba1a939caa273447
|
7
|
+
data.tar.gz: f7a63adbbb9abb5fb5c51276814aa3ee45f7ef898291248982e5687b66efee119e6da79fc4e04981ba2e54eb34fc3e171ef9a0e197e833a75871118be9e7afcf
|
data/.rubocop.yml
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
AllCops:
|
2
2
|
TargetRubyVersion: 2.3
|
3
3
|
DisplayCopNames: true
|
4
|
+
DisplayStyleGuide: true
|
5
|
+
ExtraDetails: true
|
4
6
|
|
5
7
|
Layout/MultilineOperationIndentation:
|
6
8
|
EnforcedStyle: indented
|
@@ -30,6 +32,11 @@ Style/Documentation:
|
|
30
32
|
Enabled: false
|
31
33
|
Style/Encoding:
|
32
34
|
Enabled: false
|
35
|
+
|
36
|
+
# Pending a Rubocop release with https://github.com/bbatsov/rubocop/issues/5245 included.
|
37
|
+
Style/FormatStringToken:
|
38
|
+
Enabled: false
|
39
|
+
|
33
40
|
Style/NumericPredicate:
|
34
41
|
Enabled: false
|
35
42
|
Style/FrozenStringLiteralComment:
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.5
|
data/.travis.yml
CHANGED
@@ -8,9 +8,8 @@ env:
|
|
8
8
|
- "JRUBY_OPTS=--debug"
|
9
9
|
|
10
10
|
before_install:
|
11
|
-
- rm -rf ~/.rvm && if [ ! -d "$HOME/jruby-bin" ]; then mkdir -p ~/jruby-bin && pushd ~/jruby-bin && curl -o- -L https://s3.amazonaws.com/jruby.org/downloads/9.1.
|
11
|
+
- rm -rf ~/.rvm && if [ ! -d "$HOME/jruby-bin" ]; then mkdir -p ~/jruby-bin && pushd ~/jruby-bin && curl -o- -L https://s3.amazonaws.com/jruby.org/downloads/9.1.15.0/jruby-bin-9.1.15.0.tar.gz | tar xzf - --strip-components=1 && popd ; fi
|
12
12
|
- export PATH="$HOME/jruby-bin/bin:$PATH"
|
13
13
|
- gem install bundler
|
14
|
-
- gem update --system
|
15
14
|
|
16
15
|
cache: bundler
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
This code contains some useful extension methods to various Ruby classes.
|
6
6
|
|
7
|
-
It also contains a
|
7
|
+
It also contains a mixin in the `Ecraft::Extensions::Mixins` module.
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -24,25 +24,20 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
|
-
Preferred approach:
|
28
|
-
|
29
27
|
```ruby
|
30
28
|
# To load a specific extension:
|
31
29
|
require 'ecraft/extensions/bigdecimal'
|
32
30
|
```
|
33
31
|
|
34
|
-
|
32
|
+
## Development
|
35
33
|
|
36
|
-
|
37
|
-
# To load _all_ core extensions. USE WITH GREAT CARE, since this could cause conflicts with other libraries.
|
38
|
-
require 'ecraft/extensions/all'
|
39
|
-
```
|
34
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
40
35
|
|
41
|
-
|
36
|
+
Then, run `rake spec` to run the tests.
|
42
37
|
|
43
|
-
|
38
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
44
39
|
|
45
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
40
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
46
41
|
|
47
42
|
## Contributing
|
48
43
|
|
@@ -52,29 +47,27 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/ecraft
|
|
52
47
|
|
53
48
|
We strive to write documentation inline in [YARD](http://yardoc.org) format.
|
54
49
|
|
55
|
-
###
|
50
|
+
### Preview documentation locally
|
51
|
+
|
56
52
|
```
|
57
53
|
bundle exec yard server -r
|
58
54
|
```
|
59
55
|
|
60
|
-
Check the locally served documentation at http://localhost:8808/
|
56
|
+
Check the locally served documentation at [http://localhost:8808/](http://localhost:8808/).
|
61
57
|
|
62
58
|
### Releasing a new version
|
63
59
|
|
64
60
|
- Bump the version in `version.rb`
|
65
61
|
- Create the tag:
|
66
|
-
|
67
62
|
```
|
68
|
-
$ git release v1.0.x
|
63
|
+
$ git release v1.0.x
|
69
64
|
```
|
70
|
-
|
71
|
-
- Build the gemfile and push it to Rubygems.org:
|
72
|
-
|
65
|
+
- Build the `.gem` file and push it to Rubygems.org:
|
73
66
|
```shell
|
74
67
|
$ bundle exec rake build release
|
75
68
|
```
|
76
|
-
|
77
|
-
|
69
|
+
- Generate the changelog (`cargo install changelog-rs && changelog-rs .`) and
|
70
|
+
copy the relevant lines to [the releases page](https://github.com/ecraft/ecraft-extensions/releases).
|
78
71
|
|
79
72
|
### License
|
80
73
|
|
data/bin/console
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'irb'
|
4
|
+
require 'irb/completion' # easy tab completion
|
5
|
+
|
6
|
+
require 'bundler/setup'
|
7
|
+
Bundler.require
|
8
|
+
|
9
|
+
$LOAD_PATH << './lib'
|
10
|
+
|
11
|
+
require 'ecraft/extensions'
|
12
|
+
require 'ecraft/extensions/bigdecimal'
|
13
|
+
require 'ecraft/extensions/date'
|
14
|
+
require 'ecraft/extensions/datetime'
|
15
|
+
require 'ecraft/extensions/ostruct'
|
16
|
+
require 'ecraft/extensions/string'
|
17
|
+
require 'ecraft/extensions/time'
|
18
|
+
|
19
|
+
puts "<#{$PROGRAM_NAME}> Starting IRB with each file in ecraft/extensions/ required"
|
20
|
+
puts
|
21
|
+
puts "<#{$PROGRAM_NAME}> To try the mixin, require 'ecraft/extensions/mixins/hashable'"
|
22
|
+
|
23
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env sh
|
2
|
+
|
3
|
+
echo "<$0> Installing prerequisites..."
|
4
|
+
|
5
|
+
which bundler || gem install bundler
|
6
|
+
bundle check || bundle install
|
7
|
+
|
8
|
+
echo "<$0> Done installing prerequisites!"
|
9
|
+
echo
|
10
|
+
echo "Explore this library using bin/console - an IRB with lib/ in the \$LOAD_PATH and this library required."
|
11
|
+
echo
|
data/ecraft-extensions.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
lib = File.expand_path('
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
5
|
require 'ecraft/extensions/version'
|
6
6
|
|
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency 'guard-rspec', '~> 4.7'
|
29
29
|
spec.add_development_dependency 'rake'
|
30
30
|
spec.add_development_dependency 'rspec'
|
31
|
-
spec.add_development_dependency 'rubocop', '~> 0.
|
31
|
+
spec.add_development_dependency 'rubocop', '~> 0.51'
|
32
32
|
spec.add_development_dependency 'simplecov'
|
33
33
|
spec.add_development_dependency 'yard'
|
34
34
|
end
|
@@ -23,7 +23,7 @@ class ::BigDecimal
|
|
23
23
|
# Values without any fraction digits will use `Fixnum` form, where values with a fractional part will use `Float` form.
|
24
24
|
#
|
25
25
|
# @return [String]
|
26
|
-
def to_json(*
|
26
|
+
def to_json(*_args)
|
27
27
|
to_s
|
28
28
|
end
|
29
29
|
|
@@ -31,14 +31,14 @@ class ::BigDecimal
|
|
31
31
|
#
|
32
32
|
# Values without any fraction digits will use `Fixnum` form, where values with a fractional part will use `Float` form.
|
33
33
|
#
|
34
|
-
# @param
|
35
|
-
# called using this parameter to provide the same semantics as the original method.
|
34
|
+
# @param string_format [String] The format that should be used for the conversion. If provided, the original `to_s`
|
35
|
+
# implementation will be called using this parameter to provide the same semantics as the original method.
|
36
36
|
# @return [String]
|
37
|
-
def to_s(
|
38
|
-
if
|
37
|
+
def to_s(string_format = nil)
|
38
|
+
if string_format.nil?
|
39
39
|
to_s_original('F').gsub(/\.0$/, '')
|
40
40
|
else
|
41
|
-
to_s_original(
|
41
|
+
to_s_original(string_format)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -47,13 +47,13 @@ module Ecraft
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
def value_type?(
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
50
|
+
def value_type?(value)
|
51
|
+
value.is_a?(BigDecimal) ||
|
52
|
+
value.is_a?(Integer) ||
|
53
|
+
value.is_a?(Float) ||
|
54
|
+
value.is_a?(String) ||
|
55
|
+
value.is_a?(TrueClass) ||
|
56
|
+
value.is_a?(FalseClass)
|
57
57
|
end
|
58
58
|
|
59
59
|
def strip_string_recurse_enumerable_values(hash)
|
@@ -1,21 +1,9 @@
|
|
1
1
|
class ::String
|
2
2
|
# These methods should not be used in new code
|
3
|
-
# Instead use
|
3
|
+
# Instead use the examples provided.
|
4
4
|
|
5
|
-
#
|
6
|
-
# require 'active_support/core_ext/string/inflections'
|
5
|
+
# Don't use! Instead, write like this:
|
7
6
|
#
|
8
|
-
# 'active_support_string'.camelize # result: "ActiveSupportString"
|
9
|
-
def to_camelcase
|
10
|
-
separators = ['_', '\s']
|
11
|
-
str = dup
|
12
|
-
separators.each do |s|
|
13
|
-
str = str.gsub(/(?:#{s}+)([a-z])/) { Regexp.last_match(1).upcase }
|
14
|
-
end
|
15
|
-
str = str.gsub(/(\A|\s)([a-z])/) { Regexp.last_match(1) + Regexp.last_match(2).upcase }
|
16
|
-
str
|
17
|
-
end
|
18
|
-
|
19
7
|
# require 'active_support'
|
20
8
|
# require 'active_support/core_ext/string/inflections'
|
21
9
|
#
|
@@ -24,20 +12,6 @@ class ::String
|
|
24
12
|
gsub(/\B[A-Z]/, '_\&').downcase
|
25
13
|
end
|
26
14
|
|
27
|
-
# require 'active_support'
|
28
|
-
# require 'active_support/core_ext/string/inflections'
|
29
|
-
# 'Foo::Bar'.constantize # => Foo::Bar
|
30
|
-
def to_class
|
31
|
-
chain = split '::'
|
32
|
-
klass = Kernel
|
33
|
-
chain.each do |klass_string|
|
34
|
-
klass = klass.const_get klass_string
|
35
|
-
end
|
36
|
-
klass.is_a?(Class) ? klass : nil
|
37
|
-
rescue NameError
|
38
|
-
nil
|
39
|
-
end
|
40
|
-
|
41
15
|
def to_bool
|
42
16
|
!self !~ /^(true|t|yes|y|1)$/i
|
43
17
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'json/add/core'
|
3
|
+
require 'time'
|
3
4
|
|
4
5
|
class ::Time
|
5
6
|
def as_ms
|
6
7
|
to_i * 1000 + usec / 1000
|
7
8
|
end
|
8
9
|
|
9
|
-
def to_json(*
|
10
|
+
def to_json(*_args)
|
10
11
|
# Use the precision provided in our receiver, but only up to milliseconds at max. Objects lacking the fraction part
|
11
12
|
# altogether will be serialized without fraction part using this algorithm.
|
12
13
|
fraction_digits = [nsec.to_s.sub(/0+$/, '').length, 3].min
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ecraft-extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tre Kronor
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '0.
|
117
|
+
version: '0.51'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '0.
|
124
|
+
version: '0.51'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: simplecov
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -168,9 +168,10 @@ files:
|
|
168
168
|
- LICENSE
|
169
169
|
- README.md
|
170
170
|
- Rakefile
|
171
|
+
- bin/console
|
172
|
+
- bin/setup
|
171
173
|
- ecraft-extensions.gemspec
|
172
174
|
- lib/ecraft/extensions.rb
|
173
|
-
- lib/ecraft/extensions/all.rb
|
174
175
|
- lib/ecraft/extensions/bigdecimal.rb
|
175
176
|
- lib/ecraft/extensions/date.rb
|
176
177
|
- lib/ecraft/extensions/datetime.rb
|
@@ -200,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
201
|
version: '0'
|
201
202
|
requirements: []
|
202
203
|
rubyforge_project:
|
203
|
-
rubygems_version: 2.6
|
204
|
+
rubygems_version: 2.7.6
|
204
205
|
signing_key:
|
205
206
|
specification_version: 4
|
206
207
|
summary: eCraft Extensions
|
@@ -1,7 +0,0 @@
|
|
1
|
-
# Requiring this file will activate _all_ the "core extensions" defined in ecraft-extensions. This may or may not be what you want.
|
2
|
-
# It is usually a better, safer approach to selectively require only the parts you know that you need, since core extensions _can_
|
3
|
-
# potentially cause conflicts with other libraries extending core classes (such as ActiveSupport).
|
4
|
-
require 'ecraft/extensions/bigdecimal'
|
5
|
-
require 'ecraft/extensions/date'
|
6
|
-
require 'ecraft/extensions/datetime'
|
7
|
-
require 'ecraft/extensions/ostruct'
|