-
-
Save barhum/cdc1d46111b0b3c14542 to your computer and use it in GitHub Desktop.
php array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Failure/Error: customer.payment_methods << payment_method | |
NoMethodError: | |
undefined method `each_pair' for []:Array | |
# ./app/models/php_array.rb:11:in `new' | |
# ./app/models/php_array.rb:11:in `load' | |
# ./spec/api/order_spec.rb:345:in `block (3 levels) in <top (required)> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ostruct' | |
require 'php_serialize' | |
class PhpArray < OpenStruct | |
class << self | |
def dump(obj) | |
::PHP.serialize(obj.attributes) | |
end | |
def load(s) | |
new(unserialize(s)) | |
end | |
def unserialize arr | |
arr.blank? ? {} : ::PHP.unserialize(arr.encode('ASCII-8BIT',replace:"?")) | |
rescue Exception => e | |
Rails.logger.error e.message | |
Rails.logger.error e.backtrace.join("\n") | |
raise "Failed to unserialize #{arr.inspect}" | |
end | |
end | |
alias :attributes :marshal_dump | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment