dolzenko 0.0.11 → 0.0.12
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.
@@ -0,0 +1,53 @@
|
|
1
|
+
class Class
|
2
|
+
def acts_as(*args)
|
3
|
+
modules_with_options = []
|
4
|
+
for arg in args
|
5
|
+
if arg.is_a?(Module)
|
6
|
+
modules_with_options << [arg]
|
7
|
+
elsif arg.is_a?(Hash)
|
8
|
+
raise ArgumentError, "Options without module" unless modules_with_options[-1][0].is_a?(Module)
|
9
|
+
modules_with_options[-1][1] = arg
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
klass = self
|
14
|
+
for mod, options in modules_with_options
|
15
|
+
klass.send(:instance_exec, options, &mod::ClassContextProc) if defined?(mod::ClassContextProc)
|
16
|
+
klass.send(:include, mod::InstanceMethods) if defined?(mod::InstanceMethods)
|
17
|
+
klass.extend(mod::ClassMethods) if defined?(mod::ClassMethods)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module NeverTooDry
|
23
|
+
ClassContextProc = proc do |options|
|
24
|
+
attr_accessor :some_attr
|
25
|
+
|
26
|
+
class_eval <<-RUBY
|
27
|
+
def #{options[:meta_method_name]}; end
|
28
|
+
RUBY
|
29
|
+
end
|
30
|
+
|
31
|
+
module InstanceMethods
|
32
|
+
def instance_method; end
|
33
|
+
end
|
34
|
+
|
35
|
+
module ClassMethods
|
36
|
+
def class_method; end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module Dummy; end
|
41
|
+
|
42
|
+
class C
|
43
|
+
acts_as NeverTooDry, { :meta_method_name => "meta_method" },
|
44
|
+
Dummy
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
C.class_method
|
49
|
+
|
50
|
+
c = C.new
|
51
|
+
c.some_attr = 123
|
52
|
+
c.meta_method
|
53
|
+
c.instance_method
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# *Correct* `alias_method_chain_once` implementation
|
2
|
+
class Module
|
3
|
+
def alias_method_chain_once(target, feature)
|
4
|
+
aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
|
5
|
+
without_method = "#{aliased_target}_without_#{feature}#{punctuation}"
|
6
|
+
|
7
|
+
# `method_defined?` matches public and protected methods,
|
8
|
+
# also `*_method_defined?` family of methods is the portable
|
9
|
+
# way to check for method existence, while `public_methods.include?`
|
10
|
+
# will work either on 1.8 or 1.9 (depending on where symbol or string
|
11
|
+
# is provided as method name)
|
12
|
+
unless method_defined?(without_method) ||
|
13
|
+
private_method_defined?(without_method)
|
14
|
+
alias_method_chain(target, feature)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
module Dolzenko
|
1
2
|
module RemoteDownload
|
2
3
|
# Returns IO object to be used with attachment_fu models, if retrieval fails - return nil
|
3
4
|
def get_uploaded_data(url, follow_redirect = 2)
|
@@ -87,4 +88,5 @@ module RemoteDownload
|
|
87
88
|
|
88
89
|
attr_accessor :content_type, :filename, :size, :original_filename
|
89
90
|
end
|
91
|
+
end
|
90
92
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 12
|
9
|
+
version: 0.0.12
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Evgeniy Dolzhenko
|
@@ -56,10 +56,13 @@ extensions: []
|
|
56
56
|
extra_rdoc_files: []
|
57
57
|
|
58
58
|
files:
|
59
|
+
- lib/dolzenko/acts_as.rb
|
60
|
+
- lib/dolzenko/alias_method_chain_once.rb
|
59
61
|
- lib/dolzenko/django_f_object.rb
|
60
62
|
- lib/dolzenko/django_q_object.rb
|
61
63
|
- lib/dolzenko/error_print.rb
|
62
64
|
- lib/dolzenko/gist_readme.rb
|
65
|
+
- lib/dolzenko/global_net_http_debug.rb
|
63
66
|
- lib/dolzenko/includable_with_options.rb
|
64
67
|
- lib/dolzenko/io_interceptor.rb
|
65
68
|
- lib/dolzenko/remote_download.rb
|