Class: Dommy::Clipboard
Overview
‘navigator.clipboard` — an in-memory clipboard for tests. Real OS clipboard access is intentionally not implemented; reads and writes round-trip through Ruby memory only.
Async APIs (‘readText`/`writeText`/`read`/`write`) return PromiseValue so callers’ ‘.await` chains keep working.
Instance Method Summary
collapse
included
#__internal_deliver_event__, #add_event_listener, capture_flag, #deliver_at, #dispatch_event, js_truthy?, #remove_event_listener
Constructor Details
#initialize(window) ⇒ Clipboard
Returns a new instance of Clipboard.
138
139
140
141
142
|
# File 'lib/dommy/navigator.rb', line 138
def initialize(window)
@window = window
@text = ""
@items = []
end
|
Instance Method Details
#__internal_event_parent__ ⇒ Object
200
201
202
|
# File 'lib/dommy/navigator.rb', line 200
def __internal_event_parent__
nil
end
|
#__js_call__(method, args) ⇒ Object
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/dommy/navigator.rb', line 181
def __js_call__(method, args)
case method
when "readText"
read_text
when "writeText"
write_text(args[0])
when "read"
read
when "write"
write(args[0])
when "addEventListener"
add_event_listener(args[0], args[1], args[2])
when "removeEventListener"
remove_event_listener(args[0], args[1], args[2])
when "dispatchEvent"
dispatch_event(args[0])
end
end
|
#__js_get__(_key) ⇒ Object
171
172
173
|
# File 'lib/dommy/navigator.rb', line 171
def __js_get__(_key)
nil
end
|
#__js_set__(_key, _value) ⇒ Object
175
176
177
|
# File 'lib/dommy/navigator.rb', line 175
def __js_set__(_key, _value)
Bridge::UNHANDLED
end
|
#read ⇒ Object
162
163
164
|
# File 'lib/dommy/navigator.rb', line 162
def read
PromiseValue.resolve(@window, @items.dup)
end
|
#read_text ⇒ Object
153
154
155
|
# File 'lib/dommy/navigator.rb', line 153
def read_text
PromiseValue.resolve(@window, @text)
end
|
#text ⇒ Object
Sync read for tests that don’t want to await.
145
146
147
|
# File 'lib/dommy/navigator.rb', line 145
def text
@text
end
|
#text=(value) ⇒ Object
149
150
151
|
# File 'lib/dommy/navigator.rb', line 149
def text=(value)
@text = value.to_s
end
|
#write(items) ⇒ Object
166
167
168
169
|
# File 'lib/dommy/navigator.rb', line 166
def write(items)
@items = items.is_a?(Array) ? items : [items]
PromiseValue.resolve(@window, nil)
end
|
#write_text(text) ⇒ Object
157
158
159
160
|
# File 'lib/dommy/navigator.rb', line 157
def write_text(text)
@text = text.to_s
PromiseValue.resolve(@window, nil)
end
|