Class: Leftovers::ConfigLoader::Attribute
- Inherits:
-
Object
- Object
- Leftovers::ConfigLoader::Attribute
- Defined in:
- lib/leftovers/config_loader/attribute.rb
Instance Attribute Summary collapse
-
#aliases ⇒ Object
readonly
Returns the value of attribute aliases.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#require_group ⇒ Object
Returns the value of attribute require_group.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(name, schema, aliases: nil, require_group: nil, suggest: true) ⇒ Attribute
constructor
A new instance of Attribute.
- #name?(name) ⇒ Boolean
- #suggest? ⇒ Boolean
- #to_ruby(value) ⇒ Object
- #validate_value(value) ⇒ Object
- #without_require_group ⇒ Object
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
#aliases ⇒ Object (readonly)
Returns the value of attribute aliases.
6 7 8 |
# File 'lib/leftovers/config_loader/attribute.rb', line 6 def aliases @aliases end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/leftovers/config_loader/attribute.rb', line 6 def name @name end |
#require_group ⇒ Object
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 |
#schema ⇒ Object (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
#attributes ⇒ Object
31 32 33 |
# File 'lib/leftovers/config_loader/attribute.rb', line 31 def attributes [self] end |
#name?(name) ⇒ 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
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_group ⇒ Object
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 |