Skip to content

Instantly share code, notes, and snippets.

@flash-gordon
Created February 23, 2013 22:05
Show Gist options
  • Save flash-gordon/5021564 to your computer and use it in GitHub Desktop.
Save flash-gordon/5021564 to your computer and use it in GitHub Desktop.
before_save :check_comment_size, if: :max_comment_size
class << self
def max_comment_size
return @max_comment_size if defined? @max_comment_size
@max_comment_size = comment_field.try(:[], :data_length)
end
def comment_field
put_procedure = procedure_methods[:put][:procedure]
return nil unless put_procedure
put_procedure.arguments[0][:vch_vc_rem]
end
end # class << self
delegate :max_comment_size, to: :'self.class'
private
def check_comment_size
size = vc_rem.try(:bytesize) || 0
if size > max_comment_size
raise ArgumentError, I18n.t(:'api.common.errors.long_comment', :size => size, :max_size => max_comment_size)
end
true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment