Class: Avm::Instances::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/avm/instances/entry.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.auto_value_method_name(suffix) ⇒ Object



10
11
12
# File 'lib/avm/instances/entry.rb', line 10

def auto_value_method_name(suffix)
  "auto_#{suffix.to_s.gsub('.', '_')}"
end

Instance Method Details

#auto_valueObject



17
18
19
# File 'lib/avm/instances/entry.rb', line 17

def auto_value
  parent.respond_to?(auto_value_method, true) ? parent.send(auto_value_method) : nil
end

#auto_value_methodObject



21
22
23
# File 'lib/avm/instances/entry.rb', line 21

def auto_value_method
  self.class.auto_value_method_name(suffix)
end

#full_pathObject



25
26
27
# File 'lib/avm/instances/entry.rb', line 25

def full_path
  (parent.path_prefix + suffix_as_array).join('.')
end

#optional_valueObject



29
30
31
# File 'lib/avm/instances/entry.rb', line 29

def optional_value
  read(required: false, noinput: true) || auto_value
end

#read(extra_options = {}) ⇒ Object



33
34
35
# File 'lib/avm/instances/entry.rb', line 33

def read(extra_options = {})
  ::Avm::Apps::Config.current.entry(full_path, options.merge(extra_options)).value
end

#suffix_as_arrayObject



37
38
39
40
41
42
43
# File 'lib/avm/instances/entry.rb', line 37

def suffix_as_array
  if suffix.is_a?(::Array)
    suffix.dup
  else
    ::EacConfig::PathsHash.parse_entry_key(suffix.to_s)
  end
end

#valueObject



45
46
47
# File 'lib/avm/instances/entry.rb', line 45

def value
  optional_value || read
end

#write(value) ⇒ Object



49
50
51
# File 'lib/avm/instances/entry.rb', line 49

def write(value)
  ::Avm::Apps::Config.current.entry(full_path).value = value
end