Skip to content

Commit

Permalink
Merge pull request #1056 from nanoc/snapshot-eh
Browse files Browse the repository at this point in the history
Add #snapshot?
  • Loading branch information
denisdefreyne committed Jan 22, 2017
2 parents e8a6002 + f7483af commit 747aefd
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/nanoc/base/entities/item_rep.rb
Expand Up @@ -44,6 +44,11 @@ def initialize(item, name)
@compiled = false
end

contract Symbol => C::Bool
def snapshot?(name)
snapshot_defs.any? { |sd| sd.name == name }
end

contract C::KeywordArgs[snapshot: C::Optional[Symbol]] => C::Maybe[String]
# Returns the item rep’s raw path. It includes the path to the output
# directory and the full filename.
Expand Down
5 changes: 5 additions & 0 deletions lib/nanoc/base/views/item_rep_view.rb
Expand Up @@ -46,6 +46,11 @@ def compiled_content(snapshot: nil)
@context.snapshot_repo.compiled_content(rep: unwrap, snapshot: snapshot)
end

def snapshot?(name)
@context.dependency_tracker.bounce(unwrap.item, compiled_content: true)
@item_rep.snapshot?(name)
end

# Returns the item rep’s path, as used when being linked to. It starts
# with a slash and it is relative to the output directory. It does not
# include the path to the output directory. It will not include the
Expand Down
20 changes: 20 additions & 0 deletions spec/nanoc/base/entities/item_rep_spec.rb
@@ -1,4 +1,24 @@
describe Nanoc::Int::ItemRep do
let(:item) { Nanoc::Int::Item.new('asdf', {}, '/foo.md') }
let(:rep) { Nanoc::Int::ItemRep.new(item, :giraffe) }

describe '#snapshot?' do
subject { rep.snapshot?(snapshot_name) }

let(:snapshot_name) { raise 'override me' }

before do
rep.snapshot_defs = [Nanoc::Int::SnapshotDef.new(:donkey)]
end

context 'snapshot does not exist' do
let(:snapshot_name) { :giraffe }
it { is_expected.not_to be }
end

context 'snapshot exists' do
let(:snapshot_name) { :donkey }
it { is_expected.to be }
end
end
end
67 changes: 67 additions & 0 deletions spec/nanoc/base/views/item_rep_view_spec.rb
Expand Up @@ -137,6 +137,73 @@
it { should == described_class.hash ^ Nanoc::Identifier.new('/foo/').hash ^ :jacques.hash }
end

describe '#snapshot?' do
subject { view.snapshot?(snapshot_name) }

let(:view) { described_class.new(rep, view_context) }

let(:rep) do
Nanoc::Int::ItemRep.new(item, :default).tap do |ir|
ir.compiled = true
ir.snapshot_defs = [
Nanoc::Int::SnapshotDef.new(:last),
]
end
end

let(:item) do
Nanoc::Int::Item.new('content', {}, '/asdf.md')
end

let(:snapshot_name) { raise 'override me' }

before do
snapshot_repo.set(rep, :last, Nanoc::Int::TextualContent.new('Hallo'))
end

context 'snapshot exists' do
let(:snapshot_name) { :last }

it 'creates a dependency' do
expect { subject }.to change { dependency_store.objects_causing_outdatedness_of(base_item) }.from([]).to([item])
end

it 'creates a dependency with the right props' do
subject
dep = dependency_store.dependencies_causing_outdatedness_of(base_item)[0]

expect(dep.props.compiled_content?).to eq(true)

expect(dep.props.raw_content?).to eq(false)
expect(dep.props.attributes?).to eq(false)
expect(dep.props.path?).to eq(false)
end

it { is_expected.to be }
end

context 'snapshot does not exist' do
let(:snapshot_name) { :donkey }

it 'creates a dependency' do
expect { subject }.to change { dependency_store.objects_causing_outdatedness_of(base_item) }.from([]).to([item])
end

it 'creates a dependency with the right props' do
subject
dep = dependency_store.dependencies_causing_outdatedness_of(base_item)[0]

expect(dep.props.compiled_content?).to eq(true)

expect(dep.props.raw_content?).to eq(false)
expect(dep.props.attributes?).to eq(false)
expect(dep.props.path?).to eq(false)
end

it { is_expected.not_to be }
end
end

describe '#compiled_content' do
subject { view.compiled_content }

Expand Down

0 comments on commit 747aefd

Please sign in to comment.