yerba 0.7.1-x86_64-linux-gnu → 0.7.2-x86_64-linux-gnu
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/exe/x86_64-linux-gnu/yerba +0 -0
- data/ext/yerba/include/yerba.h +5 -0
- data/ext/yerba/yerba.c +16 -0
- data/lib/yerba/3.2/yerba.so +0 -0
- data/lib/yerba/3.3/yerba.so +0 -0
- data/lib/yerba/3.4/yerba.so +0 -0
- data/lib/yerba/4.0/yerba.so +0 -0
- data/lib/yerba/document.rb +21 -1
- data/lib/yerba/map.rb +4 -0
- data/lib/yerba/node.rb +6 -0
- data/lib/yerba/sequence.rb +4 -0
- data/lib/yerba/version.rb +1 -1
- data/lib/yerba.rb +1 -0
- data/rust/Cargo.lock +1 -1
- data/rust/Cargo.toml +1 -1
- data/rust/src/document/mod.rs +5 -0
- data/rust/src/ffi.rs +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3a901689f1ac4a8c221bcdef132cf38e26a923c0dda6098b5f66df72e61e9db6
|
|
4
|
+
data.tar.gz: ce4068b78e473c95f0329c338231beb3da503534a8d6311bc7e9bdc3a22c4265
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f3923446f3aff456976150b2cfae3b75dfb854f2b6e0352647c9afbca77d3bf75e831151f716fbb1461c7334e5069f0c863effe17ba11d56a5789d7797e331f0
|
|
7
|
+
data.tar.gz: 2ceb3df0cd42c4cf4cc0302d928d6895f8ed98fda4cc74fe5cdfe9f4567b617725e9a1d688f0f9aa8eb475cdcced58ff9f1914d774b49769343d422413c534a9
|
data/exe/x86_64-linux-gnu/yerba
CHANGED
|
Binary file
|
data/ext/yerba/include/yerba.h
CHANGED
|
@@ -72,6 +72,11 @@ void yerba_document_free(struct Document *document);
|
|
|
72
72
|
|
|
73
73
|
struct YerbaGetResult yerba_document_get(const struct Document *document, const char *path);
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Caller must free with yerba_string_free.
|
|
77
|
+
*/
|
|
78
|
+
char *yerba_document_source(const struct Document *document, const char *path);
|
|
79
|
+
|
|
75
80
|
/**
|
|
76
81
|
* Caller must free with yerba_string_free.
|
|
77
82
|
*/
|
data/ext/yerba/yerba.c
CHANGED
|
@@ -119,10 +119,12 @@ static VALUE document_initialize(int argc, VALUE *argv, VALUE self) {
|
|
|
119
119
|
if (NIL_P(path)) {
|
|
120
120
|
result = yerba_document_parse("---\n");
|
|
121
121
|
rb_iv_set(self, "@path", Qnil);
|
|
122
|
+
rb_iv_set(self, "@loaded_mtime", Qnil);
|
|
122
123
|
} else {
|
|
123
124
|
const char *file_path = StringValueCStr(path);
|
|
124
125
|
result = yerba_document_parse_file(file_path);
|
|
125
126
|
rb_iv_set(self, "@path", path);
|
|
127
|
+
rb_iv_set(self, "@loaded_mtime", rb_funcall(rb_cFile, rb_intern("mtime"), 1, path));
|
|
126
128
|
}
|
|
127
129
|
|
|
128
130
|
if (!result.document) {
|
|
@@ -297,6 +299,19 @@ static VALUE document_valid_selector_p(VALUE self, VALUE path) {
|
|
|
297
299
|
return yerba_document_valid_selector(document, StringValueCStr(path)) ? Qtrue : Qfalse;
|
|
298
300
|
}
|
|
299
301
|
|
|
302
|
+
/* document.source(path) → raw YAML text of the node at path */
|
|
303
|
+
static VALUE document_source(VALUE self, VALUE path) {
|
|
304
|
+
struct Document *document = get_document(self);
|
|
305
|
+
char *text = yerba_document_source(document, StringValueCStr(path));
|
|
306
|
+
|
|
307
|
+
if (!text) return Qnil;
|
|
308
|
+
|
|
309
|
+
VALUE result = make_utf8_string(text);
|
|
310
|
+
yerba_string_free(text);
|
|
311
|
+
|
|
312
|
+
return result;
|
|
313
|
+
}
|
|
314
|
+
|
|
300
315
|
/* document.get_value(path) → parsed Ruby object (Hash/Array/String/Integer/etc) */
|
|
301
316
|
static VALUE document_get_value(VALUE self, VALUE path) {
|
|
302
317
|
struct Document *document = get_document(self);
|
|
@@ -1091,6 +1106,7 @@ void Init_yerba(void) {
|
|
|
1091
1106
|
rb_define_method(rb_cDocument, "blank_lines", document_blank_lines, 2);
|
|
1092
1107
|
rb_define_method(rb_cDocument, "apply_yerbafile", document_apply_yerbafile, -1);
|
|
1093
1108
|
rb_define_method(rb_cDocument, "validate_schema", document_validate_schema, -1);
|
|
1109
|
+
rb_define_method(rb_cDocument, "source", document_source, 1);
|
|
1094
1110
|
rb_define_method(rb_cDocument, "to_s", document_to_s, 0);
|
|
1095
1111
|
rb_define_method(rb_cDocument, "write!", document_save, 0);
|
|
1096
1112
|
rb_define_method(rb_cDocument, "changed?", document_changed_p, 0);
|
data/lib/yerba/3.2/yerba.so
CHANGED
|
Binary file
|
data/lib/yerba/3.3/yerba.so
CHANGED
|
Binary file
|
data/lib/yerba/3.4/yerba.so
CHANGED
|
Binary file
|
data/lib/yerba/4.0/yerba.so
CHANGED
|
Binary file
|
data/lib/yerba/document.rb
CHANGED
|
@@ -64,9 +64,16 @@ module Yerba
|
|
|
64
64
|
|
|
65
65
|
def save_to!(path)
|
|
66
66
|
@path = path
|
|
67
|
+
@loaded_mtime = nil
|
|
67
68
|
save!
|
|
68
69
|
end
|
|
69
70
|
|
|
71
|
+
def stale?
|
|
72
|
+
return false unless @path && @loaded_mtime
|
|
73
|
+
|
|
74
|
+
File.mtime(@path) != @loaded_mtime
|
|
75
|
+
end
|
|
76
|
+
|
|
70
77
|
def dig(*keys)
|
|
71
78
|
keys.reduce(self) { |node, key| node.nil? ? nil : node[key] }
|
|
72
79
|
end
|
|
@@ -106,15 +113,18 @@ module Yerba
|
|
|
106
113
|
end
|
|
107
114
|
|
|
108
115
|
def save!(apply: false)
|
|
116
|
+
check_stale!
|
|
109
117
|
Yerbafile.apply!(self, apply) if apply
|
|
110
118
|
write!
|
|
111
|
-
|
|
119
|
+
@loaded_mtime = File.mtime(@path) if @path
|
|
112
120
|
self
|
|
113
121
|
end
|
|
114
122
|
|
|
115
123
|
def apply!(yerbafile = nil)
|
|
124
|
+
check_stale!
|
|
116
125
|
apply(yerbafile)
|
|
117
126
|
write! if changed?
|
|
127
|
+
@loaded_mtime = File.mtime(@path) if @path
|
|
118
128
|
|
|
119
129
|
self
|
|
120
130
|
end
|
|
@@ -157,6 +167,16 @@ module Yerba
|
|
|
157
167
|
raise Yerba::SelectorNotFoundError, message
|
|
158
168
|
end
|
|
159
169
|
|
|
170
|
+
private
|
|
171
|
+
|
|
172
|
+
def check_stale!
|
|
173
|
+
return unless stale?
|
|
174
|
+
|
|
175
|
+
raise Yerba::StaleFileError, "#{@path} was modified externally since it was loaded"
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
public
|
|
179
|
+
|
|
160
180
|
def inspect
|
|
161
181
|
if path
|
|
162
182
|
"#<Yerba::Document path=#{path.inspect}>"
|
data/lib/yerba/map.rb
CHANGED
data/lib/yerba/node.rb
CHANGED
|
@@ -20,6 +20,12 @@ module Yerba
|
|
|
20
20
|
!@document.nil? || !@file_path.nil?
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
def source
|
|
24
|
+
return nil unless connected? && @selector
|
|
25
|
+
|
|
26
|
+
document.source(@selector)
|
|
27
|
+
end
|
|
28
|
+
|
|
23
29
|
module ClassMethods
|
|
24
30
|
def from_document(document, selector, location = nil, key = nil, **attributes)
|
|
25
31
|
instance = allocate
|
data/lib/yerba/sequence.rb
CHANGED
data/lib/yerba/version.rb
CHANGED
data/lib/yerba.rb
CHANGED
|
@@ -30,6 +30,7 @@ module Yerba
|
|
|
30
30
|
class ExecutableNotFoundError < StandardError; end
|
|
31
31
|
class CompilationError < StandardError; end
|
|
32
32
|
class SelectorNotFoundError < StandardError; end
|
|
33
|
+
class StaleFileError < StandardError; end
|
|
33
34
|
|
|
34
35
|
GEM_NAME = "yerba"
|
|
35
36
|
EXECUTABLE_NAME = "yerba"
|
data/rust/Cargo.lock
CHANGED
data/rust/Cargo.toml
CHANGED
data/rust/src/document/mod.rs
CHANGED
|
@@ -159,6 +159,11 @@ impl Document {
|
|
|
159
159
|
Ok(())
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
+
pub fn source(&self, dot_path: &str) -> Result<String, YerbaError> {
|
|
163
|
+
let node = self.navigate(dot_path)?;
|
|
164
|
+
Ok(node.text().to_string())
|
|
165
|
+
}
|
|
166
|
+
|
|
162
167
|
pub fn navigate(&self, dot_path: &str) -> Result<SyntaxNode, YerbaError> {
|
|
163
168
|
Self::validate_path(dot_path)?;
|
|
164
169
|
|
data/rust/src/ffi.rs
CHANGED
|
@@ -278,6 +278,18 @@ fn location_to_ffi(location: crate::Location) -> YerbaLocation {
|
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
|
|
281
|
+
/// Caller must free with yerba_string_free.
|
|
282
|
+
#[no_mangle]
|
|
283
|
+
pub unsafe extern "C" fn yerba_document_source(document: *const Document, path: *const c_char) -> *mut c_char {
|
|
284
|
+
let document = &*document;
|
|
285
|
+
let selector_string = CStr::from_ptr(path).to_str().unwrap_or("");
|
|
286
|
+
|
|
287
|
+
match document.source(selector_string) {
|
|
288
|
+
Ok(text) => CString::new(text).unwrap_or_default().into_raw(),
|
|
289
|
+
Err(_) => ptr::null_mut(),
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
281
293
|
/// Caller must free with yerba_string_free.
|
|
282
294
|
#[no_mangle]
|
|
283
295
|
pub unsafe extern "C" fn yerba_document_get_value(document: *const Document, path: *const c_char) -> *mut c_char {
|