94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/gtk3/builder.rb', line 94
def add(target_or_options={})
if target_or_options.is_a?(Hash)
options = target_or_options
else
target = target_or_options
options = {}
if target.respond_to?(:to_path)
options[:path] = target.to_path
elsif target.start_with?("<") or target.start_with?(" ")
options[:string] = target
elsif File.exist?(target)
options[:path] = target
else
options[:resource] = target
end
end
string = options[:string]
path = options[:path] || options[:file]
resource = options[:resource]
object_ids = options[:object_ids]
if path
path = path.to_path if path.respond_to?(:to_path)
if object_ids
add_objects_from_file(path, object_ids)
else
add_from_file(path)
end
elsif resource
if object_ids
add_objects_from_resource(resource, object_ids)
else
add_from_resource(resource)
end
elsif string
if object_ids
add_objects_from_string(string, object_ids)
else
add_from_string(string)
end
else
message = ":path (:file), :resource or :string " +
"must be specified: #{options.inspect}"
raise InvalidArgument, message
end
end
|