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 +4 -4
- data/lib/qmin/core_ext/class.rb +15 -16
- data/lib/qmin/core_ext/string.rb +3 -16
- data/lib/qmin/strategy/inline.rb +2 -2
- data/lib/qmin/version.rb +1 -1
- data/spec/qmin/core_ext/class_spec.rb +54 -51
- data/spec/qmin/core_ext/string_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bdf979e1a4ccffc039a44895e321ace747931dc
|
4
|
+
data.tar.gz: 7cc149608162bcd7dcdad2b0cf5149372fcfb6c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3b490eb195f7a82b500cca30d12af8f58cbbe71f978638c53102e2de194f2e915a12171a8e74ad5ff2d7c41e2ec65f3fe862418bf2173f670225170f88972c6
|
7
|
+
data.tar.gz: 2367ffe1008775f40db4e9973df7edafa231a0eedb3007a7acd769c13081dbc88fc38ae339f28f7b4d19cb8669eeaf3d65648a6662fdc5bd866a0751789e0f9c
|
data/lib/qmin/core_ext/class.rb
CHANGED
@@ -1,24 +1,23 @@
|
|
1
|
-
# Extends class with #
|
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
|
5
|
-
#
|
6
|
-
# Calls to
|
7
|
-
# The original
|
8
|
-
def
|
9
|
-
|
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
|
data/lib/qmin/core_ext/string.rb
CHANGED
@@ -1,33 +1,20 @@
|
|
1
|
-
unless
|
1
|
+
unless !!defined?(ActiveSupport::Inflector)
|
2
2
|
|
3
3
|
class String
|
4
|
-
def
|
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('::','').
|
17
|
+
gsub('::','').underscore
|
31
18
|
end
|
32
19
|
end
|
33
20
|
|
data/lib/qmin/strategy/inline.rb
CHANGED
@@ -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
@@ -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(:
|
5
|
+
Class.new.should respond_to(:background)
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
14
|
-
|
16
|
+
subject.should respond_to(:foo)
|
17
|
+
subject.should respond_to(:foo_without_qmin)
|
15
18
|
end
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
60
|
+
it 'decorates class method in eigenclass' do
|
61
|
+
klass = Class.new do
|
62
|
+
def self.foo; end
|
65
63
|
|
66
|
-
|
67
|
-
|
68
|
-
|
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'.
|
6
|
-
'Module::MyClassName'.
|
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