Class: Sirens::ObjectBrowser
- Inherits:
-
Component
- Object
- AbstractComponent
- Component
- Sirens::ObjectBrowser
- Defined in:
- lib/sirens/browsers/object_browser.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#browse(object:) ⇒ Object
Actions.
- #browse_class_of(object:) ⇒ Object
- #browse_text_selection(text:) ⇒ Object
-
#default_model ⇒ Object
Model.
-
#render_with(layout) ⇒ Object
Building.
Methods inherited from Component
#build, #create_view, #initialize, #main_child_component, #on_component_added, #open
Methods inherited from AbstractComponent
#add_all_components, #add_component, #child_components, #create_view, #initialize, #model, #on_component_added, #on_model_changed, open, #props, #remove_component_at, #remove_last_component, #set_model, #set_props, #view
Constructor Details
This class inherits a constructor from Sirens::Component
Class Method Details
.open_on(object:) ⇒ Object
5 6 7 8 9 |
# File 'lib/sirens/browsers/object_browser.rb', line 5 def self.open_on(object:) self.open.tap { |browser| browser.model.object.set_value(object) } end |
Instance Method Details
#browse(object:) ⇒ Object
Actions
85 86 87 |
# File 'lib/sirens/browsers/object_browser.rb', line 85 def browse(object:) Sirens.browse(object: object) end |
#browse_class_of(object:) ⇒ Object
89 90 91 |
# File 'lib/sirens/browsers/object_browser.rb', line 89 def browse_class_of(object:) Sirens.browse(klass: object.class) end |
#browse_text_selection(text:) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/sirens/browsers/object_browser.rb', line 93 def browse_text_selection(text:) selected_object = model.selected_inst_var_value evaluation_result = begin selected_object.instance_exec { eval(text) } rescue Exception => e e end browse(object: evaluation_result) end |
#default_model ⇒ Object
Model
13 14 15 |
# File 'lib/sirens/browsers/object_browser.rb', line 13 def default_model() ObjectBrowserModel.new end |
#render_with(layout) ⇒ Object
Building
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/sirens/browsers/object_browser.rb', line 19 def render_with(layout) browser_model = model layout.render do |component| window do styles title: 'Object Browser', width: 400, height: 400 vertical_splitter do choices_tree do model browser_model.object_instance_variables styles splitter_proportion: 2.0/3.0 handlers on_selection_action: proc { |index_path:, item:| component.browse(object: item.value) } column label: '', get_image_block: proc{ |inst_var| inst_var.icon } column label: 'Instance variables', get_text_block: proc { |inst_var| inst_var.display_string } { |menu:, menu_owner:| selected_object = component.model.selected_inst_var_value .item label: 'Browse it', enabled: ! selected_object.nil?, action: proc{ component.browse(object: selected_object) } .separator .item label: 'Browse class', enabled: ! selected_object.nil?, action: proc{ component.browse_class_of(object: selected_object) } } end text do model browser_model.text styles( splitter_proportion: 1.0/3.0, wrap_mode: :char ) { |menu:, menu_owner:| selected_text = .selected_text .separator .item label: 'Browse it', enabled: ! selected_text.nil?, action: proc{ component.browse_text_selection(text: selected_text) } } end end end end end |