Module: OCTranspo::RemoteResourceMethods
- Included in:
- MobileResourceMethods, StopResource
- Defined in:
- lib/octranspo/remote_resource_methods.rb
Instance Method Summary collapse
- #cache(options = {}) ⇒ Object
- #cache_path ⇒ Object
- #cache_path_for(options = {}) ⇒ Object
- #create_fixture(options = {}) ⇒ Object
- #fixture_path_for(options = {}) ⇒ Object
- #fixtures_path ⇒ Object
- #logger ⇒ Object
- #path_for(options = {}) ⇒ Object
- #read(options = {}) ⇒ Object
- #read_from_cache(options) ⇒ Object
- #read_from_fixture(options) ⇒ Object
- #read_from_remote(options) ⇒ Object
- #reset! ⇒ Object
- #site ⇒ Object
- #url_for(options = {}) ⇒ Object
- #use_fixtures! ⇒ Object
Instance Method Details
#cache(options = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/octranspo/remote_resource_methods.rb', line 75 def cache (={}) address = cache_path_for() system "mkdir -p #{File.dirname(address)}" File.open(address, "w") do |f| f.write read_from_remote() end puts "Cached #{address}" read_from_cache() end |
#cache_path ⇒ Object
61 62 63 |
# File 'lib/octranspo/remote_resource_methods.rb', line 61 def cache_path "cache/octranspo/#{self.name.demodulize.underscore}" end |
#cache_path_for(options = {}) ⇒ Object
53 54 55 |
# File 'lib/octranspo/remote_resource_methods.rb', line 53 def cache_path_for (={}); "#{cache_path}/#{path_for()}" end |
#create_fixture(options = {}) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/octranspo/remote_resource_methods.rb', line 65 def create_fixture (={}) address = fixture_path_for() puts "Creating fixture #{address}" system "mkdir -p #{File.dirname(address)}" File.open(address, "w") do |f| f.write read_from_remote() end read_from_fixture() end |
#fixture_path_for(options = {}) ⇒ Object
49 50 51 |
# File 'lib/octranspo/remote_resource_methods.rb', line 49 def fixture_path_for (={}); "#{fixtures_path}/#{path_for()}" end |
#fixtures_path ⇒ Object
57 58 59 |
# File 'lib/octranspo/remote_resource_methods.rb', line 57 def fixtures_path "test/fixtures/#{self.name.demodulize.underscore}" end |
#logger ⇒ Object
85 86 87 |
# File 'lib/octranspo/remote_resource_methods.rb', line 85 def logger RAILS_DEFAULT_LOGGER end |
#path_for(options = {}) ⇒ Object
47 |
# File 'lib/octranspo/remote_resource_methods.rb', line 47 def path_for (={}); end |
#read(options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/octranspo/remote_resource_methods.rb', line 6 def read (={}) # puts url_for(options) case @source when :fixtures read_from_fixture() else read_from_cache() || cache() end end |
#read_from_cache(options) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/octranspo/remote_resource_methods.rb', line 28 def read_from_cache () address = cache_path_for() if File.exist?(address) open(address).read end end |
#read_from_fixture(options) ⇒ Object
22 23 24 25 26 |
# File 'lib/octranspo/remote_resource_methods.rb', line 22 def read_from_fixture () address = fixture_path_for() create_fixture() unless File.exist?(address) open(address).read end |
#read_from_remote(options) ⇒ Object
16 17 18 19 20 |
# File 'lib/octranspo/remote_resource_methods.rb', line 16 def read_from_remote () url = url_for() puts "Opening #{url}" open(url).read end |
#reset! ⇒ Object
35 36 37 |
# File 'lib/octranspo/remote_resource_methods.rb', line 35 def reset! @source = nil end |
#site ⇒ Object
43 |
# File 'lib/octranspo/remote_resource_methods.rb', line 43 def site; end |
#url_for(options = {}) ⇒ Object
45 |
# File 'lib/octranspo/remote_resource_methods.rb', line 45 def url_for (={}); end |
#use_fixtures! ⇒ Object
39 40 41 |
# File 'lib/octranspo/remote_resource_methods.rb', line 39 def use_fixtures! @source = :fixtures end |