soup 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -21,7 +21,7 @@ spec = Gem::Specification.new do |s|
21
21
 
22
22
  # Change these as appropriate
23
23
  s.name = "soup"
24
- s.version = "1.0.5"
24
+ s.version = "1.0.6"
25
25
  s.summary = "A super-simple data store"
26
26
  s.author = "James Adam"
27
27
  s.email = "james@lazyatom.com"
@@ -8,28 +8,6 @@ class Soup
8
8
  autoload :Backends, 'soup/backends'
9
9
  autoload :Snip, 'soup/snip'
10
10
 
11
- # You can access a default soup using this methods.
12
-
13
- def self.default_instance #:nodoc:
14
- @@instance ||= new
15
- end
16
-
17
- def self.[](*args)
18
- default_instance[*args]
19
- end
20
-
21
- def self.<<(attributes)
22
- default_instance << attributes
23
- end
24
-
25
- def self.with(*args)
26
- default_instance.sieve(*args)
27
- end
28
-
29
- def self.destroy(*args)
30
- default_instance.destroy(*args)
31
- end
32
-
33
11
  # Get the soup ready!
34
12
  def initialize(backend=nil)
35
13
  @backend = backend || Soup::Backends::FileBackend.new
@@ -10,26 +10,13 @@ class Soup
10
10
  end
11
11
 
12
12
  def names
13
- snip_paths.map { |s| File.basename(s).split(".").first }
13
+ snip_paths.map { |s| snip_name_from_path(s) }
14
14
  end
15
15
 
16
16
  def load_snip(name)
17
- path = snip_paths.find { |s| File.basename(s).split(".").first == name }
17
+ path = snip_paths.find { |s| snip_name_from_path(s) == name }
18
18
  if path
19
- file = File.new(path)
20
- data = file.read
21
- default_attributes = {:name => name, :updated_at => file.mtime, :created_at => file.mtime}
22
- if attribute_start = data.index("\n:")
23
- content = data[0, attribute_start].strip
24
- attributes = default_attributes.merge(YAML.load(data[attribute_start, data.length]))
25
- else
26
- content = data
27
- attributes = default_attributes
28
- end
29
- attributes.update(:content => content) if content && content.length > 0
30
- extension = File.extname(path).gsub(/^\./, '')
31
- attributes.update(:extension => extension) if extension != "snip"
32
- Snip.new(attributes, self)
19
+ load_snip_from_path(path, name)
33
20
  else
34
21
  nil
35
22
  end
@@ -54,8 +41,35 @@ class Soup
54
41
  end
55
42
  end
56
43
 
44
+ def all_snips
45
+ snip_paths.map do |path|
46
+ load_snip_from_path(path, snip_name_from_path(path))
47
+ end
48
+ end
49
+
57
50
  private
58
51
 
52
+ def snip_name_from_path(path)
53
+ File.basename(path).split(".").first
54
+ end
55
+
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
66
+ 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)
71
+ end
72
+
59
73
  def path_for(name, extension=nil)
60
74
  snip_extension = ".snip"
61
75
  snip_extension += ".#{extension}" if extension
@@ -65,12 +79,6 @@ class Soup
65
79
  def snip_paths
66
80
  Dir[File.join(@base_path, "*")].select { |s| File.file?(s) }
67
81
  end
68
-
69
- def all_snips
70
- Dir[File.join(@base_path, "*")].map do |key|
71
- load_snip(File.basename(key, ".snip"))
72
- end
73
- end
74
82
  end
75
83
  end
76
84
  end
@@ -11,19 +11,16 @@ class Soup
11
11
 
12
12
  def method_missing(*args)
13
13
  @backends.each do |backend|
14
- if result = backend.__send__(*args)
14
+ if result = backend.respond_to?(args.first) ? backend.__send__(*args) : nil
15
15
  return result
16
16
  end
17
17
  end
18
18
  nil
19
19
  end
20
20
 
21
- private
22
-
23
21
  def all_snips
24
- @backends.map { |b| b.send(:all_snips) }.flatten
22
+ @backends.map { |b| b.all_snips }.flatten
25
23
  end
26
-
27
24
  end
28
25
  end
29
26
  end
@@ -10,7 +10,7 @@ class Soup
10
10
  end
11
11
 
12
12
  def method_missing(*args)
13
- @backend.__send__(*args)
13
+ @backend.__send__(*args) if @backend.respond_to?(args.first)
14
14
  end
15
15
  end
16
16
  end
@@ -51,17 +51,17 @@ class Soup
51
51
  end
52
52
  end
53
53
 
54
- private
55
-
56
- def path_for(name)
57
- File.join(@base_path, name + ".yml")
58
- end
59
-
60
54
  def all_snips
61
55
  Dir[path_for("*")].map do |key|
62
56
  load_snip(File.basename(key, ".yml"))
63
57
  end
64
58
  end
59
+
60
+ private
61
+
62
+ def path_for(name)
63
+ File.join(@base_path, name + ".yml")
64
+ end
65
65
  end
66
66
  end
67
67
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soup
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 5
10
- version: 1.0.5
9
+ - 6
10
+ version: 1.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Adam