able 0.1.3 → 0.1.4

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: 85e8bf6fced362435c4074897de80c04b06ffbc8
4
- data.tar.gz: eeb1d7634b86c54001baad051d7a5c18c3788b71
3
+ metadata.gz: 375a99d24d70203258f5d235ade3088182097302
4
+ data.tar.gz: afecad7c5c6e6b015825221d5a0a3ac56625d28f
5
5
  SHA512:
6
- metadata.gz: e05c8bfc91052b724abd71d3e965c0f7810f11b1a60cc6cb3846dda6eb7599fd9402c54490922967640bb5169f275547c6000f617d2b01faa69b131f4ce7660d
7
- data.tar.gz: 04ba880e9155f7c3fca41d5565c2df90f7a117f5ada2865e4427feb5ac73a6792369fef33cb0638be58890f285f1b25e055e880af0e81ac5f9632db9dc68a527
6
+ metadata.gz: ca3a53d44651d77710fd9bb45b43c172009d64bf47787c5952c089a156385cdb337fb9eff6dd8bae2fb62d4b858a891e0e2612beb7e00f409db583d52050afdc
7
+ data.tar.gz: 006295e17471daa7be685f12d5f404e012a30964a9b12313b01a06807e5cf59376b184b6c735aae69448d6cff6e371c57df0614ea252bec2eefa1b0ece0eaa59
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Able
2
2
 
3
- This gem helps you to start develop new app simple. See usage instructions
3
+ This gem contains pieces of code I copy-past from one project to another one.
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,6 +20,8 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
+ ###Concerns
24
+
23
25
  1. [Emailable](https://github.com/entity1991/able/tree/master/lib/able/emailable.rb)
24
26
  2. [Fullnameable](https://github.com/entity1991/able/tree/master/lib/able/fullnameable.rb)
25
27
  `full_name` method
@@ -33,6 +35,12 @@ Or install it yourself as:
33
35
  end
34
36
  ```
35
37
 
38
+ ### Ruby class extensions
39
+
40
+ 1. [Integer](https://github.com/entity1991/able/tree/master/lib/ext/integer.rb)
41
+ 1. [Kernel](https://github.com/entity1991/able/tree/master/lib/ext/kernel.rb)
42
+ 1. [String](https://github.com/entity1991/able/tree/master/lib/ext/string.rb)
43
+
36
44
  ## Contributing
37
45
 
38
46
  Bug reports and pull requests are welcome on GitHub at [https://github.com/entity1991/able](https://github.com/entity1991/able).
data/lib/able.rb CHANGED
@@ -4,6 +4,10 @@ require 'able/emailable'
4
4
  require 'able/fullnameable'
5
5
  require 'able/tokenizer'
6
6
 
7
+ require 'ext/integer'
8
+ require 'ext/kernel'
9
+ require 'ext/string'
10
+
7
11
  module Able
8
12
  # Your code goes here...
9
13
  end
data/lib/able/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Able
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
@@ -0,0 +1,13 @@
1
+ class Integer
2
+ def to_filesize
3
+ {
4
+ 'B' => 1024,
5
+ 'KB' => 1024 * 1024,
6
+ 'MB' => 1024 * 1024 * 1024,
7
+ 'GB' => 1024 * 1024 * 1024 * 1024,
8
+ 'TB' => 1024 * 1024 * 1024 * 1024 * 1024
9
+ }.each_pair { |e, s| return "#{(self.to_f / (s / 1024)).round(2)} #{e}" if self < s }
10
+ end
11
+
12
+ alias_method :to_file_size, :to_filesize
13
+ end
data/lib/ext/kernel.rb ADDED
@@ -0,0 +1,53 @@
1
+ module Kernel
2
+
3
+ # retrying code 'attempt' times with delay 'attempt' ** 2. If last attempt failed - returns nil.
4
+ def try_to(attempt = 1, &block)
5
+ begin
6
+ yield
7
+ rescue => exception
8
+ if attempt < 5
9
+ sleep(attempt ** 2)
10
+ try_to(attempt + 1, &block)
11
+ else
12
+ Airbrake.notify(exception, error_message: "Exception from try_to block: #{exception.message}")
13
+ return nil
14
+ end
15
+ end
16
+ end
17
+
18
+ # returns spent time in milliseconds
19
+ def track_time(&block)
20
+ start = Time.now
21
+ yield block
22
+ (Time.now - start).round(3) * 1000
23
+ end
24
+
25
+ # Is good for rake tasks, migrations etc.
26
+ def each_with_progress(collection)
27
+ progress = 0
28
+
29
+ all_count = collection.count
30
+ puts_with_time "Found before: #{all_count} items."
31
+ i = 0
32
+
33
+ collection.find_each(batch_size: 1000) do |item|
34
+ yield item
35
+
36
+ i = i + 1
37
+
38
+ current_progress = ((i * 100) / all_count.to_f).floor
39
+ if current_progress > progress
40
+ progress = current_progress
41
+ puts_with_time "Done #{progress}%. #{i} of #{all_count} records."
42
+ end
43
+
44
+ end
45
+
46
+ puts_with_time "Left after: #{collection.count} items."
47
+ end
48
+
49
+ def puts_with_time(string)
50
+ puts "#{Time.now.utc.strftime('%F %T(%Z)')}. #{string}"
51
+ end
52
+
53
+ end
data/lib/ext/string.rb ADDED
@@ -0,0 +1,12 @@
1
+ class String
2
+
3
+ def methodize
4
+ gsub(/([A-Z]+)([A-Z])/,'\1_\2').
5
+ gsub(/([a-z])([A-Z])/,'\1_\2').
6
+ gsub('/' ,'__').
7
+ gsub('::','__').
8
+ gsub(' ','_').
9
+ downcase
10
+ end
11
+
12
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: able
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - entity
@@ -75,6 +75,9 @@ files:
75
75
  - lib/able/fullnameable.rb
76
76
  - lib/able/tokenizer.rb
77
77
  - lib/able/version.rb
78
+ - lib/ext/integer.rb
79
+ - lib/ext/kernel.rb
80
+ - lib/ext/string.rb
78
81
  homepage: https://github.com/entity1991/able
79
82
  licenses:
80
83
  - MIT