Class: RubyBindgen::Inputter
- Inherits:
-
Object
- Object
- RubyBindgen::Inputter
- Includes:
- Enumerable
- Defined in:
- lib/ruby-bindgen/inputter.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#exclude_glob ⇒ Object
readonly
Returns the value of attribute exclude_glob.
-
#globs ⇒ Object
readonly
Returns the value of attribute globs.
Instance Method Summary collapse
- #each ⇒ Object
- #exclude ⇒ Object
-
#initialize(base_path, globs = nil, exclude_glob = []) ⇒ Inputter
constructor
A new instance of Inputter.
Constructor Details
#initialize(base_path, globs = nil, exclude_glob = []) ⇒ Inputter
Returns a new instance of Inputter.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ruby-bindgen/inputter.rb', line 11 def initialize(base_path, globs=nil, exclude_glob=[]) @base_path = base_path @globs = Array(globs).empty? ? ["**/*.{h,hpp}"] : Array(globs) @exclude_glob = exclude_glob if RUBY_PLATFORM.match?(/mswin/) || RUBY_PLATFORM.match?(/mingw/) @base_path = @base_path.gsub('\\', '/') @globs = @globs.map { |g| g.gsub('\\', '/') } @exclude_glob = @exclude_glob.map { |g| g.gsub('\\', '/') } end end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
9 10 11 |
# File 'lib/ruby-bindgen/inputter.rb', line 9 def base_path @base_path end |
#exclude_glob ⇒ Object (readonly)
Returns the value of attribute exclude_glob.
9 10 11 |
# File 'lib/ruby-bindgen/inputter.rb', line 9 def exclude_glob @exclude_glob end |
#globs ⇒ Object (readonly)
Returns the value of attribute globs.
9 10 11 |
# File 'lib/ruby-bindgen/inputter.rb', line 9 def globs @globs end |
Instance Method Details
#each ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ruby-bindgen/inputter.rb', line 23 def each raise(ArgumentError, "No block given") unless block_given? yielded = 0 seen = Set.new self.globs.each do |glob| search = File.join(self.base_path, glob) Dir.glob(search).each do |path| next if exclude.include?(path) next unless seen.add?(path) yielded += 1 relative_path = Pathname.new(path).relative_path_from(self.base_path) yield path, relative_path.to_path end end # Silent empty output is one of the most common config mistakes. Warn # so a typo'd match: glob doesn't look like a successful run. if yielded.zero? warn "ruby-bindgen: no input files matched #{self.globs.inspect} under #{self.base_path}" end end |
#exclude ⇒ Object
47 48 49 50 51 52 |
# File 'lib/ruby-bindgen/inputter.rb', line 47 def exclude @exclude ||= self.exclude_glob.map do |exclude| search = File.join(self.base_path, exclude) Dir.glob(search) end.flatten.uniq end |