lib/bindata/deprecated.rb in bindata-1.4.5 vs lib/bindata/deprecated.rb in bindata-1.5.0

- old
+ new

@@ -16,73 +16,35 @@ end module BinData class Base - alias_method :initialize_without_deprecation, :initialize - def initialize_with_deprecation(*args) + # Don't override initialize. If you are defining a new kind of datatype + # (list, array, choice etc) then put your initialization code in + # #initialize_instance. This is because BinData objects can be initialized + # as prototypes and your initialization code may not be called. + # + # If you're subclassing BinData::Record, you are definitely doing the wrong + # thing. Read the documentation on how to use BinData. + # http://bindata.rubyforge.org/manual.html#records + alias_method :initialize_without_warning, :initialize + def initialize_with_warning(*args) owner = method(:initialize).owner if owner != BinData::Base - fail "implementing #initialize on #{owner} is not allowed.\nEither downgrade to BinData 1.2.2, or rename #initialize to #initialize_instance." + msg = "Don't override #initialize on #{owner}." + if %w(BinData::Base BinData::BasePrimitive).include? self.class.superclass.name + msg += "\nrename #initialize to #initialize_instance." + end + fail msg end - initialize_without_deprecation(*args) + initialize_without_warning(*args) end - alias_method :initialize, :initialize_with_deprecation + alias_method :initialize, :initialize_with_warning def initialize_instance(*args) unless args.empty? warn "#{caller[0]} remove the call to super in #initialize_instance" end end - class << self - def register_self - warn "#{caller[0]} `register_self' is no longer needed as of BinData 1.3.2. You can delete this line" - end - - def register(name, class_to_register) - warn "#{caller[0]} `register' is no longer needed as of BinData 1.3.2. You can delete this line" - end - end - - def _do_read(io) - warn "#{caller[0]} `_do_read(io)' is deprecated as of BinData 1.3.0. Replace with `do_read(io)'" - do_read(io) - end - - def _do_write(io) - warn "#{caller[0]} `_do_write(io)' is deprecated as of BinData 1.3.0. Replace with `do_write(io)'" - do_write(io) - end - - def _do_num_bytes - warn "#{caller[0]} `_do_num_bytes' is deprecated as of BinData 1.3.0. Replace with `do_num_bytes'" - do_num_bytes - end - - def _assign(val) - warn "#{caller[0]} `_assign(val)' is deprecated as of BinData 1.3.0. Replace with `assign(val)'" - assign(val) - end - - def _snapshot - warn "#{caller[0]} `_snapshot' is deprecated as of BinData 1.3.0. Replace with `snapshot'" - snapshot - end - end - - class SingleValue - class << self - def inherited(subclass) #:nodoc: - fail "BinData::SingleValue is deprecated. Downgrade to BinData 0.11.1.\nYou will need to make changes to your code before you can use BinData >= 1.0.0" - end - end - end - - class MultiValue - class << self - def inherited(subclass) #:nodoc: - fail "BinData::MultiValue is deprecated. Downgrade to BinData 0.11.1.\nYou will need to make changes to your code before you can use BinData >= 1.0.0" - end - end end end