Module: MPS::Element::ClassMethods
- Defined in:
- lib/mps/elements/element.rb
Instance Method Summary collapse
-
#_schema ⇒ Object
Internal mutable schema hash.
-
#attribute(name, type: :string, default: nil, flag: nil, aliases: []) ⇒ Object
Declare a typed attribute for this element class.
-
#parse_args(raw) ⇒ Object
Schema-driven parse_args.
-
#schema ⇒ Object
Frozen public view of the schema.
Instance Method Details
#_schema ⇒ Object
Internal mutable schema hash.
24 25 26 |
# File 'lib/mps/elements/element.rb', line 24 def _schema @_schema ||= {} end |
#attribute(name, type: :string, default: nil, flag: nil, aliases: []) ⇒ Object
Declare a typed attribute for this element class.
19 20 21 |
# File 'lib/mps/elements/element.rb', line 19 def attribute(name, type: :string, default: nil, flag: nil, aliases: []) _schema[name] = { type: type, default: default, flag: flag, aliases: Array(aliases) } end |
#parse_args(raw) ⇒ Object
Schema-driven parse_args. Subclasses do NOT need to override this. Any key: value pair in raw whose key matches a declared attribute name is extracted; remaining bare words become tags.
36 37 38 39 40 41 42 43 |
# File 'lib/mps/elements/element.rb', line 36 def parse_args(raw) split = ::MPS::Element.split_args(raw) result = { tags: split[:tags] } _schema.each do |name, defn| result[name] = split[:attrs].fetch(name, defn[:default]) end result end |
#schema ⇒ Object
Frozen public view of the schema.
29 30 31 |
# File 'lib/mps/elements/element.rb', line 29 def schema _schema.dup.freeze end |