qmin 0.0.2 → 0.0.3

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: e969b8719fe5f2db6ad1fef920177bc35d048ace
4
- data.tar.gz: 19f78471b5de8855854afba3d8d49896a6a096d6
3
+ metadata.gz: 8bdf979e1a4ccffc039a44895e321ace747931dc
4
+ data.tar.gz: 7cc149608162bcd7dcdad2b0cf5149372fcfb6c2
5
5
  SHA512:
6
- metadata.gz: f0c2225a4754b8b3d5a6b3c4e6951dd98c4394b227144edeaa77f5335a06b9082794cff6672c045e7aebfc0b3cf52a64371dad59f49364c065cbdb3a87ce24ea
7
- data.tar.gz: b574a6d930f82e523dd3eef0fa081a560e4a6be439649dd1826dad10738bc56ba3d522fbcef595c0b8b8c9f3d2085a0b57d3188d31d8c04884a1e96ac0e6ad31
6
+ metadata.gz: e3b490eb195f7a82b500cca30d12af8f58cbbe71f978638c53102e2de194f2e915a12171a8e74ad5ff2d7c41e2ec65f3fe862418bf2173f670225170f88972c6
7
+ data.tar.gz: 2367ffe1008775f40db4e9973df7edafa231a0eedb3007a7acd769c13081dbc88fc38ae339f28f7b4d19cb8669eeaf3d65648a6662fdc5bd866a0751789e0f9c
@@ -1,24 +1,23 @@
1
- # Extends class with #background_method(method_name)
1
+ # Extends class with #background(method_name)
2
2
  # The annotated method will be handled by Qmin and it's current strategy
3
3
  class Class
4
- # @param method_name
5
- # Decorates a method to be handled by Qmin's #background_call method
6
- # Calls to the method will then be handled by the configured Qmin::Strategy#background_call method
7
- # The original method is still available through "<method_name>_without_qmin"
8
- def background_method(method_name)
9
- return if respond_to?("#{method_name}_without_qmin") || !!method_name.to_s.match(/_without_qmin$/)
4
+ # @param *method_names
5
+ # Define one or many methods that you want to be handled by Qmin's #background_call method.
6
+ # Calls to these methods will be handled by the configured Qmin::Strategy#background_call method
7
+ # The original methods are still available through "<method_name>_without_qmin"
8
+ def background(*method_names)
9
+ method_names.each do |method_name|
10
+ define_qmin_background_method method_name.to_s
11
+ end
12
+ end
13
+
14
+ def define_qmin_background_method(method_name)
15
+ return if respond_to?("#{method_name}_without_qmin") || !!method_name.match(/_without_qmin$/)
10
16
 
11
- alias_method "#{method_name}_without_qmin", method_name
17
+ alias_method "#{method_name}_without_qmin", method_name.to_sym
12
18
 
13
19
  define_method method_name do
14
- ::Qmin::Qmin.background_call(self, method_name)
20
+ ::Qmin::Qmin.background_call(self, method_name.to_sym)
15
21
  end
16
22
  end
17
-
18
- # @param *method_names
19
- # annotates all methods as background_methods
20
- # see #background_method for more information
21
- def background_methods(*method_names)
22
- method_names.map(&:to_s).each{|method_name| background_method method_name }
23
- end
24
23
  end
@@ -1,33 +1,20 @@
1
- unless String.instance_methods.include?(:snake_case)
1
+ unless !!defined?(ActiveSupport::Inflector)
2
2
 
3
3
  class String
4
- def snake_case
4
+ def underscore
5
5
  self.to_s.gsub(/::/, '/').
6
6
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
7
7
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
8
8
  tr('-', '_').
9
9
  downcase
10
10
  end
11
- end
12
-
13
- end
14
-
15
- unless String.instance_methods.include?(:constantize)
16
11
 
17
- class String
18
12
  def constantize
19
13
  Kernel.const_get(self)
20
14
  end
21
- end
22
15
 
23
- end
24
-
25
-
26
- unless String.instance_methods.include?(:to_queue_name)
27
-
28
- class String
29
16
  def to_queue_name
30
- gsub('::','').snake_case
17
+ gsub('::','').underscore
31
18
  end
32
19
  end
33
20
 
@@ -7,8 +7,8 @@ module Qmin
7
7
  end
8
8
 
9
9
  # call method directly
10
- def background_call(instance, method_name)
11
- instance.send(::Qmin.method_name_for_instance(instance, method_name))
10
+ def background_call(instance, method_name, *args)
11
+ instance.send(::Qmin.method_name_for_instance(instance, method_name), *args)
12
12
  end
13
13
  end
14
14
  end
data/lib/qmin/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Qmin
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -2,69 +2,72 @@ require File.expand_path '../../spec_helper', File.dirname(__FILE__)
2
2
 
3
3
  describe Class do
4
4
  it 'responds to background_method' do
5
- Class.new.should respond_to(:background_method)
5
+ Class.new.should respond_to(:background)
6
6
  end
7
7
 
8
- it 'annotates methods' do
9
- klass = Class.new do
10
- def foo; end
11
- background_method :foo
8
+ describe 'instance methods' do
9
+ it 'annotates methods' do
10
+ klass = Class.new do
11
+ def foo; end
12
+ background :foo
13
+ end
14
+ subject = klass.new
12
15
 
13
- def bar; end
14
- background_method :bar
16
+ subject.should respond_to(:foo)
17
+ subject.should respond_to(:foo_without_qmin)
15
18
  end
16
19
 
17
- subject = klass.new
18
-
19
- subject.should.respond_to? :foo
20
- subject.should.respond_to? :foo_without_qmin
21
-
22
- subject.should.respond_to? :bar
23
- subject.should.respond_to? :bar_without_qmin
24
- end
25
-
26
-
27
- it 'annotates many methods' do
28
- klass = Class.new do
29
- def foo; end
30
- def bar; end
31
-
32
- background_methods :foo, :bar
20
+ it 'annotates many methods' do
21
+ klass = Class.new do
22
+ def foo; end
23
+ def bar; end
24
+ background :foo, :bar
25
+ end
26
+ subject = klass.new
27
+
28
+ subject.should respond_to(:foo)
29
+ subject.should respond_to(:foo_without_qmin)
30
+ subject.should respond_to(:bar)
31
+ subject.should respond_to(:bar_without_qmin)
33
32
  end
34
33
 
35
- subject = klass.new
36
-
37
- subject.should.respond_to? :foo
38
- subject.should.respond_to? :foo_without_qmin
39
-
40
- subject.should.respond_to? :bar
41
- subject.should.respond_to? :bar_without_qmin
42
- end
43
-
44
- it 'does not annotate method twice' do
45
- klass = Class.new do
46
- def foo; end
47
- background_method :foo
48
- background_method :foo
34
+ it 'does not annotate original method' do
35
+ klass = Class.new do
36
+ def foo; end
37
+ background :foo
38
+ background :foo_without_qmin
39
+ end
40
+ subject = klass.new
41
+
42
+ subject.should respond_to(:foo)
43
+ subject.should respond_to(:foo_without_qmin)
44
+ subject.should_not respond_to(:foo_without_qmin_without_qmin)
49
45
  end
50
-
51
- subject = klass.new
52
-
53
- subject.should.respond_to? :foo
54
- subject.should.respond_to? :foo_without_qmin
55
46
  end
56
47
 
57
- it 'does not annotate original method' do
58
- klass = Class.new do
59
- def foo; end
60
- background_method :foo
61
- background_method :foo_without_qmin
48
+ describe 'class methods' do
49
+ it 'decorates eigenclass' do
50
+ klass = Class.new do
51
+ class << self
52
+ def foo; end
53
+ background :foo
54
+ end
55
+ end
56
+ klass.should respond_to(:foo)
57
+ klass.should respond_to(:foo_without_qmin)
62
58
  end
63
59
 
64
- subject = klass.new
60
+ it 'decorates class method in eigenclass' do
61
+ klass = Class.new do
62
+ def self.foo; end
65
63
 
66
- subject.should.respond_to? :foo
67
- subject.should.respond_to? :foo_without_qmin
68
- subject.should_not.respond_to? :foo_without_qmin_without_qmin
64
+ class << self
65
+ background :foo
66
+ end
67
+ end
68
+ klass.should respond_to(:foo)
69
+ klass.should respond_to(:foo_without_qmin)
70
+ end
69
71
  end
72
+
70
73
  end
@@ -2,8 +2,8 @@ require File.expand_path '../../spec_helper', File.dirname(__FILE__)
2
2
 
3
3
  describe String do
4
4
  it '.snake_case' do
5
- 'MyClassName'.snake_case.should eql 'my_class_name'
6
- 'Module::MyClassName'.snake_case.should eql 'module/my_class_name'
5
+ 'MyClassName'.underscore.should eql 'my_class_name'
6
+ 'Module::MyClassName'.underscore.should eql 'module/my_class_name'
7
7
  end
8
8
 
9
9
  it '.constantize' do
data/spec/spec_helper.rb CHANGED
@@ -86,7 +86,7 @@ class BackgroundTestClass < TestClass
86
86
  'BackgroundTestClass'
87
87
  end
88
88
 
89
- background_method :action
89
+ background :action
90
90
  end
91
91
 
92
92
  class TestJob < Qmin::Resque::BaseJob
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qmin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - the-architect