Skip to content

Commit

Permalink
Track dependencies across regexes as well
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Jul 1, 2017
1 parent cdbbf2e commit 781b853
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/nanoc/base/entities/props.rb
Expand Up @@ -9,7 +9,7 @@ class Props
attr_reader :raw_content

# TODO: Split raw_content for documents and collections
C_RAW_CONTENT = C::Or[C::IterOf[String], C::Bool]
C_RAW_CONTENT = C::Or[C::IterOf[C::Or[String, Regexp]], C::Bool]
C_ATTRS = C::Or[C::IterOf[Symbol], C::Bool]
contract C::KeywordArgs[raw_content: C::Optional[C_RAW_CONTENT], attributes: C::Optional[C_ATTRS], compiled_content: C::Optional[C::Bool], path: C::Optional[C::Bool]] => C::Any
def initialize(raw_content: false, attributes: false, compiled_content: false, path: false)
Expand Down
2 changes: 1 addition & 1 deletion lib/nanoc/base/repos/dependency_store.rb
Expand Up @@ -88,7 +88,7 @@ def objects_causing_outdatedness_of(object)
refs2objs(@graph.direct_predecessors_of(obj2ref(object)))
end

C_RAW_CONTENT = C::Or[C::IterOf[String], C::Bool]
C_RAW_CONTENT = C::Or[C::IterOf[C::Or[String, Regexp]], C::Bool]
C_ATTR = C::Or[C::IterOf[Symbol], C::Bool]
C_KEYWORD_PROPS = C::KeywordArgs[raw_content: C::Optional[C_RAW_CONTENT], attributes: C::Optional[C_ATTR], compiled_content: C::Optional[C::Bool], path: C::Optional[C::Bool]]

Expand Down
2 changes: 1 addition & 1 deletion lib/nanoc/base/services/dependency_tracker.rb
Expand Up @@ -6,7 +6,7 @@ class DependencyTracker
include Nanoc::Int::ContractsSupport

C_OBJ = C::Or[Nanoc::Int::Item, Nanoc::Int::Layout, Nanoc::Int::Configuration, Nanoc::Int::IdentifiableCollection]
C_RAW_CONTENT = C::Or[C::IterOf[String], C::Bool]
C_RAW_CONTENT = C::Or[C::IterOf[C::Or[String, Regexp]], C::Bool]
C_ATTR = C::Or[C::IterOf[Symbol], C::Bool]
C_ARGS = C::KeywordArgs[raw_content: C::Optional[C_RAW_CONTENT], attributes: C::Optional[C_ATTR], compiled_content: C::Optional[C::Bool], path: C::Optional[C::Bool]]

Expand Down
14 changes: 6 additions & 8 deletions lib/nanoc/base/views/identifiable_collection_view.rb
Expand Up @@ -47,13 +47,12 @@ def size
#
# @return [Enumerable]
def find_all(arg)
# TODO: support regex
prop_attribute =
case arg
when String
[arg]
when Nanoc::Identifier
when String, Nanoc::Identifier
[arg.to_s]
when Regexp
[arg]
else
true
end
Expand Down Expand Up @@ -85,13 +84,12 @@ def find_all(arg)
#
# @return [#identifier] if an object was found
def [](arg)
# TODO: support regex
prop_attribute =
case arg
when String
[arg]
when Nanoc::Identifier
when String, Nanoc::Identifier
[arg.to_s]
when Regexp
[arg]
else
true
end
Expand Down
44 changes: 43 additions & 1 deletion spec/nanoc/base/services/outdatedness_checker_spec.rb
Expand Up @@ -564,7 +564,7 @@
end
end

context 'dependency on specific new items' do
context 'dependency on specific new items (string)' do
before do
dependency_tracker = Nanoc::Int::DependencyTracker.new(dependency_store)
dependency_tracker.enter(item)
Expand Down Expand Up @@ -605,6 +605,48 @@
it { is_expected.not_to be }
end
end

context 'dependency on specific new items (regex)' do
before do
dependency_tracker = Nanoc::Int::DependencyTracker.new(dependency_store)
dependency_tracker.enter(item)
dependency_tracker.bounce(items, raw_content: [%r{^/new.*}])
dependency_store.store
end

context 'nothing changed' do
it { is_expected.not_to be }
end

context 'matching item added' do
before do
new_item = Nanoc::Int::Item.new('stuff', {}, '/newblahz.md')
dependency_store.items = Nanoc::Int::ItemCollection.new(config, items.to_a + [new_item])
dependency_store.load
end

it { is_expected.to be }
end

context 'non-matching item added' do
before do
new_item = Nanoc::Int::Item.new('stuff', {}, '/nublahz.md')
dependency_store.items = Nanoc::Int::ItemCollection.new(config, items.to_a + [new_item])
dependency_store.load
end

it { is_expected.not_to be }
end

context 'item removed' do
before do
dependency_store.items = Nanoc::Int::ItemCollection.new(config, [])
dependency_store.load
end

it { is_expected.not_to be }
end
end
end

context 'only layout collection dependency' do
Expand Down
4 changes: 2 additions & 2 deletions spec/nanoc/base/views/identifiable_collection_view_spec.rb
Expand Up @@ -215,7 +215,7 @@
let(:arg) { %r{\A/home} }

it 'creates dependency' do
expect(dependency_tracker).to receive(:bounce).with(wrapped, raw_content: true)
expect(dependency_tracker).to receive(:bounce).with(wrapped, raw_content: [%r{\A/home}])
subject
end

Expand Down Expand Up @@ -261,7 +261,7 @@
let(:arg) { %r{\.css\z} }

it 'creates dependency' do
expect(dependency_tracker).to receive(:bounce).with(wrapped, raw_content: true)
expect(dependency_tracker).to receive(:bounce).with(wrapped, raw_content: [%r{\.css\z}])
subject
end

Expand Down

0 comments on commit 781b853

Please sign in to comment.