Class: Leftovers::ConfigLoader::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/leftovers/config_loader/attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, schema, aliases: nil, require_group: nil, suggest: true) ⇒ Attribute

Returns a new instance of Attribute.



13
14
15
16
17
18
19
# File 'lib/leftovers/config_loader/attribute.rb', line 13

def initialize(name, schema, aliases: nil, require_group: nil, suggest: true)
  @name = name
  @schema = schema
  @aliases = Array(aliases)
  @require_group = require_group
  @suggest = suggest
end

Instance Attribute Details

#aliasesObject (readonly)

Returns the value of attribute aliases.



6
7
8
# File 'lib/leftovers/config_loader/attribute.rb', line 6

def aliases
  @aliases
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/leftovers/config_loader/attribute.rb', line 6

def name
  @name
end

#require_groupObject

Returns the value of attribute require_group.



11
12
13
# File 'lib/leftovers/config_loader/attribute.rb', line 11

def require_group
  @require_group
end

#schemaObject (readonly)

Returns the value of attribute schema.



6
7
8
# File 'lib/leftovers/config_loader/attribute.rb', line 6

def schema
  @schema
end

Instance Method Details

#attributesObject



31
32
33
# File 'lib/leftovers/config_loader/attribute.rb', line 31

def attributes
  [self]
end

#name?(name) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
# File 'lib/leftovers/config_loader/attribute.rb', line 35

def name?(name)
  name = name.to_sym

  @name == name || @aliases.include?(name)
end

#suggest?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/leftovers/config_loader/attribute.rb', line 27

def suggest?
  @suggest
end

#to_ruby(value) ⇒ Object



41
42
43
# File 'lib/leftovers/config_loader/attribute.rb', line 41

def to_ruby(value)
  [key_to_ruby, @schema.to_ruby(value)]
end

#validate_value(value) ⇒ Object



45
46
47
# File 'lib/leftovers/config_loader/attribute.rb', line 45

def validate_value(value)
  @schema.validate(value)
end

#without_require_groupObject



21
22
23
24
25
# File 'lib/leftovers/config_loader/attribute.rb', line 21

def without_require_group
  new = dup
  new.require_group = nil
  new
end