Module: RestCore::RailsUtilUtil
Defined Under Namespace
Modules: Cache, InstanceMethod
Class Method Summary
collapse
Class Method Details
.extend_rails_util(rails_util, name) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/rest-core/util/rails_util_util.rb', line 50
def self.extend_rails_util rails_util, name
meth = name.downcase
mod = if rails_util.const_defined?(:ClassMethod)
rails_util.const_get(:ClassMethod)
else
Module.new
end
mod.module_eval(" def init app=Rails\n RestCore::Config.load_for_rails(RestCore::\#{name}, '\#{meth}', app)\n end\n\n def included controller\n # skip if included already, any better way to detect this?\n return if controller.private_instance_methods.include?(:rc_\#{meth})\n\n controller.send(:include, RestCore::RailsUtilUtil::InstanceMethod)\n\n controller.helper(RestCore::\#{name}::RailsUtil::Helper)\n controller.instance_methods.select{ |method|\n method.to_s =~ /^rc_\#{meth}/\n }.each{ |method| controller.send(:private, method) }\n end\n RUBY\n rails_util.send(:extend, mod)\n rails_util.const_set(:ClassMethod, mod)\nend\n", __FILE__, __LINE__)
|
.include_rails_util(rails_util, name) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/rest-core/util/rails_util_util.rb', line 78
def self.include_rails_util rails_util, name
meth = name.downcase
mod = if rails_util.const_defined?(:InstanceMethod)
rails_util.const_get(:InstanceMethod)
else
Module.new
end
mod.module_eval(" def rc_\#{meth}\n client = RestCore::\#{name}\n @rc_\#{meth} ||= client.new(rc_options_new(client))\n end\n\n def rc_\#{meth}_setup options={}\n client = RestCore::\#{name}\n rc_setup(client, options)\n\n # we'll need to reinitialize rc_\#{meth} with the new options,\n # otherwise if you're calling rc_\#{meth} before rc_\#{meth}_setup,\n # you'll end up with default options without the ones you've passed\n # into rc_\#{meth}_setup.\n rc_\#{meth}.send(:initialize, rc_options_new(client))\n\n true # keep going\n end\n RUBY\n rails_util.send(:include, mod)\n rails_util.const_set(:InstanceMethod, mod)\nend\n", __FILE__, __LINE__)
|
.included(rails_util, name = ) ⇒ Object
44
45
46
47
48
|
# File 'lib/rest-core/util/rails_util_util.rb', line 44
def self.included rails_util, name=rails_util.name[/(\w+)::\w+$/, 1]
extend_rails_util(rails_util, name)
include_rails_util(rails_util, name)
setup_helper(rails_util, name)
end
|
.setup_helper(rails_util, name) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/rest-core/util/rails_util_util.rb', line 108
def self.setup_helper rails_util, name
meth = name.downcase
mod = if rails_util.const_defined?(:Helper)
rails_util.const_get(:Helper)
else
Module.new
end
mod.module_eval(" def rc_\#{meth}\n controller.send(:rc_\#{meth})\n end\n RUBY\n rails_util.const_set(:Helper, mod)\nend\n", __FILE__, __LINE__)
|