Class: Nugrant::Parameters

Inherits:
Object
  • Object
show all
Defined in:
lib/nugrant/parameters.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil, defaults = nil) ⇒ Parameters

Returns a new instance of Parameters.



8
9
10
11
12
13
14
15
16
17
# File 'lib/nugrant/parameters.rb', line 8

def initialize(config = nil, defaults = nil)
  @__config = config || Config.new()

  @__defaults = defaults || Bag.new()
  @__system = Helper::Bag.read(@__config.system_params_path, @__config.params_filetype)
  @__user = Helper::Bag.read(@__config.user_params_path, @__config.params_filetype)
  @__project = Helper::Bag.read(@__config.project_params_path, @__config.params_filetype)

  __compute_all()
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



23
24
25
# File 'lib/nugrant/parameters.rb', line 23

def method_missing(method, *args, &block)
  return @__all[method]
end

Instance Attribute Details

#__allObject (readonly)

Returns the value of attribute __all.



6
7
8
# File 'lib/nugrant/parameters.rb', line 6

def __all
  @__all
end

#__defaultsObject (readonly)

Returns the value of attribute __defaults.



6
7
8
# File 'lib/nugrant/parameters.rb', line 6

def __defaults
  @__defaults
end

#__projectObject (readonly)

Returns the value of attribute __project.



6
7
8
# File 'lib/nugrant/parameters.rb', line 6

def __project
  @__project
end

#__systemObject (readonly)

Returns the value of attribute __system.



6
7
8
# File 'lib/nugrant/parameters.rb', line 6

def __system
  @__system
end

#__userObject (readonly)

Returns the value of attribute __user.



6
7
8
# File 'lib/nugrant/parameters.rb', line 6

def __user
  @__user
end

Instance Method Details

#[](key) ⇒ Object



19
20
21
# File 'lib/nugrant/parameters.rb', line 19

def [](key)
  return @__all[key]
end

#__compute_allObject



46
47
48
49
50
51
52
# File 'lib/nugrant/parameters.rb', line 46

def __compute_all()
  @__all = Bag.new()
  @__all.__merge!(@__defaults)
  @__all.__merge!(@__system)
  @__all.__merge!(@__user)
  @__all.__merge!(@__project)
end

#defaults=(elements) ⇒ Object



39
40
41
42
43
44
# File 'lib/nugrant/parameters.rb', line 39

def defaults=(elements)
  @__defaults = Bag.new(elements)

  # When defaults change, we need to recompute parameters hierarchy
  __compute_all()
end

#each(&block) ⇒ Object



35
36
37
# File 'lib/nugrant/parameters.rb', line 35

def each(&block)
  @__all.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/nugrant/parameters.rb', line 27

def empty?()
  @__all.empty?()
end

#has?(key) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/nugrant/parameters.rb', line 31

def has?(key)
  return @__all.has?(key)
end