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
- #description ⇒ Object
- #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.
82 83 84 |
# File 'lib/generator_spec/matcher.rb', line 82 def tree @tree end |
Instance Method Details
#description ⇒ Object
84 85 86 |
# File 'lib/generator_spec/matcher.rb', line 84 def description 'has directory structure' end |
#directory(name, &block) ⇒ Object
95 96 97 |
# File 'lib/generator_spec/matcher.rb', line 95 def directory(name, &block) @tree[name] = block_given? && Directory.new(location(name), &block) end |
#file(name, &block) ⇒ Object
99 100 101 |
# File 'lib/generator_spec/matcher.rb', line 99 def file(name, &block) @tree[name] = File.new(location(name), &block) end |
#location(name) ⇒ Object
107 108 109 |
# File 'lib/generator_spec/matcher.rb', line 107 def location(name) [@root, name].compact.join("/") end |
#matches?(root) ⇒ Boolean
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/generator_spec/matcher.rb', line 115 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
111 112 113 |
# File 'lib/generator_spec/matcher.rb', line 111 def migration(name, &block) @tree[name] = Migration.new(location(name), &block) end |
#no_file(name) ⇒ Object
103 104 105 |
# File 'lib/generator_spec/matcher.rb', line 103 def no_file(name) @negative_tree << name end |