mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2026-03-21 19:56:11 +00:00
Refactored Style to remove usage of method_missing
This commit is contained in:
@@ -19,6 +19,30 @@ module CyberarmEngine
|
|||||||
class Style
|
class Style
|
||||||
attr_reader :hash
|
attr_reader :hash
|
||||||
|
|
||||||
|
%i[
|
||||||
|
x y z width height min_width min_height max_width max_height color background
|
||||||
|
background_image background_image_mode background_image_color
|
||||||
|
background_nine_slice background_nine_slice_mode background_nine_slice_color background_nine_slice_from_edge
|
||||||
|
background_nine_slice_left background_nine_slice_top background_nine_slice_right background_nine_slice_bottom
|
||||||
|
border_color border_color_left border_color_right border_color_top border_color_bottom
|
||||||
|
border_thickness border_thickness_left border_thickness_right border_thickness_top border_thickness_bottom
|
||||||
|
padding padding_left padding_right padding_top padding_bottom
|
||||||
|
margin margin_left margin_right margin_top margin_bottom
|
||||||
|
background_canvas background_nine_slice_canvas background_image_canvas border_canvas
|
||||||
|
|
||||||
|
fraction_background scroll fill text_wrap v_align h_align delay tag
|
||||||
|
image_width image_height
|
||||||
|
|
||||||
|
default hover active disabled
|
||||||
|
].each do |item|
|
||||||
|
define_method(item) do
|
||||||
|
@hash[item]
|
||||||
|
end
|
||||||
|
define_method(:"#{item}=") do |value|
|
||||||
|
@hash[item] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(hash = {})
|
def initialize(hash = {})
|
||||||
h = hash
|
h = hash
|
||||||
# h = Marshal.load(Marshal.dump(hash))
|
# h = Marshal.load(Marshal.dump(hash))
|
||||||
@@ -33,18 +57,5 @@ module CyberarmEngine
|
|||||||
|
|
||||||
@hash = h
|
@hash = h
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_missing(method, *args)
|
|
||||||
if method.to_s.end_with?("=")
|
|
||||||
raise "Did not expect more than 1 argument" if args.size > 1
|
|
||||||
|
|
||||||
@hash[method.to_s.sub("=", "").to_sym] = args.first
|
|
||||||
|
|
||||||
elsif args.empty?
|
|
||||||
@hash[method]
|
|
||||||
else
|
|
||||||
raise ArgumentError, "Did not expect arguments"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user