Module: Rubyhorn
- Defined in:
- lib/rubyhorn.rb,
lib/rubyhorn.rb,
lib/rubyhorn/version.rb,
lib/rubyhorn/workflow.rb,
lib/rubyhorn/matterhorn_client.rb
Defined Under Namespace
Modules: RestClient Classes: MatterhornClient, RubyhornConfigurationException, Workflow
Constant Summary collapse
- VERSION =
self.version
Class Attribute Summary collapse
-
.config ⇒ Object
Returns the value of attribute config.
-
.config_options ⇒ Object
Returns the value of attribute config_options.
-
.config_path ⇒ Object
Returns the value of attribute config_path.
Class Method Summary collapse
-
.client ⇒ Object
Connect to Opencast Matterhorn using default config.
-
.client=(client) ⇒ Object
Set the default Opencast Matterhorn client.
- .config_for_environment ⇒ Object
- .config_loaded? ⇒ Boolean
- .config_reload! ⇒ Object
-
.connect(*args) ⇒ Object
Connect to Opencast Matterhorn.
-
.environment ⇒ String
Determine what environment we’re running in.
-
.get_config_path ⇒ String
Determine the matterhorn config file to use.
-
.init(options = {}) ⇒ Object
Options allowed in matterhorn.yml first level is the environment (e.g. development, test, production and any custom environments you may have) the second level has these keys: 1.
- .load_config ⇒ Object
- .load_configs ⇒ Object
- .reset! ⇒ Object
- .version ⇒ Object
Class Attribute Details
.config ⇒ Object
Returns the value of attribute config.
13 14 15 |
# File 'lib/rubyhorn.rb', line 13 def config @config end |
.config_options ⇒ Object
Returns the value of attribute config_options.
13 14 15 |
# File 'lib/rubyhorn.rb', line 13 def @config_options end |
.config_path ⇒ Object
Returns the value of attribute config_path.
13 14 15 |
# File 'lib/rubyhorn.rb', line 13 def config_path @config_path end |
Class Method Details
.client ⇒ Object
Connect to Opencast Matterhorn using default config
150 151 152 |
# File 'lib/rubyhorn.rb', line 150 def self.client @client ||= self.connect(config_for_environment) end |
.client=(client) ⇒ Object
Set the default Opencast Matterhorn client
157 158 159 |
# File 'lib/rubyhorn.rb', line 157 def self.client= client @client = client end |
.config_for_environment ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/rubyhorn.rb', line 78 def self.config_for_environment envconfig = @config[@config_env.to_sym].symbolize_keys url = envconfig[:url] u = URI.parse url envconfig[:user] = u.user envconfig[:password] = u.password envconfig[:url] = "#{u.scheme}://#{u.host}:#{u.port}#{u.path}" envconfig end |
.config_loaded? ⇒ Boolean
57 58 59 |
# File 'lib/rubyhorn.rb', line 57 def self.config_loaded? @config_loaded || false end |
.config_reload! ⇒ Object
48 49 50 51 |
# File 'lib/rubyhorn.rb', line 48 def self.config_reload! reset! load_configs end |
.connect(*args) ⇒ Object
Connect to Opencast Matterhorn
144 145 146 |
# File 'lib/rubyhorn.rb', line 144 def self.connect *args @client ||= MatterhornClient.new *args end |
.environment ⇒ String
Determine what environment we’re running in. Order of preference is:
-
Rails.env
-
development
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/rubyhorn.rb', line 98 def self.environment if .fetch(:environment,nil) return [:environment] elsif defined?(Rails.env) and !Rails.env.nil? return Rails.env.to_s elsif defined?(ENV['environment']) and !(ENV['environment'].nil?) return ENV['environment'] elsif defined?(ENV['RAILS_ENV']) and !(ENV['RAILS_ENV'].nil?) logger.warn("You're depending on RAILS_ENV for setting your environment. This is deprecated in Rails3. Please use ENV['environment'] for non-rails environment setting: 'rake foo:bar environment=test'") ENV['environment'] = ENV['RAILS_ENV'] return ENV['environment'] else ENV['environment'] = 'development' #raise "Can't determine what environment to run in!" end end |
.get_config_path ⇒ String
Determine the matterhorn config file to use. Order of preference is:
-
Use the config_options if it exists
-
Look in
Rails.root
/config/matterhorn.yml -
Look in current working directory/config/matterhorn.yml
-
Load the default config that ships with this gem
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/rubyhorn.rb', line 120 def self.get_config_path if (config_path = [:config_path] ) raise RubyhornConfigurationException, "file does not exist #{config_path}" unless File.file? config_path return config_path end if defined?(Rails.root) config_path = "#{Rails.root}/config/matterhorn.yml" return config_path if File.file? config_path end if File.file? "#{Dir.getwd}/config/matterhorn.yml" return "#{Dir.getwd}/config/matterhorn.yml" end # Last choice, check for the default config file config_path = File.(File.join(File.dirname(__FILE__), "..", "config", "matterhorn.yml")) logger.warn "Using the default matterhorn.yml that comes with rubyhorn. If you want to override this, pass the path to matterhorn.yml to Rubyhorn - ie. Rubyhorn.init(:config_path => '/path/to/matterhorn.yml) - or set Rails.root and put matterhorn.yml into \#{Rails.root}/config." return config_path if File.file? config_path raise RubyhornConfigurationException "Couldn't load matterhorn config file!" end |
.init(options = {}) ⇒ Object
Options allowed in matterhorn.yml first level is the environment (e.g. development, test, production and any custom environments you may have) the second level has these keys:
-
url: url including protocol, user/pass, host, port, and path (e.g. matterhorn_system_account:[email protected]:8080/)
41 42 43 44 45 46 |
# File 'lib/rubyhorn.rb', line 41 def self.init( ={} ) # Make config_options into a Hash if nil is passed in as the value = {} if .nil? @config_options = config_reload! end |
.load_config ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/rubyhorn.rb', line 68 def self.load_config @config_path = get_config_path logger.info("Loading Rubyhorn.config from #{File.(config_path)}") @config = YAML.load(File.open(config_path)).symbolize_keys raise "The #{@config_env.to_sym} environment settings were not found in the matterhorn.yml config. If you already have a matterhorn.yml file defined, make sure it defines settings for the #{@config_env} environment" unless config[@config_env.to_sym] @config end |
.load_configs ⇒ Object
61 62 63 64 65 66 |
# File 'lib/rubyhorn.rb', line 61 def self.load_configs return if config_loaded? @config_env = environment load_config @config_loaded = true end |
.reset! ⇒ Object
53 54 55 |
# File 'lib/rubyhorn.rb', line 53 def self.reset! @config_loaded = false #Force reload of configs end |
.version ⇒ Object
4 5 6 |
# File 'lib/rubyhorn/version.rb', line 4 def self.version @version ||= File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).chomp end |