Class: OroGen::Loaders::Project

Inherits:
BasicObject
Defined in:
lib/orogen/loaders/project.rb

Overview

Class that allows to load an oroGen file to build a Spec::Project

It basically ignores any statements that are not part of the spec, assuming that they are part of the code-generation side of things

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ Project


91
92
93
# File 'lib/orogen/loaders/project.rb', line 91

def initialize(spec)
    @spec = spec
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object


120
121
122
123
124
# File 'lib/orogen/loaders/project.rb', line 120

def method_missing(m, *args, &block)
    if @spec.respond_to?(m)
        @spec.send(m, *args, &block)
    end
end

Class Method Details

.const_missing(m) ⇒ Object


126
127
128
# File 'lib/orogen/loaders/project.rb', line 126

def self.const_missing(m)
    ::Kernel.const_get(m)
end

Instance Method Details

#__eval__(deffile, deftext, verbose = (::OroGen.logger.level == ::Logger::DEBUG)) ⇒ Object


144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/orogen/loaders/project.rb', line 144

def __eval__(deffile, deftext, verbose = (::OroGen.logger.level == ::Logger::DEBUG))
    if !deffile
        @load_doc = false
        instance_eval deftext
    else
        @load_doc = ::File.file?(deffile)
        instance_eval deftext, deffile, 1
    end
    self
rescue ::Exception => e
    if true || verbose then ::Kernel.raise
    else
        this_level = ::Kernel.caller.size
        until_here = e.backtrace[-(this_level-1)..-1] || []
        subcalls = e.backtrace[0, e.backtrace.size - this_level - 1] || []
        subcalls.delete_if { |line| line =~ /eval|method_missing/ && line !~ /\.orogen/ }
        subcalls = subcalls.map { |line| line.gsub(/:in `(?:block in )?__eval__'/, '') }
        ::Kernel.raise e, e.message, (subcalls + until_here)
    end
end

#__load__(file, verbose = (::OroGen.logger.level == ::Logger::DEBUG)) ⇒ Object


139
140
141
142
# File 'lib/orogen/loaders/project.rb', line 139

def __load__(file, verbose = (::OroGen.logger.level == ::Logger::DEBUG))
    deffile = ::File.expand_path(file)
    __eval__(deffile, File.read(deffile), verbose)
end

#find_task_context(name) ⇒ Object


130
131
132
133
# File 'lib/orogen/loaders/project.rb', line 130

def find_task_context(name)
    @spec.loader.task_model_from_name(name)
rescue OroGen::TaskModelNotFound
end

#has_typekit?(name) ⇒ Boolean


135
136
137
# File 'lib/orogen/loaders/project.rb', line 135

def has_typekit?(name)
    @spec.loader.has_typekit?(name)
end

#import_types_from(typekit) ⇒ Object


100
101
102
103
104
105
106
107
# File 'lib/orogen/loaders/project.rb', line 100

def import_types_from(typekit)
    # Filter out the files ... For now, by ignoring stuff that is
    # not a typekit
    if typekit.respond_to?(:to_str) && !@spec.loader.has_typekit?(typekit)
        return
    end
    super
end

#task_context(*args, &block) ⇒ Object


109
110
111
112
113
114
115
116
117
118
# File 'lib/orogen/loaders/project.rb', line 109

def task_context(*args, &block)
    load_doc = @load_doc
    model = super(*args) do
        ::OroGen::Loaders::TaskContext.new(load_doc, self).instance_eval(&block)
    end
    if @load_doc
        Spec.load_documentation(model, /^task_context/)
    end
    model
end

#typekitObject


165
166
167
# File 'lib/orogen/loaders/project.rb', line 165

def typekit
    BlackHole.new
end

#using_typekit(typekit) ⇒ Object

For backward-compatibility reasons


96
97
98
# File 'lib/orogen/loaders/project.rb', line 96

def using_typekit(typekit)
    import_types_from(typekit)
end