Skip to content

Commit

Permalink
Use InMemDataSource
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Feb 5, 2017
1 parent b28172a commit 8e6557b
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 30 deletions.
25 changes: 15 additions & 10 deletions lib/nanoc/base/entities/site.rb
Expand Up @@ -3,17 +3,19 @@ module Nanoc::Int
class Site
include Nanoc::Int::ContractsSupport

attr_reader :code_snippets
attr_reader :config
attr_accessor :data_source
attr_accessor :compiler

contract C::KeywordArgs[config: Nanoc::Int::Configuration, code_snippets: C::IterOf[Nanoc::Int::CodeSnippet], items: C::IterOf[Nanoc::Int::Item], layouts: C::IterOf[Nanoc::Int::Layout]] => C::Any
def initialize(config:, code_snippets:, items:, layouts:)
contract C::KeywordArgs[config: Nanoc::Int::Configuration, code_snippets: C::IterOf[Nanoc::Int::CodeSnippet], data_source: C::Maybe[C::Named['Nanoc::DataSource']]] => C::Any
def initialize(config:, code_snippets:, data_source:)
@config = config
@code_snippets = code_snippets
@items = items
@layouts = layouts
@data_source = data_source

ensure_identifier_uniqueness(@items, 'item')
ensure_identifier_uniqueness(@layouts, 'layout')
ensure_identifier_uniqueness(@data_source.items, 'item')
ensure_identifier_uniqueness(@data_source.layouts, 'layout')
end

contract C::None => self
Expand All @@ -27,10 +29,13 @@ def compiler
@compiler ||= Nanoc::Int::CompilerLoader.new.load(self)
end

attr_reader :code_snippets
attr_reader :config
attr_reader :items
attr_reader :layouts
def items
@data_source.items
end

def layouts
@data_source.layouts
end

contract C::None => self
def freeze
Expand Down
1 change: 1 addition & 0 deletions lib/nanoc/base/repos.rb
Expand Up @@ -10,3 +10,4 @@
require_relative 'repos/rule_memory_store'
require_relative 'repos/site_loader'
require_relative 'repos/snapshot_repo'
require_relative 'repos/in_mem_data_source'
13 changes: 13 additions & 0 deletions lib/nanoc/base/repos/in_mem_data_source.rb
@@ -0,0 +1,13 @@
module Nanoc
class InMemDataSource < Nanoc::DataSource
attr_reader :items
attr_reader :layouts

def initialize(items, layouts)
super({}, '/', '/', {})

@items = items
@layouts = layouts
end
end
end
3 changes: 1 addition & 2 deletions lib/nanoc/base/repos/site_loader.rb
Expand Up @@ -39,8 +39,7 @@ def site_from_config(config)
Nanoc::Int::Site.new(
config: config,
code_snippets: code_snippets,
items: items,
layouts: layouts,
data_source: Nanoc::InMemDataSource.new(items, layouts),
)
end

Expand Down
3 changes: 1 addition & 2 deletions lib/nanoc/spec.rb
Expand Up @@ -160,8 +160,7 @@ def site
site = Nanoc::Int::Site.new(
config: @config,
code_snippets: [],
items: @items,
layouts: @layouts,
data_source: Nanoc::InMemDataSource.new(@items, @layouts),
)
site.compiler = new_compiler_for(site)
site
Expand Down
6 changes: 5 additions & 1 deletion spec/nanoc/base/checksummer_spec.rb
Expand Up @@ -310,7 +310,11 @@
let(:item) { Nanoc::Int::Item.new('stuff', {}, '/stuff.md') }

let(:site) do
Nanoc::Int::Site.new(config: config, code_snippets: code_snippets, items: items, layouts: layouts)
Nanoc::Int::Site.new(
config: config,
code_snippets: code_snippets,
data_source: Nanoc::InMemDataSource.new(items, layouts),
)
end

let(:config) { Nanoc::Int::Configuration.new(hash: { 'foo' => 'bar' }) }
Expand Down
3 changes: 1 addition & 2 deletions spec/nanoc/base/compiler_spec.rb
Expand Up @@ -35,8 +35,7 @@
Nanoc::Int::Site.new(
config: config,
code_snippets: code_snippets,
items: items,
layouts: layouts,
data_source: Nanoc::InMemDataSource.new(items, layouts),
)
end

Expand Down
3 changes: 1 addition & 2 deletions spec/nanoc/base/entities/site_spec.rb
Expand Up @@ -4,8 +4,7 @@
described_class.new(
config: config,
code_snippets: code_snippets,
items: items,
layouts: layouts,
data_source: Nanoc::InMemDataSource.new(items, layouts),
)
end

Expand Down
3 changes: 1 addition & 2 deletions spec/nanoc/base/repos/outdatedness_store_spec.rb
Expand Up @@ -11,8 +11,7 @@
Nanoc::Int::Site.new(
config: config,
code_snippets: code_snippets,
items: items,
layouts: layouts,
data_source: Nanoc::InMemDataSource.new(items, layouts),
)
end

Expand Down
6 changes: 5 additions & 1 deletion spec/nanoc/base/repos/store_spec.rb
Expand Up @@ -4,7 +4,11 @@
subject { described_class.tmp_path_for(site: site, store_name: 'giraffes') }

let(:site) do
Nanoc::Int::Site.new(config: config, code_snippets: code_snippets, items: items, layouts: layouts)
Nanoc::Int::Site.new(
config: config,
code_snippets: code_snippets,
data_source: Nanoc::InMemDataSource.new(items, layouts),
)
end

let(:code_snippets) { [] }
Expand Down
Expand Up @@ -37,8 +37,7 @@
Nanoc::Int::Site.new(
config: config,
code_snippets: code_snippets,
items: items,
layouts: layouts,
data_source: Nanoc::InMemDataSource.new(items, layouts),
)
end

Expand Down
3 changes: 1 addition & 2 deletions spec/nanoc/base/services/outdatedness_checker_spec.rb
Expand Up @@ -21,9 +21,8 @@
let(:site) do
Nanoc::Int::Site.new(
config: config,
items: [],
layouts: [],
code_snippets: [],
data_source: Nanoc::InMemDataSource.new([], []),
)
end

Expand Down
3 changes: 1 addition & 2 deletions spec/nanoc/base/services/outdatedness_rules_spec.rb
Expand Up @@ -25,9 +25,8 @@
let(:site) do
Nanoc::Int::Site.new(
config: config,
items: [],
layouts: [],
code_snippets: code_snippets,
data_source: Nanoc::InMemDataSource.new([], []),
)
end

Expand Down
3 changes: 1 addition & 2 deletions test/base/test_compiler.rb
Expand Up @@ -5,8 +5,7 @@ def new_compiler(site = nil)
site ||= Nanoc::Int::Site.new(
config: nil,
code_snippets: [],
items: [],
layouts: [],
data_source: Nanoc::InMemDataSource.new([], []),
)

reps = Nanoc::Int::ItemRepRepo.new
Expand Down

0 comments on commit 8e6557b

Please sign in to comment.