class Sirens::ObjectBrowserModel

Attributes

object[R]

Accessors

object_instance_variables[R]

Accessors

text[R]

Accessors

Public Class Methods

new() click to toggle source

Initializing

Calls superclass method
# File lib/sirens/models/object_browser_model.rb, line 6
def initialize()
    super()

    @object = ValueModel.on(nil)

    @object_instance_variables = TreeChoiceModel.new(
            selection: object,
            roots: [InstanceVariable.new(key: nil, value: object)],
            get_children_block: proc { |instance_variable|
                get_child_instance_variables_of(instance_variable.value)
            }
        )

    @text = ValueModel.on('')

    connect_models
end

Public Instance Methods

connect_models() click to toggle source
# File lib/sirens/models/object_browser_model.rb, line 24
def connect_models()
    @object.add_observer(self, :on_object_changed)
    @object_instance_variables.selection.add_observer(self, :on_instance_variable_changed)
end
get_child_instance_variables_of(object) click to toggle source

Get the child instance variables of an object.

# File lib/sirens/models/object_browser_model.rb, line 62
def get_child_instance_variables_of(object)
    if object.kind_of?(Array)
        i = -1
        object.collect{ |value|
            i += 1
            InstanceVariable.new(
                key: i,
                value: value
            )
        }
    elsif object.kind_of?(Hash)
      object.collect{ |key, value|
          InstanceVariable.new(
              key: "[#{key.inspect}]",
              value: value
          )
      }
    else
        object.instance_variables.collect{ |inst_var_name|
            InstanceVariable.new(
                key: inst_var_name,
                value: object.instance_variable_get(inst_var_name)
            )
        }
    end
end
on_instance_variable_changed(announcement) click to toggle source
# File lib/sirens/models/object_browser_model.rb, line 51
def on_instance_variable_changed(announcement)
    instance_variable = announcement.new_value.last

    value = instance_variable.nil? ? '' : instance_variable.value.inspect

    @text.set_value(value)
end
on_object_changed(announcement) click to toggle source

Events

# File lib/sirens/models/object_browser_model.rb, line 43
def on_object_changed(announcement)
    new_object = announcement.new_value

    @object_instance_variables.set_tree_roots(
        [InstanceVariable.new(key: nil, value: new_object)]
    )
end
selected_inst_var_value() click to toggle source
# File lib/sirens/models/object_browser_model.rb, line 35
def selected_inst_var_value()
    tree_selection = object_instance_variables.selection.value.last

    tree_selection.nil? ? nil : tree_selection.value
end