Class: Ast::Merge::Ruleset::Parser
- Inherits:
-
Object
- Object
- Ast::Merge::Ruleset::Parser
- Defined in:
- lib/ast/merge/ruleset/parser.rb
Overview
Parses and validates a compact merge-ruleset document into normalized attributes.
Constant Summary collapse
- REQUIRED_DIRECTIVES =
%i[format owners match read attach].freeze
- OPTIONAL_SINGLE_VALUE_DIRECTIVES =
%i[comment_style render].freeze
- MULTI_VALUE_DIRECTIVES =
%i[capability logical_owner repair surface delegate].freeze
- KNOWN_DIRECTIVES =
(REQUIRED_DIRECTIVES + OPTIONAL_SINGLE_VALUE_DIRECTIVES + MULTI_VALUE_DIRECTIVES).freeze
- READ_STRATEGIES =
%i[ source_augmented_portable_write native_read_portable_write native_mutation ].freeze
- IDENTIFIER_RE =
/\A[A-Za-z][A-Za-z0-9_.-]*\z/- TOKEN_RE =
/\A[!-~]+\z/
Instance Attribute Summary collapse
-
#capabilities ⇒ Object
readonly
Returns the value of attribute capabilities.
-
#delegation_policies ⇒ Object
readonly
Returns the value of attribute delegation_policies.
-
#directives ⇒ Object
readonly
Returns the value of attribute directives.
-
#logical_owners ⇒ Object
readonly
Returns the value of attribute logical_owners.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#repair_policies ⇒ Object
readonly
Returns the value of attribute repair_policies.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#surfaces ⇒ Object
readonly
Returns the value of attribute surfaces.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(source, path: nil) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(source, path: nil) ⇒ Parser
Returns a new instance of Parser.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ast/merge/ruleset/parser.rb', line 31 def initialize(source, path: nil) @source = source.to_s @path = path @directives = [] @capabilities = {} @logical_owners = {} @repair_policies = {} @surfaces = [] @delegation_policies = [] @parsed_values = {} end |
Instance Attribute Details
#capabilities ⇒ Object (readonly)
Returns the value of attribute capabilities.
22 23 24 |
# File 'lib/ast/merge/ruleset/parser.rb', line 22 def capabilities @capabilities end |
#delegation_policies ⇒ Object (readonly)
Returns the value of attribute delegation_policies.
22 23 24 |
# File 'lib/ast/merge/ruleset/parser.rb', line 22 def delegation_policies @delegation_policies end |
#directives ⇒ Object (readonly)
Returns the value of attribute directives.
22 23 24 |
# File 'lib/ast/merge/ruleset/parser.rb', line 22 def directives @directives end |
#logical_owners ⇒ Object (readonly)
Returns the value of attribute logical_owners.
22 23 24 |
# File 'lib/ast/merge/ruleset/parser.rb', line 22 def logical_owners @logical_owners end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
22 23 24 |
# File 'lib/ast/merge/ruleset/parser.rb', line 22 def path @path end |
#repair_policies ⇒ Object (readonly)
Returns the value of attribute repair_policies.
22 23 24 |
# File 'lib/ast/merge/ruleset/parser.rb', line 22 def repair_policies @repair_policies end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
22 23 24 |
# File 'lib/ast/merge/ruleset/parser.rb', line 22 def source @source end |
#surfaces ⇒ Object (readonly)
Returns the value of attribute surfaces.
22 23 24 |
# File 'lib/ast/merge/ruleset/parser.rb', line 22 def surfaces @surfaces end |
Class Method Details
.parse(source, path: nil) ⇒ Object
26 27 28 |
# File 'lib/ast/merge/ruleset/parser.rb', line 26 def parse(source, path: nil) new(source, path: path).parse end |
Instance Method Details
#parse ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ast/merge/ruleset/parser.rb', line 43 def parse parse_source! validate_required_directives! { source: source, path: path, directives: directives.dup, capabilities: capabilities.dup, logical_owners: logical_owners.dup, repair_policies: repair_policies.dup, surfaces: surfaces.map(&:dup), delegation_policies: delegation_policies.map(&:dup) }.merge(@parsed_values) end |