Moved to extra directory to extend ruby core.

This commit is contained in:
Martin Edenhofer 2013-09-20 08:29:09 +02:00
parent f2401fe793
commit b3bda95b7c
5 changed files with 42 additions and 26 deletions

View file

@ -257,7 +257,7 @@ class ApplicationController < ActionController::Base
begin
# 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
generic_object.save!
@ -266,6 +266,7 @@ class ApplicationController < ActionController::Base
rescue Exception => e
puts e.message.inspect
logger.error e.message
logger.error e.backtrace.inspect
render :json => { :error => e.message }, :status => :unprocessable_entity
end
end
@ -280,10 +281,11 @@ class ApplicationController < ActionController::Base
generic_object = object.find( params[:id] )
# 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)
rescue Exception => e
logger.error e.message
logger.error e.backtrace.inspect
render :json => { :error => e.message }, :status => :unprocessable_entity
end
end
@ -298,6 +300,7 @@ class ApplicationController < ActionController::Base
model_destory_render_item()
rescue Exception => e
logger.error e.message
logger.error e.backtrace.inspect
render :json => { :error => e.message }, :status => :unprocessable_entity
end
end
@ -311,6 +314,7 @@ class ApplicationController < ActionController::Base
model_show_render_item(generic_object)
rescue Exception => e
logger.error e.message
logger.error e.backtrace.inspect
render :json => { :error => e.message }, :status => :unprocessable_entity
end
end
@ -324,6 +328,7 @@ class ApplicationController < ActionController::Base
model_index_render_result( generic_object )
rescue Exception => e
logger.error e.message
logger.error e.backtrace.inspect
render :json => { :error => e.message }, :status => :unprocessable_entity
end
end

View 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
View 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
View 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

View file

@ -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
def self.build(data)
@ -85,4 +62,4 @@ module NotificationFactory
true
)
end
end
end