Module: RestCore::RailsUtilUtil
Defined Under Namespace
Modules: Cache, InstanceMethod
Class Method Summary
collapse
Class Method Details
.extend_rails_util(rails_util, name) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/rest-core/util/rails_util_util.rb', line 61
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::RailsUtilUtil.load_config(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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/rest-core/util/rails_util_util.rb', line 89
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
55
56
57
58
59
|
# File 'lib/rest-core/util/rails_util_util.rb', line 55
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
|
.load_config(klass, namespace = nil, app = Rails) ⇒ Object
4
5
6
7
8
9
10
11
12
13
|
# File 'lib/rest-core/util/rails_util_util.rb', line 4
def self.load_config klass, namespace=nil, app=Rails
RestCore::Config.default_attributes_module(klass)
root = File.expand_path(app.root)
path = ["#{root}/config/rest-core.yaml",
"#{root}/config/rest-core.yml" ].find{|p| File.exist?(p)}
return if path.nil?
RestCore::Config.load(klass, path, app.env, namespace)
end
|
.setup_helper(rails_util, name) ⇒ Object
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/rest-core/util/rails_util_util.rb', line 119
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__)
|