Skip to content

Commit a4d2c55

Browse files
Add OpenStruct support to Awesome Print
Check that OpenStruct exists before patching
1 parent 12b35a6 commit a4d2c55

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Enable OpenStruct support in awesome print
2+
# Code from @marshallshen https://github.com/michaeldv/awesome_print/pull/145
3+
#
4+
# Copyright (c) 2010-2013 Michael Dvorkin
5+
#
6+
# Awesome Print is freely distributable under the terms of MIT license.
7+
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
8+
#------------------------------------------------------------------------------
9+
10+
if defined?(OpenStruct)
11+
module AwesomePrint
12+
module OpenStruct
13+
def self.included(base)
14+
base.send :alias_method, :cast_without_ostruct, :cast
15+
base.send :alias_method, :cast, :cast_with_ostruct
16+
end
17+
18+
def cast_with_ostruct(object, type)
19+
cast = cast_without_ostruct(object, type)
20+
if (defined?(::OpenStruct)) && (object.is_a?(::OpenStruct))
21+
cast = :open_struct_instance
22+
end
23+
cast
24+
end
25+
26+
def awesome_open_struct_instance(object)
27+
"#{object.class} #{awesome_hash(object.marshal_dump)}"
28+
end
29+
end
30+
end
31+
32+
AwesomePrint::Formatter.send(:include, AwesomePrint::OpenStruct)
33+
end

lib/appium_lib/driver.rb

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# encoding: utf-8
22
require 'rubygems'
33
require 'ap'
4-
54
require 'selenium-webdriver'
65

6+
# patch ap
7+
require_relative 'awesome_print/ostruct'
8+
79
# common
810
require_relative 'common/helper'
911
require_relative 'common/patch'
@@ -32,18 +34,6 @@
3234
# device methods
3335
require_relative 'device/device'
3436

35-
# Support OpenStruct in Awesome Print
36-
# /awesome_print/lib/awesome_print/formatter.rb
37-
# upstream issue: https://github.com/michaeldv/awesome_print/pull/36
38-
class AwesomePrint::Formatter
39-
remove_const :CORE if defined?(CORE)
40-
CORE = [:array, :hash, :class, :file, :dir, :bigdecimal, :rational, :struct, :openstruct, :method, :unboundmethod]
41-
42-
def awesome_openstruct target
43-
awesome_hash target.marshal_dump
44-
end
45-
end
46-
4737
# Fix uninitialized constant Minitest (NameError)
4838
module Minitest
4939
# Fix superclass mismatch for class Spec

0 commit comments

Comments
 (0)