Class: Gloo::Core::Obj
Direct Known Subclasses
GlooSystem, Objs::Alias, Objs::Boolean, Objs::Cipher, Objs::Colorize, Objs::Confirm, Objs::Container, Objs::Date, Objs::Datetime, Objs::Decimal, Objs::Each, Objs::Element, Objs::Erb, Objs::Eval, Objs::FileHandle, Objs::Function, Objs::Git, Objs::HttpGet, Objs::HttpPost, Objs::Integer, Objs::Json, Objs::Markdown, Objs::Menu, Objs::MenuItem, Objs::Mysql, Objs::Page, Objs::Partial, Objs::Password, Objs::Pg, Objs::Prompt, Objs::Query, Objs::Repeat, Objs::Script, Objs::Select, Objs::Slack, Objs::Sqlite, Objs::SshExec, Objs::Stats, Objs::String, Objs::Svr, Objs::System, Objs::Table, Objs::Teams, Objs::Text, Objs::Time, Objs::Untyped, Objs::Uri
Constant Summary
Constants inherited from Baseo
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#value ⇒ Object
Returns the value of attribute value.
Attributes inherited from Baseo
Class Method Summary collapse
-
.can_create? ⇒ Boolean
Can this object be created? This is true by default and only false for some special cases such as the System object.
-
.help ⇒ Object
Get help for this object.
-
.inherited(subclass) ⇒ Object
Register object types when they are loaded.
-
.messages ⇒ Object
Get a list of message names that this object receives.
-
.typename ⇒ Object
The name of the object type.
Instance Method Summary collapse
-
#add_child(obj) ⇒ Object
Add a child object to the container.
-
#add_children_on_create? ⇒ Boolean
Does this object have children to add when an object is created in interactive mode? This does not apply during obj load, etc.
-
#add_default_children ⇒ Object
Add children to this object.
-
#can_receive_message?(msg) ⇒ Boolean
Can this object receive a message?.
-
#child_count ⇒ Object
Get the number of children.
-
#child_index(name) ⇒ Object
Get the index of the child with the given name.
-
#contains_child?(name) ⇒ Boolean
Does this object contain an object with the given name?.
-
#delete_children ⇒ Object
Delete all children from the container.
-
#dispatch(msg) ⇒ Object
Dispatch the message to the object.
-
#display_value ⇒ Object
Generic function to get display value.
-
#find_add_child(name, type) ⇒ Object
Find a child of the given name.
-
#find_child(name) ⇒ Object
Find a child object with the given name.
-
#find_child_resolve_alias(name) ⇒ Object
Find a child, resolve any alias references.
-
#find_child_value(name) ⇒ Object
Find a child, resolve any alias references, and return the object’s value.
-
#initialize(engine) ⇒ Obj
constructor
Set up the object.
-
#is_alias? ⇒ Boolean
Is this an alias to another object?.
-
#is_function? ⇒ Boolean
Is this a function object?.
-
#msg_blank? ⇒ Boolean
Check to see if the value is blank.
-
#msg_contains? ⇒ Boolean
Check to see if there are children.
-
#msg_reload ⇒ Object
Send the object the reload message.
-
#msg_unload ⇒ Object
Send the object the unload message.
-
#multiline_value? ⇒ Boolean
Does this object support multi-line values? Initially only true for scripts.
-
#pn ⇒ Object
Get the path and name to this object.
-
#remove_child(obj) ⇒ Object
Remove the object from the children collection.
-
#render(render_ƒ) ⇒ Object
Render the object.
-
#root? ⇒ Boolean
Is this the root object?.
-
#send_message(msg, params = nil) ⇒ Object
Sent this object the given message.
-
#set_parent(obj) ⇒ Object
Set the parent for the object.
-
#set_value(new_value) ⇒ Object
Set the value with any necessary type conversions.
-
#type_display ⇒ Object
The object type, suitable for display.
-
#value_display ⇒ Object
Get the value for display purposes.
-
#value_is_array? ⇒ Boolean
Is the value an Array?.
-
#value_is_blank? ⇒ Boolean
Is the value a blank string?.
-
#value_string? ⇒ Boolean
Is the value a String?.
Constructor Details
#initialize(engine) ⇒ Obj
Set up the object.
18 19 20 21 22 23 |
# File 'lib/gloo/core/obj.rb', line 18 def initialize( engine ) @engine = engine @value = '' @children = [] @parent = nil end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
13 14 15 |
# File 'lib/gloo/core/obj.rb', line 13 def children @children end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
13 14 15 |
# File 'lib/gloo/core/obj.rb', line 13 def parent @parent end |
#value ⇒ Object
Returns the value of attribute value.
12 13 14 |
# File 'lib/gloo/core/obj.rb', line 12 def value @value end |
Class Method Details
.can_create? ⇒ Boolean
Can this object be created? This is true by default and only false for some special cases such as the System object.
66 67 68 |
# File 'lib/gloo/core/obj.rb', line 66 def self.can_create? true end |
.help ⇒ Object
Get help for this object.
392 393 394 |
# File 'lib/gloo/core/obj.rb', line 392 def self.help return 'No help found.' end |
.inherited(subclass) ⇒ Object
Register object types when they are loaded.
28 29 30 |
# File 'lib/gloo/core/obj.rb', line 28 def self.inherited( subclass ) Dictionary.instance.register_obj( subclass ) end |
.messages ⇒ Object
Get a list of message names that this object receives.
290 291 292 |
# File 'lib/gloo/core/obj.rb', line 290 def self. return %w[reload unload blank? contains?] end |
.typename ⇒ Object
The name of the object type.
35 36 37 |
# File 'lib/gloo/core/obj.rb', line 35 def self.typename raise 'this method should be overriden' end |
Instance Method Details
#add_child(obj) ⇒ Object
Add a child object to the container.
177 178 179 180 |
# File 'lib/gloo/core/obj.rb', line 177 def add_child( obj ) @children << obj obj.set_parent self end |
#add_children_on_create? ⇒ Boolean
Does this object have children to add when an object is created in interactive mode? This does not apply during obj load, etc.
272 273 274 |
# File 'lib/gloo/core/obj.rb', line 272 def add_children_on_create? return false end |
#add_default_children ⇒ Object
Add children to this object. This is used by containers to add children needed for default configurations.
279 280 281 |
# File 'lib/gloo/core/obj.rb', line 279 def add_default_children # Override this. end |
#can_receive_message?(msg) ⇒ Boolean
Can this object receive a message?
297 298 299 300 |
# File 'lib/gloo/core/obj.rb', line 297 def ( msg ) msgs = self.class. return msgs.include?( msg.strip.downcase ) end |
#child_count ⇒ Object
Get the number of children.
185 186 187 |
# File 'lib/gloo/core/obj.rb', line 185 def child_count return @children.count end |
#child_index(name) ⇒ Object
Get the index of the child with the given name.
246 247 248 249 250 251 |
# File 'lib/gloo/core/obj.rb', line 246 def child_index( name ) @children.each_with_index do |o, i| return i if name.downcase == o.name.downcase end return nil end |
#contains_child?(name) ⇒ Boolean
Does this object contain an object with the given name?
192 193 194 195 196 197 |
# File 'lib/gloo/core/obj.rb', line 192 def contains_child?( name ) @children.each do |o| return true if name.downcase == o.name.downcase end return false end |
#delete_children ⇒ Object
Delete all children from the container.
256 257 258 259 260 |
# File 'lib/gloo/core/obj.rb', line 256 def delete_children @children.reverse.each do |o| self.remove_child o end end |
#dispatch(msg) ⇒ Object
Dispatch the message to the object.
316 317 318 319 320 321 322 323 324 325 |
# File 'lib/gloo/core/obj.rb', line 316 def dispatch( msg ) o = "msg_#{msg}" if self.respond_to? o self.public_send( o ) return true else @engine.err "Message #{msg} not implemented" return false end end |
#display_value ⇒ Object
Generic function to get display value. Can be used for debugging, etc.
87 88 89 |
# File 'lib/gloo/core/obj.rb', line 87 def display_value return self.pn end |
#find_add_child(name, type) ⇒ Object
Find a child of the given name. If found, return it. If not found create it.
163 164 165 166 167 168 169 170 171 172 |
# File 'lib/gloo/core/obj.rb', line 163 def find_add_child( name, type ) child = self.find_child( name ) return child if child params = { :name => name, :type => type, :value => nil, :parent => self } return @engine.factory.create params end |
#find_child(name) ⇒ Object
Find a child object with the given name.
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/gloo/core/obj.rb', line 202 def find_child( name ) if name.end_with?( Gloo::Objs::Alias::ALIAS_REFERENCE ) name = name[ 0..-2 ] end @children.each do |o| return o if name.downcase == o.name.downcase end if is_alias? ln = Gloo::Core::Pn.new( @engine, self.value ) redirect = ln.resolve return redirect.find_child( name ) end return nil end |
#find_child_resolve_alias(name) ⇒ Object
Find a child, resolve any alias references. This returns the object, not the value.
223 224 225 226 227 228 229 |
# File 'lib/gloo/core/obj.rb', line 223 def find_child_resolve_alias( name ) o = find_child name return nil unless o o = Gloo::Objs::Alias.resolve_alias( @engine, o ) return o end |
#find_child_value(name) ⇒ Object
Find a child, resolve any alias references, and return the object’s value.
235 236 237 238 239 240 241 |
# File 'lib/gloo/core/obj.rb', line 235 def find_child_value( name ) o = find_child name return nil unless o o = Gloo::Objs::Alias.resolve_alias( @engine, o ) return o&.value end |
#is_alias? ⇒ Boolean
Is this an alias to another object?
143 144 145 |
# File 'lib/gloo/core/obj.rb', line 143 def is_alias? return self.type_display == Gloo::Objs::Alias.typename end |
#is_function? ⇒ Boolean
Is this a function object?
150 151 152 |
# File 'lib/gloo/core/obj.rb', line 150 def is_function? return self.type_display == Gloo::Objs::Function.typename end |
#msg_blank? ⇒ Boolean
Check to see if the value is blank.
355 356 357 358 359 |
# File 'lib/gloo/core/obj.rb', line 355 def msg_blank? val_blank = value.blank? @engine.heap.it.set_to val_blank return val_blank end |
#msg_contains? ⇒ Boolean
Check to see if there are children.
364 365 366 367 368 |
# File 'lib/gloo/core/obj.rb', line 364 def msg_contains? has_children = child_count.positive? @engine.heap.it.set_to has_children return has_children end |
#msg_reload ⇒ Object
Send the object the reload message. Note that this will only work for objects with file assoications.
343 344 345 346 347 348 349 350 |
# File 'lib/gloo/core/obj.rb', line 343 def msg_reload if self.root? @engine.err 'Cannot reload the root object.' return end @engine.persist_man.reload self end |
#msg_unload ⇒ Object
Send the object the unload message.
330 331 332 333 334 335 336 337 |
# File 'lib/gloo/core/obj.rb', line 330 def msg_unload if self.root? @engine.err 'Cannot unload the root object.' return end @engine.persist_man.unload self end |
#multiline_value? ⇒ Boolean
Does this object support multi-line values? Initially only true for scripts.
113 114 115 |
# File 'lib/gloo/core/obj.rb', line 113 def multiline_value? return false end |
#pn ⇒ Object
Get the path and name to this object.
73 74 75 76 77 78 79 80 81 |
# File 'lib/gloo/core/obj.rb', line 73 def pn str = self.name p = self.parent while p && !p.root? str = "#{p.name}.#{str}" p = p.parent end return str end |
#remove_child(obj) ⇒ Object
Remove the object from the children collection.
265 266 267 |
# File 'lib/gloo/core/obj.rb', line 265 def remove_child( obj ) @children.delete obj end |
#render(render_ƒ) ⇒ Object
Render the object. By default this is just the object’s value. The render_ƒ is ‘render_html’, ‘render_text’, ‘render_json’, etc.
380 381 382 |
# File 'lib/gloo/core/obj.rb', line 380 def render render_ƒ return self.value.to_s end |
#root? ⇒ Boolean
Is this the root object?
56 57 58 59 60 61 |
# File 'lib/gloo/core/obj.rb', line 56 def root? return false if @parent return false unless name.downcase == 'root' return true end |
#send_message(msg, params = nil) ⇒ Object
Sent this object the given message.
305 306 307 308 309 310 311 |
# File 'lib/gloo/core/obj.rb', line 305 def ( msg, params = nil ) @params = params return self.dispatch msg if self. msg @engine.err "Object #{self.name} cannot receive message #{msg}" return false end |
#set_parent(obj) ⇒ Object
Set the parent for the object.
49 50 51 |
# File 'lib/gloo/core/obj.rb', line 49 def set_parent( obj ) @parent = obj end |
#set_value(new_value) ⇒ Object
Set the value with any necessary type conversions.
98 99 100 |
# File 'lib/gloo/core/obj.rb', line 98 def set_value( new_value ) self.value = new_value end |
#type_display ⇒ Object
The object type, suitable for display.
42 43 44 |
# File 'lib/gloo/core/obj.rb', line 42 def type_display return self.class.typename end |
#value_display ⇒ Object
Get the value for display purposes.
105 106 107 |
# File 'lib/gloo/core/obj.rb', line 105 def value_display return self.value.to_s end |
#value_is_array? ⇒ Boolean
Is the value an Array?
127 128 129 |
# File 'lib/gloo/core/obj.rb', line 127 def value_is_array? return self.value.is_a? Array end |
#value_is_blank? ⇒ Boolean
Is the value a blank string?
134 135 136 137 138 |
# File 'lib/gloo/core/obj.rb', line 134 def value_is_blank? return true if value.nil? return self.value.to_s.strip.empty? end |
#value_string? ⇒ Boolean
Is the value a String?
120 121 122 |
# File 'lib/gloo/core/obj.rb', line 120 def value_string? return self.value.is_a? String end |