Class: Interscript::Node::Document
- Inherits:
-
Object
- Object
- Interscript::Node::Document
- Defined in:
- lib/interscript/node/document.rb,
lib/interscript/utils/helpers.rb
Instance Attribute Summary collapse
-
#aliases ⇒ Object
Returns the value of attribute aliases.
-
#dep_aliases ⇒ Object
Returns the value of attribute dep_aliases.
-
#dependencies ⇒ Object
Returns the value of attribute dependencies.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#name ⇒ Object
Returns the value of attribute name.
-
#reversed_from ⇒ Object
Returns the value of attribute reversed_from.
-
#stages ⇒ Object
Returns the value of attribute stages.
-
#tests ⇒ Object
Returns the value of attribute tests.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #all_dependencies ⇒ Object
- #call(str, stage = :main, compiler = $compiler || Interscript::Interpreter, **kwargs) ⇒ Object
- #imported_aliases ⇒ Object
- #imported_stages ⇒ Object
-
#initialize ⇒ Document
constructor
A new instance of Document.
- #reverse ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ Document
Returns a new instance of Document.
6 7 8 9 10 11 12 13 14 |
# File 'lib/interscript/node/document.rb', line 6 def initialize puts "Interscript::Node::Document.new " if $DEBUG @metadata = nil @tests = nil @dependencies = [] @dep_aliases = {} @aliases = {} @stages = {} end |
Instance Attribute Details
#aliases ⇒ Object
Returns the value of attribute aliases.
3 4 5 |
# File 'lib/interscript/node/document.rb', line 3 def aliases @aliases end |
#dep_aliases ⇒ Object
Returns the value of attribute dep_aliases.
3 4 5 |
# File 'lib/interscript/node/document.rb', line 3 def dep_aliases @dep_aliases end |
#dependencies ⇒ Object
Returns the value of attribute dependencies.
3 4 5 |
# File 'lib/interscript/node/document.rb', line 3 def dependencies @dependencies end |
#metadata ⇒ Object
Returns the value of attribute metadata.
2 3 4 |
# File 'lib/interscript/node/document.rb', line 2 def @metadata end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/interscript/node/document.rb', line 2 def name @name end |
#reversed_from ⇒ Object
Returns the value of attribute reversed_from.
4 5 6 |
# File 'lib/interscript/node/document.rb', line 4 def reversed_from @reversed_from end |
#stages ⇒ Object
Returns the value of attribute stages.
3 4 5 |
# File 'lib/interscript/node/document.rb', line 3 def stages @stages end |
#tests ⇒ Object
Returns the value of attribute tests.
2 3 4 |
# File 'lib/interscript/node/document.rb', line 2 def tests @tests end |
Class Method Details
.reverse_name(name) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/interscript/node/document.rb', line 50 def self.reverse_name(name) newname = (name || "noname").split("-") newname[2], newname[3] = newname[3], newname[2] if newname.length >= 4 newname = newname.join("-") if newname == name newname.gsub!("-reverse", "") end if newname == name newname += "-reverse" end newname end |
Instance Method Details
#==(other) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/interscript/node/document.rb', line 63 def ==(other) self.class == other.class && self. == other. && self.tests == other.tests && self.stages == other.stages && self.aliases == other.aliases end |
#all_dependencies ⇒ Object
32 33 34 35 36 |
# File 'lib/interscript/node/document.rb', line 32 def all_dependencies (dependencies + dependencies.map { |i| i.document.dependencies }).flatten.uniq_by do |i| i.full_name end end |
#call(str, stage = :main, compiler = $compiler || Interscript::Interpreter, **kwargs) ⇒ Object
23 24 25 |
# File 'lib/interscript/utils/helpers.rb', line 23 def call(str, stage=:main, compiler=$compiler || Interscript::Interpreter, **kwargs) compiler.(self).(str, stage, **kwargs) end |
#imported_aliases ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/interscript/node/document.rb', line 16 def imported_aliases aliases = @aliases @dependencies.select(&:import).each do |d| aliases = d.document.aliases.merge(aliases) end aliases end |
#imported_stages ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/interscript/node/document.rb', line 24 def imported_stages stages = @stages @dependencies.select(&:import).each do |d| stages = d.document.stages.merge(stages) end stages end |
#reverse ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/interscript/node/document.rb', line 38 def reverse @reverse ||= self.class.new.tap do |rdoc| rdoc.name = self.class.reverse_name(name) rdoc. = &.reverse rdoc.tests = tests&.reverse rdoc.dependencies = dependencies.map(&:reverse) rdoc.stages = stages.transform_values(&:reverse) rdoc.dep_aliases = dep_aliases.transform_values(&:reverse) rdoc.aliases = aliases end end |
#to_hash ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/interscript/node/document.rb', line 71 def to_hash { :class => self.class.to_s, :metadata => @metadata&.to_hash, :tests => @tests&.to_hash, :dependencies => @dependencies.map{|x| x.to_hash}, :dep_aliases => @dep_aliases.transform_values(&:to_hash), :aliases => @aliases.transform_values(&:to_hash), :stages => @stages.transform_values(&:to_hash) } end |