Class: Rootage::Model
- Inherits:
-
Object
- Object
- Rootage::Model
- Defined in:
- lib/rootage/core.rb
Overview
Model is a container for option keys and values. This is a
just hash table, but you can check the value is specified by user or not.
Direct Known Subclasses
Pione::Model::NotificationListenerModel, Pione::Model::TaskWorkerBrokerModel
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, val) ⇒ Object
-
#initialize ⇒ Model
constructor
A new instance of Model.
-
#specified?(name) ⇒ Boolean
Return true if the option is specified by user.
-
#specify(name, value) ⇒ void
Specify the option by user.
-
#to_hash ⇒ Hash
Convert the model into a hash.
Constructor Details
#initialize ⇒ Model
Returns a new instance of Model.
485 486 487 |
# File 'lib/rootage/core.rb', line 485 def initialize @__specified__ = Hash.new end |
Instance Method Details
#[](name) ⇒ Object
489 490 491 |
# File 'lib/rootage/core.rb', line 489 def [](name) instance_variable_get("@%s" % name) end |
#[]=(name, val) ⇒ Object
493 494 495 |
# File 'lib/rootage/core.rb', line 493 def []=(name, val) instance_variable_set("@%s" % name, val) end |
#specified?(name) ⇒ Boolean
Return true if the option is specified by user.
515 516 517 |
# File 'lib/rootage/core.rb', line 515 def specified?(name) !!@__specified__[name] end |
#specify(name, value) ⇒ void
This method returns an undefined value.
Specify the option by user.
504 505 506 507 |
# File 'lib/rootage/core.rb', line 504 def specify(name, value) self[name] = value @__specified__[name] = true end |
#to_hash ⇒ Hash
Convert the model into a hash.
523 524 525 526 527 528 529 530 |
# File 'lib/rootage/core.rb', line 523 def to_hash instance_variables.each_with_object(Hash.new) do |var, h| var = var[1..-1] unless var.to_s.start_with?("__") h[var] = self[var] end end end |