yerba 0.7.1-arm-linux-gnu → 0.7.2-arm-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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 452ab8570a0e894e9c7ca5905411a877feffc9000e858efaac8aba5861571801
4
- data.tar.gz: 7b3ebaa8ffa0795438ba0b78520303416d0a11b2720c4238b901735e92b29204
3
+ metadata.gz: 6b4a184098ccba1de65340ff7812ed2e99dd2c4e040f5091cb17a4a1301e55b3
4
+ data.tar.gz: 923fae627e8e773b8192e82d4860bfa2c2ea28db670c32a67a9125b61485c53f
5
5
  SHA512:
6
- metadata.gz: '08f327c773a0e87d1554cb624b16708f0f448565e5978346fae903cf43a7e5df9178962f8f11bc44d097891d1c861062e7b6e8d4e8f32b5f8b3ad4dd91ceb310'
7
- data.tar.gz: 0e40c44449eddd6f1f0c5cbdd230ff5046f58be2cf5ce4b9b74c9986c7c24d0261f76afc6f3f5411cd86a342c7ac90a141d9151abfd88f22771988261e5d31af
6
+ metadata.gz: 65dcad11c2c0dc109ab61757c64b15724190a9d587e8b1bddc0a5f76d2cae1a7da84a52f2b785bbd2a9cbf22d8e42f07174b4e5383c0e4a54d3e8275aa6efb47
7
+ data.tar.gz: 5aa046c0d8357e3acbc732faacb7950a3db6e233780ed3a653f89405c8eef64998a918b72711a125a485dad5448ad8251f38b9b643250459d428d1b9d6df3428
Binary file
@@ -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);
Binary file
Binary file
Binary file
Binary file
@@ -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
@@ -161,6 +161,10 @@ module Yerba
161
161
  end
162
162
  alias to_hash to_h
163
163
 
164
+ def to_s
165
+ source || to_yaml
166
+ end
167
+
164
168
  def to_yaml
165
169
  to_hash.map do |key, val|
166
170
  formatted = format_value(val)
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
@@ -281,6 +281,10 @@ module Yerba
281
281
  end.join("\n")
282
282
  end
283
283
 
284
+ def to_s
285
+ source || super
286
+ end
287
+
284
288
  def inspect
285
289
  list = items
286
290
  preview = list.first(5).map(&:inspect).join(", ")
data/lib/yerba/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Yerba
4
- VERSION = "0.7.1"
4
+ VERSION = "0.7.2"
5
5
  end
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
@@ -1772,7 +1772,7 @@ dependencies = [
1772
1772
 
1773
1773
  [[package]]
1774
1774
  name = "yerba"
1775
- version = "0.7.1"
1775
+ version = "0.7.2"
1776
1776
  dependencies = [
1777
1777
  "cbindgen",
1778
1778
  "clap",
data/rust/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "yerba"
3
- version = "0.7.1"
3
+ version = "0.7.2"
4
4
  edition = "2021"
5
5
  authors = ["Marco Roth <marco.roth@intergga.ch>"]
6
6
  description = "YAML Editing and Refactoring with Better Accuracy"
@@ -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 {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yerba
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: arm-linux-gnu
6
6
  authors:
7
7
  - Marco Roth