asynchronize 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eac19fda33067270bc4464149d1f02a9561cd6a994e004f9e73c0b288ae38f5c
4
- data.tar.gz: 55301cee6db401579e3d8836c6485b4ae33e76f6319f98e6853f151076c77a83
3
+ metadata.gz: 3f84e1c57b42abe8917434680f2a3889a4edc2608af231513f3b24bbe77d2e2c
4
+ data.tar.gz: 8dabfe07d60a388bf73a2b7c2c3b36a8d941bf0f8502bd425b4736c2ec81fc2f
5
5
  SHA512:
6
- metadata.gz: 1c06a933de8ec8aab5f2f97bf0943b5405a02ff3ff74f3612506cab6eb74117ac090f1810b5e3aa1a52b98babae51499fe8319c773e74cf41f6dbfa106d62c6b
7
- data.tar.gz: 19661f53978d370e1cf80b34c1ee5a19bb7575a7f5600752ddd67960a4da6dc9148f3ac6c52e1cb06f249f99281cc6bc247e14642728fa4e6080552b8235ab9d
6
+ metadata.gz: 23744ccb079b4e39828a9d11a46be4a56e97869f88a9e99661685fc405fa609ed92a046ce22b3642670028ccf951c5558246269418967826741184cfbf43c206
7
+ data.tar.gz: 2442aaf5bcc17538b569c00fd28b76fdfb9451d25160b47b1763e7237238d22309c49acac4c141745226e4a07f665e0feb691748d0303ea480dd75a7e06d6052
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Kenneth Cochran
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.
@@ -23,11 +23,10 @@ module Asynchronize
23
23
  # @example To add any number of methods to be asynchronized.
24
24
  # asynchronize :method1, :method2, :methodn
25
25
  def self.asynchronize(*methods)
26
- @methods_to_async.merge(methods)
26
+ @methods_to_async.merge(methods.map {|m| m.hash})
27
27
  methods.each do |method|
28
28
  # If it's not defined yet, we'll get it with method_added
29
- next unless method_defined?(method)
30
- Asynchronize.create_new_method(method, self)
29
+ Asynchronize.create_new_method(method, self) if method_defined?(method)
31
30
  end
32
31
  end
33
32
 
@@ -47,10 +46,10 @@ module Asynchronize
47
46
  # Return if this is an inherited class that hasn't included asynchronize
48
47
  return if @methods_asyncing.nil?
49
48
  # Return if we're already processing this method
50
- return if @methods_asyncing.include?(method)
51
- @methods_asyncing.add(method)
49
+ return if @methods_asyncing.include?(method.hash)
50
+ @methods_asyncing.add(method.hash)
52
51
  self.old_method_added(method) if self.methods.include?(:old_method_added)
53
- return unless @methods_to_async.include?(method)
52
+ return unless @methods_to_async.include?(method.hash)
54
53
  # This will delete from @methods_asyncing
55
54
  Asynchronize.create_new_method(method, self)
56
55
  end
@@ -62,15 +61,13 @@ module Asynchronize
62
61
  def self.create_new_method(method, klass)
63
62
  klass.instance_eval do
64
63
  old_method = instance_method(method)
65
- # Can't just store the method name, since it would break if the method
66
- # was redefined.
67
- return if @asynced_methods.include?(old_method)
64
+ return if @asynced_methods.include?(old_method.hash)
68
65
  undef_method(method)
69
66
 
70
- @methods_asyncing.add(method)
67
+ @methods_asyncing.add(method.hash)
71
68
  define_method(method, Asynchronize._build_new_method(old_method))
72
- @methods_asyncing.delete(method)
73
- @asynced_methods.add(instance_method(method))
69
+ @methods_asyncing.delete(method.hash)
70
+ @asynced_methods.add(instance_method(method).hash)
74
71
  end
75
72
  end
76
73
 
data/readme.md CHANGED
@@ -58,7 +58,7 @@ problems I didn't have. Now, just call asynchronize to make any method
58
58
  asynchronous.
59
59
 
60
60
  ## Versioning Policy
61
- Once I feel like this is ready for production code - version 1.0.0, this project
61
+ Once I feel like this is ready for production code, version 1.0.0, this project
62
62
  will follow [Semantic Versioning](https://semver.org) until then, the patch
63
63
  number (0.0.x) will be updated for any changes that do not affect the public
64
64
  interface. Versions that increment the minor number will have at least one of
@@ -88,21 +88,27 @@ We check for and alias your old method_added. It will be called before
88
88
  anything else. Of course, if you define method_added after including
89
89
  Asynchronize, you have to do the same and be careful to not overwrite ours!
90
90
 
91
- ### Why do I need another framework? My code's bloated enough as it is?
91
+ ### Why do I need another gem? My code's bloated enough as it is?
92
92
  It's super tiny. Just a light wrapper around the existing language features.
93
93
  Seriously, it's just around fifty lines of code. Actually, according to
94
- [cloc](https://www.npmjs.com/package/cloc) there's twice as many lines in the
95
- tests as the source. You should read it, I'd love feedback!
94
+ [cloc](https://www.npmjs.com/package/cloc) there's almost four times as many
95
+ lines in the tests as the source. You should read it, I'd love feedback!
96
96
 
97
97
  ### Do you accept contributions?
98
98
  Absolutely! If your use case isn't compatible with the project, you find a
99
99
  bug, or just want to donate some tests; make an issue or send a PR please.
100
100
  To run the test suite, just run `bundle` then `rake` from the project directory.
101
101
 
102
- ### What's the difference between this and promises?
103
- This attempts to be a very lightweight wrapper around threads. There's no new
104
- interface to use, just define a regular method, and interact with it like a
105
- regular thread.
102
+ ### What's the difference between asynchronize and promises/async..await?
103
+ Those projects and similar ones aim to create an entirely new abstraction to use
104
+ for doing things asynchronously. This project simply aims to make the existing
105
+ language features easier to use with less typing. Just define a regular method,
106
+ then interact with it's result like a regular thread.
107
+
108
+ ### What versions are supported?
109
+ In theory, this should work for all versions of Ruby. So far, Travis only tests
110
+ for MRI 2.2.2 and 2.5.1. I plan on verifying and adding older versions and other
111
+ implementations as I am able.
106
112
 
107
113
  ## License
108
114
  MIT
@@ -1,6 +1,4 @@
1
1
  require 'simplecov'
2
- require 'simplecov-console'
3
- SimpleCov.formatter = SimpleCov::Formatter::Console
4
2
  SimpleCov.start
5
3
 
6
4
  require 'minitest/autorun'
@@ -166,11 +166,4 @@ class BasicSpec < Minitest::Test
166
166
  end
167
167
  end
168
168
  end
169
-
170
- # describe "when being inherited from another class" do
171
- # before do
172
- #
173
- # end
174
- # after do
175
- # end
176
169
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asynchronize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenneth Cochran
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-02 00:00:00.000000000 Z
11
+ date: 2018-06-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Take any synchronous method, and run it asynchronously, without cluttering
14
14
  your code with repetetive boilerplate.
@@ -17,8 +17,7 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - Rakefile
21
- - asynchronize.gemspec
20
+ - LICENSE
22
21
  - lib/asynchronize.rb
23
22
  - readme.md
24
23
  - spec/minitest_helper.rb
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- require 'rake/testtask'
2
-
3
- Rake::TestTask.new do |t|
4
- t.pattern = "spec/*spec.rb"
5
- end
6
-
7
- desc "Run tests"
8
- task :default => :test
@@ -1,26 +0,0 @@
1
- require 'date'
2
-
3
- Gem::Specification.new do |s|
4
- s.name = 'asynchronize'
5
- s.version = '0.2.0'
6
- s.date = Date.today.to_s
7
- s.summary = 'Easily make multiple methods asynchronous with one line of code.'
8
- s.description = 'Take any synchronous method, and run it asynchronously, ' +
9
- 'without cluttering your code with repetetive boilerplate.'
10
- s.author = 'Kenneth Cochran'
11
- s.email = 'kenneth.cochran101@gmail.com'
12
- s.files = [
13
- 'lib/asynchronize.rb',
14
- 'spec/spec.rb',
15
- 'spec/minitest_helper.rb',
16
- 'asynchronize.gemspec',
17
- 'Rakefile',
18
- 'readme.md',
19
- ]
20
- s.test_files = [
21
- 'spec/spec.rb',
22
- 'spec/minitest_helper.rb'
23
- ]
24
- s.homepage = 'https://github.com/kennycoc/asynchronize'
25
- s.license = 'MIT'
26
- end