class Rootage::Model

‘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.

Public Class Methods

new() click to toggle source
# File lib/rootage/core.rb, line 485
def initialize
  @__specified__ = Hash.new
end

Public Instance Methods

[](name) click to toggle source
# File lib/rootage/core.rb, line 489
def [](name)
  instance_variable_get("@%s" % name)
end
[]=(name, val) click to toggle source
# File lib/rootage/core.rb, line 493
def []=(name, val)
  instance_variable_set("@%s" % name, val)
end
specified?(name) click to toggle source

Return true if the option is specified by user.

@param name [Symbol]

option key name

@return [Boolean]

true if the option is specified by user
# File lib/rootage/core.rb, line 515
def specified?(name)
  !!@__specified__[name]
end
specify(name, value) click to toggle source

Specify the option by user.

@param name [Symbol]

option key name

@param value [Object]

option value

@return [void]

# File lib/rootage/core.rb, line 504
def specify(name, value)
  self[name] = value
  @__specified__[name] = true
end
to_hash() click to toggle source

Convert the model into a hash.

@return [Hash]

a hash
# 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