Class: JSI::Schema::Element
- Inherits:
-
Object
- Object
- JSI::Schema::Element
- Defined in:
- lib/jsi/schema/element.rb
Instance Attribute Summary collapse
- #actions ⇒ Hash<Symbol, Array<Proc>> readonly
- #keywords ⇒ Set readonly
Instance Method Summary collapse
- #add_action(name) { ... }
-
#depends_on_elements {|| ... } ⇒ Object
this element will be invoked after elements for which the result of the block is true-ish.
-
#initialize(keyword: nil, keywords: Util::EMPTY_SET) {|Schema::Element| ... } ⇒ Element
constructor
A new instance of Element.
- #invokes?(action_name) ⇒ Boolean
-
#required_before_elements {|| ... } ⇒ Object
this element will be invoked before elements for which the result of the block is true-ish.
-
#select_elements_self_depends_on(elements) ⇒ Object
selects which of
elementsthis element depends on. -
#select_elements_self_is_required_before(elements) ⇒ Object
selects which of
elementsthis element is required before.
Constructor Details
#initialize(keyword: nil, keywords: Util::EMPTY_SET) {|Schema::Element| ... } ⇒ Element
Returns a new instance of Element.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/jsi/schema/element.rb', line 7 def initialize(keyword: nil, keywords: Util::EMPTY_SET) @keywords = keyword ? (keywords.empty? ? Set[keyword].freeze : raise(ArgumentError)) : Set.new(keywords).freeze @actions = Hash.new(Util::EMPTY_ARY) @required_before_element_selector = nil @depends_on_element_selector = nil yield(self) @actions.freeze freeze end |
Instance Attribute Details
#actions ⇒ Hash<Symbol, Array<Proc>> (readonly)
23 24 25 |
# File 'lib/jsi/schema/element.rb', line 23 def actions @actions end |
#keywords ⇒ Set (readonly)
20 21 22 |
# File 'lib/jsi/schema/element.rb', line 20 def keywords @keywords end |
Instance Method Details
#add_action(name) { ... }
This method returns an undefined value.
54 55 56 57 58 59 60 |
# File 'lib/jsi/schema/element.rb', line 54 def add_action(name, &block) raise(TypeError) unless name.is_a?(Symbol) @actions[name] = @actions[name].dup.push(block).freeze nil end |
#depends_on_elements {|| ... } ⇒ Object
this element will be invoked after elements for which the result of the block is true-ish
35 36 37 |
# File 'lib/jsi/schema/element.rb', line 35 def depends_on_elements(&block) @depends_on_element_selector = block end |
#invokes?(action_name) ⇒ Boolean
64 65 66 |
# File 'lib/jsi/schema/element.rb', line 64 def invokes?(action_name) !@actions[action_name].empty? end |
#required_before_elements {|| ... } ⇒ Object
this element will be invoked before elements for which the result of the block is true-ish
28 29 30 |
# File 'lib/jsi/schema/element.rb', line 28 def required_before_elements(&block) @required_before_element_selector = block end |
#select_elements_self_depends_on(elements) ⇒ Object
selects which of elements this element depends on
46 47 48 49 |
# File 'lib/jsi/schema/element.rb', line 46 def select_elements_self_depends_on(elements) return(Util::EMPTY_ARY) unless @depends_on_element_selector elements.select { |e| e != self && @depends_on_element_selector.call(e) }.freeze end |
#select_elements_self_is_required_before(elements) ⇒ Object
selects which of elements this element is required before
40 41 42 43 |
# File 'lib/jsi/schema/element.rb', line 40 def select_elements_self_is_required_before(elements) return(Util::EMPTY_ARY) unless @required_before_element_selector elements.select { |e| e != self && @required_before_element_selector.call(e) }.freeze end |