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:
-
Use
*
or**
pattern in model path inenrty_in
orlist_in
. -
In
virtual
method usein_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
-
#filepath_fields ⇒ Object
Returns the value of attribute filepath_fields.
-
#filepath_regexp ⇒ Object
Returns the value of attribute filepath_regexp.
Instance Attribute Details
#filepath_fields ⇒ Object
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_regexp ⇒ Object
Returns the value of attribute filepath_regexp.
53 54 55 |
# File 'lib/plain_record/filepath.rb', line 53 def filepath_regexp @filepath_regexp end |