ols 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/History.txt +4 -0
  2. data/lib/ols/cache.rb +24 -32
  3. data/lib/ols/version.rb +1 -1
  4. metadata +17 -17
@@ -1,3 +1,7 @@
1
+ === 0.2.1 2011-11-07
2
+
3
+ * Cache bugfix. Removed the use of 'Dir.chdir' as it was firing warnings.
4
+
1
5
  === 0.2.0 2011-11-07
2
6
 
3
7
  * Addition of a basic cache layer. Users can now cache regularly used ontologies on disk.
@@ -12,6 +12,7 @@ module OLS
12
12
  def initialize(args={})
13
13
  options = { :directory => Dir.getwd }.merge(args)
14
14
  @cache_directory = options[:directory]
15
+ @cache_directory.sub!(/\/$/,'')
15
16
 
16
17
  prepare_cache
17
18
  end
@@ -25,10 +26,8 @@ module OLS
25
26
  filename = @term_id_to_files[term_id].to_s
26
27
 
27
28
  unless filename.nil? || filename.empty?
28
- Dir.chdir(@cache_directory) do
29
- root_term = Marshal.load( File.open(filename) )
30
- found_term = root_term.send(:find_in_graph,term_id)
31
- end
29
+ root_term = Marshal.load( File.open("#{@cache_directory}/#{filename}") )
30
+ found_term = root_term.send(:find_in_graph,term_id)
32
31
  end
33
32
 
34
33
  found_term
@@ -50,17 +49,14 @@ module OLS
50
49
 
51
50
  new_filenames = []
52
51
 
53
- Dir.chdir(@cache_directory) do
54
- OLS.root_terms(ontology).each do |term|
55
- term_filename = "#{term.term_id.gsub(':','')}.marshal"
56
- term.focus_graph!
57
- File.open("#{term_filename}",'w') { |f| f << Marshal.dump(term) }
58
- @cached_ontologies[ontology] ||= { :filenames => [], :date => Date.today }
59
- @cached_ontologies[ontology][:filenames].push(term_filename) unless @cached_ontologies[ontology][:filenames].include? term_filename
60
- new_filenames.push(term_filename)
61
- end
52
+ OLS.root_terms(ontology).each do |term|
53
+ term_filename = "#{term.term_id.gsub(':','')}.marshal"
54
+ term.focus_graph!
55
+ File.open("#{@cache_directory}/#{term_filename}",'w') { |f| f << Marshal.dump(term) }
56
+ @cached_ontologies[ontology] ||= { :filenames => [], :date => Date.today }
57
+ @cached_ontologies[ontology][:filenames].push(term_filename) unless @cached_ontologies[ontology][:filenames].include? term_filename
58
+ new_filenames.push(term_filename)
62
59
  end
63
-
64
60
  @cached_ontologies[ontology][:filenames].delete_if { |file| !new_filenames.include?(file) }
65
61
 
66
62
  write_cached_ontologies_to_disk
@@ -76,10 +72,8 @@ module OLS
76
72
  def remove_ontology_from_cache(ontology)
77
73
  raise ArgumentError, "'#{ontology}' is not part of the cache" unless OLS.ontologies.include?(ontology)
78
74
 
79
- Dir.chdir(@cache_directory) do
80
- @cached_ontologies[ontology][:filenames].each do |file|
81
- File.delete(file)
82
- end
75
+ @cached_ontologies[ontology][:filenames].each do |file|
76
+ File.delete("#{@cache_directory}/#{file}")
83
77
  end
84
78
 
85
79
  @cached_ontologies.delete(ontology)
@@ -92,9 +86,7 @@ module OLS
92
86
 
93
87
  # writes the @cached_ontologies variable to disk
94
88
  def write_cached_ontologies_to_disk
95
- Dir.chdir(@cache_directory) do
96
- File.open('cached_ontologies.yaml','w') { |f| f << @cached_ontologies.to_yaml }
97
- end
89
+ File.open("#{@cache_directory}/cached_ontologies.yaml",'w') { |f| f << @cached_ontologies.to_yaml }
98
90
  end
99
91
 
100
92
  # Utility function to prepare the cache.
@@ -103,18 +95,18 @@ module OLS
103
95
  @term_id_to_files = {}
104
96
 
105
97
  Dir.mkdir(@cache_directory) unless Dir.exists?(@cache_directory)
106
- Dir.chdir(@cache_directory) do
107
- @cached_ontologies = YAML.load( File.open('cached_ontologies.yaml') ) if File.exists?('cached_ontologies.yaml')
108
-
109
- @cached_ontologies.each do |ontology,details|
110
- details[:filenames].each do |filename|
111
- root_term = Marshal.load( File.open(filename) )
112
- next unless root_term.is_a? OLS::Term
113
- @term_id_to_files[ root_term.term_id ] = filename.to_sym
114
- root_term.all_child_ids.each { |term_id| @term_id_to_files[term_id] = filename.to_sym }
115
- end
98
+
99
+ @cached_ontologies = YAML.load( File.open("#{@cache_directory}/cached_ontologies.yaml") ) if File.exists?("#{@cache_directory}/cached_ontologies.yaml")
100
+
101
+ @cached_ontologies.each do |ontology,details|
102
+ details[:filenames].each do |filename|
103
+ root_term = Marshal.load( File.open("#{@cache_directory}/#{filename}") )
104
+ next unless root_term.is_a? OLS::Term
105
+ @term_id_to_files[ root_term.term_id ] = filename.to_sym
106
+ root_term.all_child_ids.each { |term_id| @term_id_to_files[term_id] = filename.to_sym }
116
107
  end
117
108
  end
118
109
  end
119
110
  end
120
- end
111
+ end
112
+
@@ -2,5 +2,5 @@
2
2
 
3
3
  module OLS
4
4
  # OLS::VERSION - The OLS gem version
5
- VERSION = "0.2.0"
5
+ VERSION = "0.2.1"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ols
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: savon
16
- requirement: &2152592920 !ruby/object:Gem::Requirement
16
+ requirement: &2156971680 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152592920
24
+ version_requirements: *2156971680
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &2152592420 !ruby/object:Gem::Requirement
27
+ requirement: &2156971240 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2152592420
35
+ version_requirements: *2156971240
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: shoulda
38
- requirement: &2152591680 !ruby/object:Gem::Requirement
38
+ requirement: &2156970820 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2152591680
46
+ version_requirements: *2156970820
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: vcr
49
- requirement: &2152590620 !ruby/object:Gem::Requirement
49
+ requirement: &2156970400 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2152590620
57
+ version_requirements: *2156970400
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: webmock
60
- requirement: &2152589180 !ruby/object:Gem::Requirement
60
+ requirement: &2156969980 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2152589180
68
+ version_requirements: *2156969980
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
- requirement: &2152587220 !ruby/object:Gem::Requirement
71
+ requirement: &2156969560 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2152587220
79
+ version_requirements: *2156969560
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: simplecov-rcov
82
- requirement: &2152585760 !ruby/object:Gem::Requirement
82
+ requirement: &2156969140 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2152585760
90
+ version_requirements: *2156969140
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: mocha
93
- requirement: &2152584200 !ruby/object:Gem::Requirement
93
+ requirement: &2156968720 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2152584200
101
+ version_requirements: *2156968720
102
102
  description: ! "\n OLS provides a simple interface to the EBI's Ontology Lookup
103
103
  Service (http://www.ebi.ac.uk/ontology-lookup/).\n It provides an easy lookup
104
104
  of ontology terms and automagically builds up ontology trees for you.\n "