Class: Schemacop::V3::DslScope
- Inherits:
-
Object
- Object
- Schemacop::V3::DslScope
- Defined in:
- lib/schemacop/v3/dsl_scope.rb
Constant Summary collapse
- EXP_NAME =
/^dsl_([a-z_]+)([?!])?$/.freeze
Instance Method Summary collapse
-
#initialize(node) ⇒ DslScope
constructor
A new instance of DslScope.
- #method_missing(name, *args, **options, &block) ⇒ Object
- #respond_to_missing?(name, *args) ⇒ Boolean
Constructor Details
#initialize(node) ⇒ DslScope
Returns a new instance of DslScope.
6 7 8 9 |
# File 'lib/schemacop/v3/dsl_scope.rb', line 6 def initialize(node) @node = node @with_name = @node.class.[:name] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **options, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/schemacop/v3/dsl_scope.rb', line 11 def method_missing(name, *args, **, &block) match = EXP_NAME.match(name) return super unless match base_name, req_optional = match.captures if req_optional == '!' [:required] = true elsif req_optional == '?' [:required] = false end [:parent] = @node if (klass = NodeRegistry.by_short_name(base_name)) if @with_name [:name] = args.shift end node = klass.create(*args, **, &block) @node.add_child node return node else return super end end |
Instance Method Details
#respond_to_missing?(name, *args) ⇒ Boolean
37 38 39 40 41 42 43 |
# File 'lib/schemacop/v3/dsl_scope.rb', line 37 def respond_to_missing?(name, *args) match = EXP_NAME.match(name) return super unless match base_name, _req_optional = match.captures return NodeRegistry.by_short_name(base_name).present? || super end |