Ruby Fog gem usage - ruby

I'm mucking about with the Fog gem and have figured out how to get started:
1.9.3-p545 :008 > c = Fog::Compute::Ecloud.new({
1.9.3-p545 :009 > :base_path => '/cloudapi/spec',
1.9.3-p545 :010 > ecloud_authentication_method: 'basic_auth',
1.9.3-p545 :011 > ecloud_username: 'user#terremark.com',
1.9.3-p545 :012 > ecloud_password: 'password'
1.9.3-p545 :013?> })
[fog][WARNING] Unrecognized arguments: base_path
=> #<Fog::Compute::Ecloud::Real:25681720 #base_path="/cloudapi/spec" #connections={} #connection_options={} #host="https://services.enterprisecloud.terremark.com" #persistent=false #version="2013-06-01" #authentication_method=:basic_auth #access_key=nil #private_key=nil #username="user#terremark.com" #password="password">
I don't know what to do after this, though. How do I get the object to do anything useful? I'm new to Ruby so a lot of the code in the Fog Ecloud source doesn't make sense to me.
I've tried using different methods, but each tends to result in an error.
Can someone provide an example and explanation indicating where I need to go from here?

It looks like you have found a bug!
Fog is giving you this error because base_url is not present in the recognizes line.
I went ahead and fixed it for you. If you are using bundler you can use the latest master by updating your Gemfile to include the following
gem 'fog', :git => 'https://github.com/fog/fog.git'
Or alternatively you can just patch it in your code by executing the following code prior to using fog
require 'fog'
module Fog
module Compute
class Ecloud < Fog::Service
recognizes :ecloud_username, :ecloud_password, :ecloud_version,
:ecloud_access_key, :ecloud_private_key,
:ecloud_authentication_method, :base_path
end
end
end
For information about how to use fog, I would recommend reading the following page.

Related

Which libraries are loaded by default in pry?

When I use Tempfile class in pry, I don't use require it.
% pry -f
pry(main)> Tempfile
Tempfile < #<Class:0x00007fb5121149b8>
But when in irb I must to require tempfile first.
% irb
irb(main):001:0> Tempfile
NameError: uninitialized constant Tempfile
from (irb):1
from /Users/ironsand/.rbenv/versions/2.4.3/bin/irb:11:in `<main>'
irb(main):002:0> require 'tempfile'
=> true
So it seems pry load some libraries by default.
Which libraries are actually loaded?
This is my environment
% ruby -v
ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-darwin17]
% irb --version
pirb 0.9.6(09/06/30)
% pry --version
Pry version 0.11.3 on Ruby 2.4.3
You can compare $LOADED_FEATURES to see everything that's loaded in a default pry session vs an irb session (or a plain ruby script).
The short answer is that Pry loads whichever libraries it needs to provide its own behaviour. The long answer is too long (and too likely to get out of date, or differ between versions) to list here -- better to ask your current environment.
It's good practice not to rely on other libraries to load their dependencies for you, because those dependencies can change. (Though in cases like this, it can be hard to notice you're missing a require, because everything still works.)
As an alternative to $LOADED_FEATURES, which can be a bit excessive, consider:
Gem.loaded_specs.values.each {|s| puts s.name}
which only lists gems with specs
[20] pry(main)> Gem.loaded_specs.values.each {|s| puts s.name};nil
did_you_mean
coderay
method_source
pry
io-console
vls
=> nil
BTW, in this example, I had loaded the vls gem manually.

Where is Rubinius' Actor API?

I got the following output from pry when trying out the example from http://rubini.us/doc/en/systems/concurrency/ with Rubinius 2.2.9:
2.1.0 (main):0 > RUBY_VERSION
=> "2.1.0"
2.1.0 (main):0 > RUBY_PATCHLEVEL
=> 0
2.1.0 (main):0 > RUBY_PLATFORM
=> "x86_64-darwin13.2.0"
2.1.0 (main):0 > RUBY_ENGINE
=> "rbx"
2.1.0 (main):0 > require 'actor'
LoadError: no such file to load -- actor
from kernel/common/code_loader.rb:441:in `load_error'
Is the documentation outdated?
It looks like the documentation is slightly outdated.
Commit 79bd4c30 appears to remove the Actor api from the Rubinius standard library and extract it into the rubinius-actor gem. As far as I can tell with a quick glance, it's the exact same API as the documentation describes.

Ruby carmen 'NameError'

I am using the carmen gem and following the instructions there. When I execute these statements:
require 'carmen'
include Carmen
us = Country.named('United States')
I get a
NameError: uninitialized constant Country
even though I have required and included Carmen. require returns true and include returns Object
The reason is that the Github source and documentation you're seeing is for the latest unreleased version. Put this in your Gemfile instead:
gem "carmen", :git => "git://github.com/jim/carmen.git", :branch => "master"
It's probably best to go to Rubygems and subscribe to the library for updates too, as it's not great to have to rely on an untagged branch in a project.

Rails 3 Authlogic - 'acts_as_authentic' undefined

I'm getting the following error:
NameError (undefined local variable or method `acts_as_authentic' for #<Class:0x1037e6310>):
app/models/user.rb:2
app/controllers/user_controller.rb:3:in `new'
I'm using Rails 3.0.0, with Ruby 1.8.7. Authlogic is in my Gemfile as follows:
gem 'authlogic', :git => "git://github.com/binarylogic/authlogic.git"
The entire contents of my User.rb file are as follows:
class User < ActiveRecord::Base
acts_as_authentic
end
I get the same error whether through 'rails console' or through the server. I have restarted the server more times than I can count. Please help, I can't figure it out.
Use a version of authlogic patched for Rails 3
gem 'authlogic', :git => 'git://github.com/odorcicd/authlogic.git', :branch => 'rails3'
Or even better. Use Devise
Is the Authlogic Gem installed ?.
Please do
Bundle install
this should solve your problem.
gem "authlogic", "2.1.6"
Then
Bundle install
Hope it'll helpfull for you. :)
create a file in config/initializers as restful_authentication.rb
and paste this inside the file and restart server and try
require 'authenticated_system'
require 'restful_authentication/authentication'
require 'restful_authentication/authentication/by_password'
require 'restful_authentication/authentication/by_cookie_token'
require 'restful_authentication/authorization/aasm_roles'
require 'restful_authentication/authorization/stateful_roles'
require 'restful_authentication/trustification/email_validation'

How do I require a specific version of a ruby gem?

Specifically, the ruby-oci8 gem. I have both 1.0.7 and 2.0.4 installed. I want 1.0.7.
I can just require oci8, but I don't get the version I want.
irb(main):001:0> require 'oci8'
=> true
irb(main):002:0> OCI8::VERSION
=> "2.0.4"
I can require using the full path to the file, which works, but is not going to be portable:
irb(main):001:0> require 'C:\Ruby\lib\ruby\gems\1.8\gems\ruby-oci8-1.0.7-x86-mswin32-60\lib\oci8'
=> true
irb(main):002:0> OCI8::VERSION
=> "1.0.7"
I can use the gem command to ask for the version I want, but it doesn't appear to actually load the library:
irb(main):001:0> gem 'ruby-oci8', :lib=>'oci8', :version=>'=1.0.7'
=> true
irb(main):002:0> OCI8::VERSION
NameError: uninitialized constant OCI8
from (irb):2
I would definitely favor this last approach if would load the library, rather than just confirming that it's present on my system. What am I missing?
My problem was twofold:
1) confusing gem command syntax with that used in config.gem lines in a rails environment.rb configuration file.
2) failing to issue a require command after the gem command.
Proper usage in a script is:
gem 'ruby-oci8', '=1.0.7'
require 'oci8' # example is confusing; file required (oci8.rb) is not
# same name as gem, as is frequently the case
Proper usage in a rails 2.3.x environment.rb file is:
config.gem "ruby-oci8", :version=>'1.0.7'
Thanks to the folks at http://www.ruby-forum.com/topic/109100
Try the following syntax (instead of require):
require_gem 'RMagick' , '=1.10'
require_gem 'RMagick' , '>=1.10'
require_gem 'rake', '>=0.7.0', '<0.9.0'

Resources