Module: Vedeu::Repositories::Defaults Private
- Includes:
- Common
- Included in:
- Buffers::Clear, Buffers::Empty, Buffers::View, Cells::Empty, Colours::Colour, Editor::Document, Geometries::Move, Views::DefaultAttributes
- Defined in:
- lib/vedeu/repositories/defaults.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Some classes expect a certain set of attributes when initialized, this module uses the #defaults method of the class to provide missing attribute keys (and values).
Instance Method Summary collapse
-
#defaults ⇒ Hash<Symbol => void>
private
private
The default options/attributes for a new instance of this class.
-
#initialize(attributes = {}) ⇒ void
private
Returns a new instance of the class including this module.
- #validate(attributes) ⇒ Hash private private
Methods included from Common
#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?
Instance Method Details
#defaults ⇒ Hash<Symbol => void> (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The default options/attributes for a new instance of this class.
36 37 38 |
# File 'lib/vedeu/repositories/defaults.rb', line 36 def defaults {} end |
#initialize(attributes = {}) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
If a particular key is missing from the attributes parameter, then it is added with the respective value from #defaults.
Returns a new instance of the class including this module.
27 28 29 30 31 |
# File 'lib/vedeu/repositories/defaults.rb', line 27 def initialize(attributes = {}) defaults.merge!(validate(attributes)).each do |key, value| instance_variable_set("@#{key}", value || defaults.fetch(key)) end end |
#validate(attributes) ⇒ Hash (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
43 44 45 46 47 48 |
# File 'lib/vedeu/repositories/defaults.rb', line 43 def validate(attributes) raise Vedeu::Error::InvalidSyntax, 'Argument :attributes is not a Hash.' unless hash?(attributes) attributes.keep_if { |key, _| defaults.key?(key) } end |