Skip to content

Commit

Permalink
Switch to a Content class (#5)
Browse files Browse the repository at this point in the history
Having a proper Content class makes it easier to talk about and to reference methods even if it's still defined via Decant.define.
  • Loading branch information
benpickles authored Sep 24, 2024
1 parent 305c10a commit 8869165
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
6 changes: 2 additions & 4 deletions lib/decant.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# frozen_string_literal: true
require_relative 'decant/collection'
require_relative 'decant/content_methods'
require_relative 'decant/file'
require_relative 'decant/content'
require_relative 'decant/version'

module Decant
def self.define(dir:, ext: nil, &block)
Class.new(File) do
include ContentMethods
Class.new(Content) do
@collection = Collection.new(dir: dir, ext: ext)
class_eval(&block) if block_given?
end
Expand Down
9 changes: 3 additions & 6 deletions lib/decant/content_methods.rb → lib/decant/content.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# frozen_string_literal: true
require_relative 'errors'
require_relative 'file'

module Decant
module ContentMethods
def self.included(base)
base.extend(ClassMethods)
end

module ClassMethods
class Content < File
class << self
attr_reader :collection

def all
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
RSpec.describe Decant::ContentMethods do
RSpec.describe Decant::Content do
describe '.all' do
let(:klass) { Decant.define(dir: tmpdir, ext: ext) }

Expand Down
2 changes: 1 addition & 1 deletion spec/decant_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe Decant do
describe '.define' do
it 'sets up a new File subclass with an associated Collection and exposes the class body to the block' do
it 'sets up a new Content subclass with an associated Collection and exposes the class body to the block' do
content = <<~CONTENT
---
title: Welcome
Expand Down

0 comments on commit 8869165

Please sign in to comment.