Skip to content

arvanasse/site_connection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Provides an 'establish_site_connection' method to ActiveResource::Base that is similar to the 'establish_connection'
method of ActiveRecord::Base.  The intention is to simplify the process of setting the ActiveResource::Base.site
in different programming environments.

It assumes a config/sites.yml file that defines the URI components for each environment like this:

development:
  sample:
    host: sample.myapp.local
    port: 80
    protocol: http

test:
  sample:
    host: test.myapp.com
    port: 80
    protocol: http

production:
  sample:
    host: sample.myapp.com
    port: 80
    protocol: https
    user: secret
    password: topsecret


Given a sites.yml file configured as shown you may call establish_site_connection on the ActiveResource-based class to
define the site connection like this:

class RemoteWidget < ActiveResource::Base
  self.site = self.establish_site_connection( :sample )
end

$ ./script/console development
>> RemoteWidget.site
=> #<URI::HTTP:0x351b500 URL:http://sample.myapp.local>

$ ./script/console production
>> RemoteWidget.site
=> #<URI::HTTP:0x351b500 URL:http://secret:topsecret@sample.myapp.com>

#######################################

Koinonia::SiteConnection calling establish_site_connection with improper configuration
- should raise an argument error if the requested Rails environment is not configured
- should raise an argument error if the requested connection is not defined for the Rails environment
- should raise an argument error if no parameters are provided

Koinonia::SiteConnection calling establish_site_connection with a valid configuration file
- should load a unique host for the development environment
- should load a unique host for the production environment
- should load a unique host for the test environment
- should support multiple named hosts per environment
- should include the http basic user if provided
- should include the http basic user and password if both are provided
- should ignore the http basic password if it is provided without a user

About

Extends ActiveResource to read site information from a yaml file

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages