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

Class Method Summary collapse

Class Attribute Details

.configObject

Returns the value of attribute config.



13
14
15
# File 'lib/rubyhorn.rb', line 13

def config
  @config
end

.config_optionsObject

Returns the value of attribute config_options.



13
14
15
# File 'lib/rubyhorn.rb', line 13

def config_options
  @config_options
end

.config_pathObject

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

.clientObject

Connect to Opencast Matterhorn using default config

Returns:

  • Rubyhorn::MatterhornClient



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

Parameters:

Returns:

  • Rubyhorn::MatterhornClient



157
158
159
# File 'lib/rubyhorn.rb', line 157

def self.client= client
  @client = client
end

.config_for_environmentObject



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

Returns:

  • (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

Returns:

  • Rubyhorn::Repository



144
145
146
# File 'lib/rubyhorn.rb', line 144

def self.connect *args
  @client ||= MatterhornClient.new *args
end

.environmentString

Determine what environment we’re running in. Order of preference is:

  1. config_options

  2. Rails.env

  3. ENV

  4. ENV

  5. development

Examples:

Rubyhorn.init(:environment=>"test")
Rubyhorn.environment => "test"

Returns:

  • (String)


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 config_options.fetch(:environment,nil)
    return config_options[: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_pathString

Determine the matterhorn config file to use. Order of preference is:

  1. Use the config_options if it exists

  2. Look in Rails.root/config/matterhorn.yml

  3. Look in current working directory/config/matterhorn.yml

  4. Load the default config that ships with this gem

Returns:

  • (String)


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_options[: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.expand_path(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:

  1. 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( options={} )
  # Make config_options into a Hash if nil is passed in as the value
  options = {} if options.nil?
  @config_options = options
  config_reload!
end

.load_configObject



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.expand_path(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_configsObject



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

.versionObject



4
5
6
# File 'lib/rubyhorn/version.rb', line 4

def self.version
  @version ||= File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).chomp
end