class Wrapture::Scope
Describes a scope of one or more class specifications.
Attributes
A list of classes currently in the scope.
A list of enumerations currently in the scope.
A list of the templates defined in the scope.
Public Class Methods
Creates an empty scope with no classes in it.
# File lib/wrapture/scope.rb, line 34 def initialize(spec = nil) @classes = [] @enums = [] @templates = [] return if spec.nil? @version = Wrapture.spec_version(spec) @templates = spec.fetch('templates', []).collect do |template_hash| TemplateSpec.new(template_hash) end @classes = spec.fetch('classes', []).collect do |class_hash| ClassSpec.new(class_hash, scope: self) end @enums = spec.fetch('enums', []).collect do |enum_hash| EnumSpec.new(enum_hash) end end
Public Instance Methods
Adds a class or template specification to the scope.
This does not set the scope as the owner of the class for a ClassSpec
. This must be done during the construction of the class spec.
# File lib/wrapture/scope.rb, line 60 def <<(spec) @templates << spec if spec.is_a?(TemplateSpec) @classes << spec if spec.is_a?(ClassSpec) @enums << spec if spec.is_a?(EnumSpec) end
Adds a class to the scope created from the given specification hash.
# File lib/wrapture/scope.rb, line 67 def add_class_spec_hash(spec) ClassSpec.new(spec, scope: self) end
Adds an enumeration to the scope created from the given specification hash.
# File lib/wrapture/scope.rb, line 73 def add_enum_spec_hash(spec) @enums << EnumSpec.new(spec) end
Generates the wrapper class files for all classes in the scope.
# File lib/wrapture/scope.rb, line 78 def generate_wrappers files = [] @classes.each do |class_spec| files.concat(class_spec.generate_wrappers) end @enums.each do |enum_spec| files.concat(enum_spec.generate_wrapper) end files end
A list of ClassSpecs in this scope that are overloads of the given class.
# File lib/wrapture/scope.rb, line 93 def overloads(parent) @classes.select { |class_spec| class_spec.overloads?(parent) } end
True if there is an overload of the given class in this scope.
# File lib/wrapture/scope.rb, line 98 def overloads?(parent) @classes.any? { |class_spec| class_spec.overloads?(parent) } end
Returns the ClassSpec
for the given type
in the scope, if one exists.
# File lib/wrapture/scope.rb, line 103 def type(type) @classes.find { |class_spec| class_spec.name == type.base } end
Returns true if there is a class matching the given type
in this scope.
# File lib/wrapture/scope.rb, line 108 def type?(type) @classes.any? { |class_spec| class_spec.name == type.base } end