soup 1.0.12 → 1.0.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e3d6c5cdcae259cead6e16b21a1aacecdd44ab83
4
- data.tar.gz: 6495467cbdc7268ef2389ab7f7b52acf84c119ec
2
+ SHA256:
3
+ metadata.gz: 5ea571cb9ae5b07d025e31c315c06a92b71e2936658b2dbe042265c059f65842
4
+ data.tar.gz: ad9a2668b3cf7d38441fcc58086cd8c66a2e6147b39e9ea8d2d0893fe82cbc24
5
5
  SHA512:
6
- metadata.gz: 47a65a9ff370847a33ea9d845825b99f4fc6531eba46e3ed462b3783b9109a355caf6039cfc51f160a886cc987a532c1e1d855869281dce5fcde561f8a903a43
7
- data.tar.gz: 98b441fb09269f4c9b03d3b7fd8423a98f28d45f20afc7871b817510fa849cbd5a312eba38c36e263c71fb72bf97108a1da5d6a1ffe10deae27707ad0cb39c19
6
+ metadata.gz: 4a0e04f599cbe280fbfaae811be3f58ba306208f449c0bd5ab489292f36c18fb22a84de7dc05022f2ace1d9f09170520944a87cc21d4cb2582a6be62f8ff47a6
7
+ data.tar.gz: 253e19590bf532d22bb7bb4a001cb607192254259f41937dcf7386c100d452c34755c240187e521d556bd9990dab5696fff93cef7534b95251c3dc75fef1963b
data/Rakefile CHANGED
@@ -7,7 +7,6 @@ task :default => :test
7
7
  require "rake/testtask"
8
8
  Rake::TestTask.new do |t|
9
9
  t.libs << "test"
10
- t.ruby_opts << "-rubygems"
11
10
  t.test_files = FileList["test/**/*_test.rb"]
12
11
  t.verbose = true
13
12
  end
@@ -21,7 +20,7 @@ spec = Gem::Specification.new do |s|
21
20
 
22
21
  # Change these as appropriate
23
22
  s.name = "soup"
24
- s.version = "1.0.12"
23
+ s.version = "1.0.15"
25
24
  s.summary = "A super-simple data store"
26
25
  s.author = "James Adam"
27
26
  s.email = "james@lazyatom.com"
@@ -54,20 +54,23 @@ class Soup
54
54
  end
55
55
 
56
56
  def load_snip_from_path(path, name)
57
- file = File.new(path)
58
- data = file.read
59
- default_attributes = {:name => name, :updated_at => file.mtime, :created_at => file.mtime}
60
- if attribute_start = data.index("\n:")
61
- content = data[0, attribute_start].strip
62
- attributes = default_attributes.merge(YAML.load(data[attribute_start, data.length]))
63
- else
64
- content = data
65
- attributes = default_attributes
57
+ snip = nil
58
+ File.open(path) do |file|
59
+ data = file.read
60
+ default_attributes = {:name => name, :updated_at => file.mtime, :created_at => file.mtime}
61
+ if attribute_start = data.index("\n:")
62
+ content = data[0, attribute_start].strip
63
+ attributes = default_attributes.merge(load_from_yaml(data[attribute_start, data.length]))
64
+ else
65
+ content = data
66
+ attributes = default_attributes
67
+ end
68
+ attributes.update(:content => content) if content && content.length > 0
69
+ extension = File.extname(path).gsub(/^\./, '')
70
+ attributes.update(:extension => extension) if extension != "snip"
71
+ snip = Snip.new(attributes, self)
66
72
  end
67
- attributes.update(:content => content) if content && content.length > 0
68
- extension = File.extname(path).gsub(/^\./, '')
69
- attributes.update(:extension => extension) if extension != "snip"
70
- Snip.new(attributes, self)
73
+ snip
71
74
  end
72
75
 
73
76
  def path_for(name, extension=nil)
@@ -79,6 +82,14 @@ class Soup
79
82
  def snip_paths
80
83
  Dir[File.join(@base_path, "*")].select { |s| File.file?(s) }
81
84
  end
85
+
86
+ def load_from_yaml(yaml)
87
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.1')
88
+ YAML.load(yaml, permitted_classes: [Time, Symbol])
89
+ else
90
+ YAML.load(yaml)
91
+ end
92
+ end
82
93
  end
83
94
  end
84
95
  end
data/lib/soup/snip.rb CHANGED
@@ -39,7 +39,7 @@ class Soup
39
39
  end
40
40
 
41
41
  def respond_to?(method, include_all=false)
42
- @attributes.keys.include?(method.to_s)
42
+ @attributes.keys.any? { |k| k.to_s == method.to_s }
43
43
  end
44
44
 
45
45
  def method_missing(method, *args)
data/test/snip_test.rb CHANGED
@@ -35,4 +35,19 @@ context "A snip" do
35
35
  assert_equal Soup::Snip.new({:name => 'test'}, nil), @soup['test']
36
36
  end
37
37
  end
38
- end
38
+
39
+ context "respond_to?" do
40
+ should "be true when snip has given attribute" do
41
+ assert @snip.respond_to?(:name)
42
+ end
43
+
44
+ should "be false is snip doesn't have given attribute" do
45
+ assert !@snip.respond_to?(:blah)
46
+ end
47
+
48
+ should "allow comparison using symbols or strings" do
49
+ assert @snip.respond_to?(:name)
50
+ assert @snip.respond_to?('name')
51
+ end
52
+ end
53
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soup
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Adam
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-05 00:00:00.000000000 Z
11
+ date: 2022-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kintama
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description:
41
+ description:
42
42
  email: james@lazyatom.com
43
43
  executables: []
44
44
  extensions: []
@@ -68,7 +68,7 @@ files:
68
68
  homepage: http://lazyatom.com
69
69
  licenses: []
70
70
  metadata: {}
71
- post_install_message:
71
+ post_install_message:
72
72
  rdoc_options:
73
73
  - "--main"
74
74
  - README
@@ -85,9 +85,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  requirements: []
88
- rubyforge_project:
89
- rubygems_version: 2.5.1
90
- signing_key:
88
+ rubygems_version: 3.1.6
89
+ signing_key:
91
90
  specification_version: 4
92
91
  summary: A super-simple data store
93
92
  test_files: []