Moved to extra directory to extend ruby core.
This commit is contained in:
parent
f2401fe793
commit
b3bda95b7c
5 changed files with 42 additions and 26 deletions
|
@ -257,7 +257,7 @@ class ApplicationController < ActionController::Base
|
||||||
begin
|
begin
|
||||||
|
|
||||||
# create object
|
# create object
|
||||||
generic_object = object.new( object.param_cleanup( params[object.to_s.downcase] ) )
|
generic_object = object.new( object.param_cleanup( params[object.to_app_model] ) )
|
||||||
|
|
||||||
# save object
|
# save object
|
||||||
generic_object.save!
|
generic_object.save!
|
||||||
|
@ -266,6 +266,7 @@ class ApplicationController < ActionController::Base
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
puts e.message.inspect
|
puts e.message.inspect
|
||||||
logger.error e.message
|
logger.error e.message
|
||||||
|
logger.error e.backtrace.inspect
|
||||||
render :json => { :error => e.message }, :status => :unprocessable_entity
|
render :json => { :error => e.message }, :status => :unprocessable_entity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -280,10 +281,11 @@ class ApplicationController < ActionController::Base
|
||||||
generic_object = object.find( params[:id] )
|
generic_object = object.find( params[:id] )
|
||||||
|
|
||||||
# save object
|
# save object
|
||||||
generic_object.update_attributes!( object.param_cleanup( params[object.to_s.downcase] ) )
|
generic_object.update_attributes!( object.param_cleanup( params[object.to_app_model] ) )
|
||||||
model_update_render_item(generic_object)
|
model_update_render_item(generic_object)
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
logger.error e.message
|
logger.error e.message
|
||||||
|
logger.error e.backtrace.inspect
|
||||||
render :json => { :error => e.message }, :status => :unprocessable_entity
|
render :json => { :error => e.message }, :status => :unprocessable_entity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -298,6 +300,7 @@ class ApplicationController < ActionController::Base
|
||||||
model_destory_render_item()
|
model_destory_render_item()
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
logger.error e.message
|
logger.error e.message
|
||||||
|
logger.error e.backtrace.inspect
|
||||||
render :json => { :error => e.message }, :status => :unprocessable_entity
|
render :json => { :error => e.message }, :status => :unprocessable_entity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -311,6 +314,7 @@ class ApplicationController < ActionController::Base
|
||||||
model_show_render_item(generic_object)
|
model_show_render_item(generic_object)
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
logger.error e.message
|
logger.error e.message
|
||||||
|
logger.error e.backtrace.inspect
|
||||||
render :json => { :error => e.message }, :status => :unprocessable_entity
|
render :json => { :error => e.message }, :status => :unprocessable_entity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -324,6 +328,7 @@ class ApplicationController < ActionController::Base
|
||||||
model_index_render_result( generic_object )
|
model_index_render_result( generic_object )
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
logger.error e.message
|
logger.error e.message
|
||||||
|
logger.error e.backtrace.inspect
|
||||||
render :json => { :error => e.message }, :status => :unprocessable_entity
|
render :json => { :error => e.message }, :status => :unprocessable_entity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
6
config/initializers/core_ext.rb
Normal file
6
config/initializers/core_ext.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
# load all core_ext extentions
|
||||||
|
Dir["#{Rails.root}/lib/core_ext/*"].each {|file|
|
||||||
|
if File.file?(file)
|
||||||
|
require file
|
||||||
|
end
|
||||||
|
}
|
6
lib/core_ext/class.rb
Normal file
6
lib/core_ext/class.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
class Class
|
||||||
|
def to_app_model
|
||||||
|
name = self.to_s.downcase
|
||||||
|
name.gsub( /::/, '_' )
|
||||||
|
end
|
||||||
|
end
|
22
lib/core_ext/string.rb
Normal file
22
lib/core_ext/string.rb
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
class String
|
||||||
|
def message_quote
|
||||||
|
quote = self.split("\n")
|
||||||
|
body_quote = ''
|
||||||
|
quote.each do |line|
|
||||||
|
body_quote = body_quote + '> ' + line + "\n"
|
||||||
|
end
|
||||||
|
body_quote
|
||||||
|
end
|
||||||
|
def word_wrap(*args)
|
||||||
|
options = args.extract_options!
|
||||||
|
unless args.blank?
|
||||||
|
options[:line_width] = args[0] || 82
|
||||||
|
end
|
||||||
|
options.reverse_merge!(:line_width => 82)
|
||||||
|
|
||||||
|
lines = self
|
||||||
|
lines.split("\n").collect do |line|
|
||||||
|
line.length > options[:line_width] ? line.gsub(/(.{1,#{options[:line_width]}})(\s+|$)/, "\\1\n").strip : line
|
||||||
|
end * "\n"
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,26 +1,3 @@
|
||||||
class String
|
|
||||||
def message_quote
|
|
||||||
quote = self.split("\n")
|
|
||||||
body_quote = ''
|
|
||||||
quote.each do |line|
|
|
||||||
body_quote = body_quote + '> ' + line + "\n"
|
|
||||||
end
|
|
||||||
body_quote
|
|
||||||
end
|
|
||||||
def word_wrap(*args)
|
|
||||||
options = args.extract_options!
|
|
||||||
unless args.blank?
|
|
||||||
options[:line_width] = args[0] || 82
|
|
||||||
end
|
|
||||||
options.reverse_merge!(:line_width => 82)
|
|
||||||
|
|
||||||
lines = self
|
|
||||||
lines.split("\n").collect do |line|
|
|
||||||
line.length > options[:line_width] ? line.gsub(/(.{1,#{options[:line_width]}})(\s+|$)/, "\\1\n").strip : line
|
|
||||||
end * "\n"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
module NotificationFactory
|
module NotificationFactory
|
||||||
def self.build(data)
|
def self.build(data)
|
||||||
|
|
||||||
|
@ -85,4 +62,4 @@ module NotificationFactory
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue