Setting Up Configuration Settings When Writing a Gem

Setting up configuration settings when writing a gem

Try refactoring to:

def self.configuration
@configuration ||= Configuration.new
end

def self.configure
yield(configuration) if block_given?
end

Writing a Gem -- How to manage configuration settings?

there are gems that help you create rails initializer style configuration.

an example is https://github.com/phoet/confiture/

Config information for a gem

If are you working on rails gem, you can create install generator which will copy default config file and then load it into your app.

Gem install configuration in Gemfile

You can specify the gem install configuration options in the bundle config.

Bundler retrieves its configuration from the local application (app/.bundle/config) environment variables and then user's home directory (~/.bundle/config), in that order of priority.

A very common example, the mysql gem, requires Snow Leopard users to pass configuration flags to gem install to specify where to find the mysql_config executable.

gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

Since the specific location of that executable can change from machine to machine, you can specify these flags on a per-machine basis.

bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config

After running this command, every time bundler needs to install the mysql gem, it will pass along the flags you specified.

Visit bundle-config for more info.

How to use a Gem with different config settings for my users

After briefly looking into the code of the gem, I think you should be able to create instances ad hoc as you need them. For example:

config = SquareConnect::Configuration.new do |config|
config.access_token = 'some token'
end
api_client = SquareConnect::ApiClient.new(config)
api_instance = SquareConnect::CatalogApi.new(api_client)

How to configure a GEM in a Ruby on Rails app

in config/initializers/load_lib.rb(create if does not exist) write: require 'kraken_client' and save
after it come to rails c and call it

How do I update Ruby Gems from behind a Proxy (ISA-NTLM)

I wasn't able to get mine working from the command-line switch but I have been able to do it just by setting my HTTP_PROXY environment variable. (Note that case seems to be important). I have a batch file that has a line like this in it:

SET HTTP_PROXY=http://%USER%:%PASSWORD%@%SERVER%:%PORT%

I set the four referenced variables before I get to this line obviously. As an example if my username is "wolfbyte", my password is "secret" and my proxy is called "pigsy" and operates on port 8080:

SET HTTP_PROXY=http://wolfbyte:secret@pigsy:8080

You might want to be careful how you manage that because it stores your password in plain text in the machine's session but I don't think it should be too much of an issue.

Install a specific set of gems in a CircleCI configuration file

THIS SOLUTION ONLY WORKS WITH CIRCLE 1.0

From my current research I had to verify the continous_integration environment
was setup correctly throughout Rails inside of secrets, the environments folder, gems, etc. As it turns out I have discovered that bundler does not use the ENV set so I am working with the following configuration know to force cache the gems, speed up the build process, and use the continous_integration environment.

References

  • CircleCI gems caching
  • https://github.com/sj26/rspec_junit_formatter/issues/50#issuecomment-312787281

.rspec

--color
--require spec_helper
--format documentation

.circle.yml

machine:
timezone:
America/Los_Angeles
ruby:
version:
2.4.1
services:
- redis

dependencies:
pre:
- gem install bundler
- gem update bundler
override:
- bundle config without development:test
- bundle check --path=vendor/bundle || bundle install --without development test --path=vendor/bundle --jobs=4 --retry=3:
timeout: 180

database:
override:
- RAILS_ENV=continous_integration bundle exec rake db:drop
- RAILS_ENV=continous_integration bundle exec rake db:setup

test:
override:
- RAILS_ENV=continous_integration bundle exec rspec --format RspecJunitFormatter -o $CIRCLE_TEST_REPORTS/rspec.xml
post:
- gem install brakeman
- gem install rubocop
- gem install rubocop-rspec
- RAILS_ENV=continous_integration bundle exec rubocop --format fuubar --require rubocop-rspec --config .rubocop.yml
- RAILS_ENV=continous_integration brakeman -z

Gemfile

group :development do
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'spring-commands-rspec'
gem 'spring-commands-rubocop'
end

group :development, :test do
gem 'pry-rails'
gem 'pry-nav'
gem 'pry-clipboard'
gem 'pry-rescue'
gem 'table_print'
gem 'awesome_print'
gem 'guard-rake'
gem 'guard-rspec'
end

group :development, :test, :continous_integration do
gem 'brakeman', require: false
gem 'rubocop', require: false
gem 'rubocop-rspec', require: false
gem 'timecop'
gem 'mail_safe'
gem 'dotenv-rails'
gem 'factory_girl_rails'
gem 'faker', '~> 1.6.6'
end

group :test, :continous_integration do
gem 'simplecov'
gem 'database_cleaner'
gem 'rspec-rails'
gem 'json_spec'
gem 'json-schema'
gem 'json_matchers'
gem 'shoulda-matchers'
gem 'nyan-cat-formatter'
gem 'rspec_junit_formatter', '~> 0.3.0.pre6'
gem 'webmock'
gem 'vcr'
end

This setup will yield the correct error output in Circle CI too

Sample Image



Related Topics



Leave a reply



Submit