Class: GeneratorSpec::Matcher::Directory
- Inherits:
-
Object
- Object
- GeneratorSpec::Matcher::Directory
- Defined in:
- lib/generator_spec/matcher.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Instance Method Summary collapse
- #directory(name, &block) ⇒ Object
- #file(name, &block) ⇒ Object
-
#initialize(root = nil, &block) ⇒ Directory
constructor
A new instance of Directory.
- #location(name) ⇒ Object
- #matches?(root) ⇒ Boolean
- #migration(name, &block) ⇒ Object
- #no_file(name) ⇒ Object
Constructor Details
Instance Attribute Details
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
62 63 64 |
# File 'lib/generator_spec/matcher.rb', line 62 def tree @tree end |
Instance Method Details
#directory(name, &block) ⇒ Object
71 72 73 |
# File 'lib/generator_spec/matcher.rb', line 71 def directory(name, &block) @tree[name] = block_given? && Directory.new(location(name), &block) end |
#file(name, &block) ⇒ Object
75 76 77 |
# File 'lib/generator_spec/matcher.rb', line 75 def file(name, &block) @tree[name] = File.new(location(name), &block) end |
#location(name) ⇒ Object
83 84 85 |
# File 'lib/generator_spec/matcher.rb', line 83 def location(name) [@root, name].compact.join("/") end |
#matches?(root) ⇒ Boolean
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/generator_spec/matcher.rb', line 91 def matches?(root) @tree.each do |file, value| unless value unless root.join(location(file)).exist? throw :failure, "#{root}/#{location(file)}" end else value.matches?(root) end end @negative_tree.each do |file| if root.join(location(file)).exist? throw :failure, [:not, "unexpected #{root}/#{location(file)}"] end end nil end |
#migration(name, &block) ⇒ Object
87 88 89 |
# File 'lib/generator_spec/matcher.rb', line 87 def migration(name, &block) @tree[name] = Migration.new(location(name), &block) end |
#no_file(name) ⇒ Object
79 80 81 |
# File 'lib/generator_spec/matcher.rb', line 79 def no_file(name) @negative_tree << name end |