Module: Rubeus::Awt::Attributes::ClassMethods
- Defined in:
- lib/rubeus/awt/attributes.rb
Instance Method Summary collapse
- #default_attributes(attributes = nil) ⇒ Object
- #default_attributes=(attributes) ⇒ Object
- #new_with_attributes(*args, &block) ⇒ Object
Instance Method Details
#default_attributes(attributes = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rubeus/awt/attributes.rb', line 31 def default_attributes(attributes = nil) self.default_attributes = attributes if attributes result = {} @class_to_default_attributes ||= {} classes = self.ancestors.select{|klass| !klass.java_class.interface? and klass.respond_to?(:default_attributes)} classes.reverse.each do |klass| if attrs = @class_to_default_attributes[klass.java_class.name] result.update(attrs) end end result end |
#default_attributes=(attributes) ⇒ Object
45 46 47 48 |
# File 'lib/rubeus/awt/attributes.rb', line 45 def default_attributes=(attributes) @class_to_default_attributes ||= {} @class_to_default_attributes[self.java_class.name] ||= (attributes || {}) end |
#new_with_attributes(*args, &block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rubeus/awt/attributes.rb', line 12 def new_with_attributes(*args, &block) = args.last.is_a?(Hash) ? args.pop : {} result = self.new_without_attributes(*args, &block) attributes = ((@class_to_default_attributes || {})[self.java_class.name] || {}).merge() if respond_to?(:update_attributes) update_attributes(result, attributes) else attributes.each do |attr, value| begin value = (self.const_get(value) rescue value) if value.is_a?(Symbol) result.send("#{attr.to_s}=", value) rescue raise ArgumentError, "Failed setting #{value.inspect} to #{attr.inspect} cause of #{$!.to_s}" end end end result end |