Class: GDK::ConfigType::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/gdk/config_type/base.rb

Direct Known Subclasses

Anything, Array, Bool, Hash, Integer, Path, SettingsArray, String

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent:, builder:) ⇒ Base

Returns a new instance of Base.



12
13
14
15
16
17
# File 'lib/gdk/config_type/base.rb', line 12

def initialize(parent:, builder:)
  @parent = parent
  @builder = builder

  self.value = read_value
end

Instance Attribute Details

#builderObject (readonly)

Returns the value of attribute builder.



8
9
10
# File 'lib/gdk/config_type/base.rb', line 8

def builder
  @builder
end

#parentObject (readonly)

Returns the value of attribute parent.



8
9
10
# File 'lib/gdk/config_type/base.rb', line 8

def parent
  @parent
end

#user_valueObject (readonly)

Returns the value of attribute user_value.



8
9
10
# File 'lib/gdk/config_type/base.rb', line 8

def user_value
  @user_value
end

#valueObject

Returns the value of attribute value.



8
9
10
# File 'lib/gdk/config_type/base.rb', line 8

def value
  @value
end

Instance Method Details

#default_valueObject



19
20
21
22
23
24
25
# File 'lib/gdk/config_type/base.rb', line 19

def default_value
  parent.instance_eval(&blk) if blk
rescue ::GDK::ConfigSettings::LooseFile => e
  GDK::Output.warn(e)
  GDK::Output.info("Instead, set '#{slug}' in your gdk.yml.")
  exit(5)
end

#dump!Object



43
44
45
# File 'lib/gdk/config_type/base.rb', line 43

def dump!(*)
  value
end

#rootObject Also known as: config



51
52
53
# File 'lib/gdk/config_type/base.rb', line 51

def root
  parent&.root || self
end

#slugObject



47
48
49
# File 'lib/gdk/config_type/base.rb', line 47

def slug
  [parent.slug, key].compact.join('.')
end

#user_defined?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/gdk/config_type/base.rb', line 35

def user_defined?
  !!defined?(@user_value)
end

#validate!Object



39
40
41
# File 'lib/gdk/config_type/base.rb', line 39

def validate!
  true # Validated in #value=
end