Module: Sweet::Component
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
138
139
140
|
# File 'lib/sweet/base.rb', line 138
def method_missing(name, *args, &block)
app.send(name, *args, &block) rescue super
end
|
Instance Attribute Details
#app(&block) ⇒ Object
Returns the value of attribute app.
73
74
75
|
# File 'lib/sweet/base.rb', line 73
def app
@app
end
|
Class Method Details
.included(cls) ⇒ Object
68
69
70
71
|
# File 'lib/sweet/base.rb', line 68
def self.included(cls)
puts "extending #{cls}"
cls.extend(ClassMethods)
end
|
Instance Method Details
#append(&block) ⇒ Object
103
104
105
106
|
# File 'lib/sweet/base.rb', line 103
def append(&block)
raise "Append called without block" unless block
handle_container &block
end
|
108
109
110
111
112
113
|
# File 'lib/sweet/base.rb', line 108
def meta(&block)
@meta ||= class << self
self
end
block ? @meta.class_eval(&block) : @meta
end
|
#options=(opts) ⇒ Object
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/sweet/base.rb', line 115
def options=(opts)
opts.each_pair do |k, v|
case k
when :hidden
setVisible !v
else
name = k.to_s + "="
next unless respond_to? name
if v
classname = respond_to?(:java_class) ? self.java_class.simple_name : self.class.name
Sweet.debug "#{classname}.#{k} = #{v.inspect}"
send name, *v
end
opts.delete(k)
end
end
end
|
134
135
136
|
# File 'lib/sweet/base.rb', line 134
def perform(&block)
app.perform &block
end
|
#sweeten(app, opts, &block) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/sweet/base.rb', line 75
def sweeten(app, opts, &block)
@app = app
self.options = opts
if block
case handler = @block_handler
when nil
handle_container &block
when Symbol
handle_event handler, &block
when Proc
instance_eval do
handler.call self, opts, block
end
else
raise("Invalid :block_handler ",handler) unless sweet_block_handler(handler, &block)
end
end
puts "Unknown properties for class #{self.class}: #{opts.keys.inspect}" unless opts.empty?
end
|