lib/ProMotion/helpers/view_helper.rb in ProMotion-0.6.5 vs lib/ProMotion/helpers/view_helper.rb in ProMotion-0.7.0
- old
+ new
@@ -4,17 +4,19 @@
args.each { |k, v| set_attribute(element, k, v) }
element
end
def set_attribute(element, k, v)
+ return element unless element
+
if v.is_a?(Hash) && element.respond_to?(k)
sub_element = element.send(k)
- set_attributes sub_element, v
- elsif v.is_a?(Array) && element.respond_to?("#{k}")
- element.send("#{k}", *v)
+ set_attributes(sub_element, v) if sub_element
elsif element.respond_to?("#{k}=")
element.send("#{k}=", v)
+ elsif v.is_a?(Array) && element.respond_to?("#{k}") && element.method("#{k}").arity == v.length
+ element.send("#{k}", *v)
else
# Doesn't respond. Check if snake case.
if k.to_s.include?("_")
set_attribute(element, objective_c_method_name(k), v)
end
@@ -46,11 +48,11 @@
set_attributes element, attributes
element
end
def frame_from_array(array)
- PM.logger.deprecated "`frame_from_array` is deprecated and will be removed. Use RubyMotion's built-in [[x, y], [width, height]]."
+ PM.logger.deprecated "`frame_from_array` is deprecated and will be removed. Use RubyMotion's built-in [[x, y], [width, height]] or CGRectMake(x, y, w, h)."
return CGRectMake(array[0], array[1], array[2], array[3]) if array.length == 4
PM.logger.error "frame_from_array expects an array with four elements: [x, y, width, height]"
CGRectZero.dup
end
@@ -66,6 +68,6 @@
end
height
end
end
-end
\ No newline at end of file
+end