Module: PlainRecord::Filepath

Included in:
Model
Defined in:
lib/plain_record/filepath.rb

Overview

Extention to get fields from enrty file path. For example, your blog post may stored in name/post.md, and post model will have name field. Also if you set name field to Model#first or Model#all method, they will load entry directly only by it file.

To define filepath field:

  1. Use * or ** pattern in model path in enrty_in or list_in.

  2. In virtual method use in_filepath(i) filter after name with * or ** number (start from 1).

Define filepath field only after entry_in or list_in call.

class Post
  include PlainRecord::Resource

  entry_in '*/*/post.md'

  virtual :category, in_filepath(1)
  virtual :name,     in_filepath(1)
  
end

superpost = Post.new
superpost.name = 'superpost'
superpost.category = 'best/'
superpost.save               # Save to best/superpost/post.md

bests = Post.all(category: 'best') # Look up only in best/ dir

Instance Attribute Summary collapse

Instance Attribute Details

#filepath_fieldsObject

Returns the value of attribute filepath_fields.



52
53
54
# File 'lib/plain_record/filepath.rb', line 52

def filepath_fields
  @filepath_fields
end

#filepath_regexpObject

Returns the value of attribute filepath_regexp.



53
54
55
# File 'lib/plain_record/filepath.rb', line 53

def filepath_regexp
  @filepath_regexp
end