Class: ProfileFilter
- Defined in:
- lib/extensions/mspec/mspec/runner/filters/profile.rb
Instance Method Summary collapse
- #===(string) ⇒ Object
- #find(name) ⇒ Object
-
#initialize(what, *files) ⇒ ProfileFilter
constructor
A new instance of ProfileFilter.
- #load(*files) ⇒ Object
- #parse(file) ⇒ Object
- #register ⇒ Object
- #unregister ⇒ Object
Constructor Details
#initialize(what, *files) ⇒ ProfileFilter
Returns a new instance of ProfileFilter.
2 3 4 5 6 |
# File 'lib/extensions/mspec/mspec/runner/filters/profile.rb', line 2 def initialize(what, *files) @what = what @methods = load(*files) @pattern = /([^ .#]+[.#])([^ ]+)/ end |
Instance Method Details
#===(string) ⇒ Object
41 42 43 44 45 |
# File 'lib/extensions/mspec/mspec/runner/filters/profile.rb', line 41 def ===(string) return false unless m = @pattern.match(string) return false unless l = @methods[m[1]] l.include? m[2] end |
#find(name) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/extensions/mspec/mspec/runner/filters/profile.rb', line 8 def find(name) return name if File.exist?(File.(name)) ["spec/profiles", "spec", "profiles", "."].each do |dir| file = File.join dir, name return file if File.exist? file end end |
#load(*files) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/extensions/mspec/mspec/runner/filters/profile.rb', line 31 def load(*files) files.inject({}) do |hash, file| next hash unless name = find(file) File.open name, "r" do |f| hash.merge parse(f) end end end |
#parse(file) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/extensions/mspec/mspec/runner/filters/profile.rb', line 17 def parse(file) pattern = /(\S+):\s*/ key = "" file.inject(Hash.new { |h,k| h[k] = [] }) do |hash, line| line.chomp! if line[0,2] == "- " hash[key] << line[2..-1].gsub(/[ '"]/, "") elsif m = pattern.match(line) key = m[1] end hash end end |
#register ⇒ Object
47 48 49 |
# File 'lib/extensions/mspec/mspec/runner/filters/profile.rb', line 47 def register MSpec.register @what, self end |
#unregister ⇒ Object
51 52 53 |
# File 'lib/extensions/mspec/mspec/runner/filters/profile.rb', line 51 def unregister MSpec.unregister @what, self end |