GithubHelp home page GithubHelp logo

mattrayner / macmillan-utils Goto Github PK

View Code? Open in Web Editor NEW

This project forked from springernature/macmillan-utils

0.0 2.0 0.0 110 KB

A collection of useful patterns we use in our Ruby applications.

License: MIT License

Ruby 100.00%

macmillan-utils's Introduction

Macmillan::Utils

A collection of useful patterns we use in our Ruby applications.

<img src=“https://travis-ci.org/springernature/macmillan-utils.svg?branch=log-formatter” alt=“Build Status” /> <img src=“https://codeclimate.com/github/springernature/macmillan-utils.png” alt=“CodeClimate Rating” /> <img src=“https://codeclimate.com/github/springernature/macmillan-utils/coverage.png” alt=“Test Coverage” /> <img src=“https://img.shields.io/badge/license-MIT-blue.svg” alt=“MIT Licensed” />

Installation

Add this line to your application’s Gemfile:

gem 'macmillan-utils', require: false

And then execute:

$ bundle

Or install it yourself with:

$ gem install macmillan-utils

Usage

Logger Objects

To build logger objects quickly and easily:

require 'macmillan/utils/logger'

logger = Macmillan::Utils::Logger::Factory.build_logger(:syslog, tag: 'myapp')

The logger will automatically use the {Macmillan::Utils::Logger::Formatter} formatter, and will log at the {Logger::INFO} level.

See the class documentation for more information:

  • {Macmillan::Utils::Logger::Factory}

  • {Macmillan::Utils::Logger::Formatter}

Settings

Easily store and lookup configuration values in either environment variables, or a ‘application.yml` file.

ENV['REDIS_URL'] = 'localhost'
$settings        = Macmillan::Utils::Settings.instance
redis_url        = $settings.lookup('redis_url')          #=> 'localhost'

The default action is to support BOTH environment variables and a ‘application.yml` file for settings - if you would prefer only one or the other, see the ’Switching Backends’ section.

If a setting is requested and it has not been set (in any configured backend), a Macmillan::Utils::Settings::KeyNotFoundError is raised.

Evironment Variables

Set your environment variables as you would normally, using all caps for the key name, and you can then fetch the value using ‘.lookup`. Simples.

‘application.yml` Files

If you prefer to use a YAML based config file, this is the option for you. The code will first look for a ‘application.yml` file in a `config` directory (within the current working directory), if it doesn’t find one, then it looks in the current working directory, and keeps moving up the filesystem until it finds one. If it doesn’t it raises an error.

Switching Backends

By default both the environment variable and application yaml backends are used, if you’d like only one, you need to specify this before building the settings instance, i.e.:

Macmillan::Utils::Settings.backends = [Macmillan::Utils::Settings::EnvVarsBackend]

would only look for environment variables, whereas

Macmillan::Utils::Settings.backends = [Macmillan::Utils::Settings::AppYamlBackendBackend]

would only look for settings in an ‘application.yml` file.

RSpec Helpers

Add the following to the top of your ‘spec_helper.rb`:

require 'macmillan/utils/rspec/rspec_defaults'
require 'macmillan/utils/rspec/webmock_helper'
require 'macmillan/utils/test_helpers/codeclimate_helper'
require 'macmillan/utils/test_helpers/simplecov_helper'
require 'macmillan/utils/test_helpers/fixture_loading_helper'

Cucumber Helpers

Add the following to the top of your ‘env.rb`:

require 'macmillan/utils/cucumber/cucumber_defaults'
require 'macmillan/utils/cucumber/webmock_helper'
require 'macmillan/utils/test_helpers/codeclimate_helper'
require 'macmillan/utils/test_helpers/simplecov_helper'
require 'macmillan/utils/test_helpers/fixture_loading_helper'

StatsD

  • {Macmillan::Utils::StatsdDecorator} - Logging and more for StatsD calls.

  • {Macmillan::Utils::StatsdStub} - Stubbed StatsD class for use in test suites.

  • {Macmillan::Utils::StatsdMiddleware} - Rack middleware for sending web application metrics to StatsD

  • {Macmillan::Utils::StatsdControllerHelper} - Helper functions to send metrics to StatsD via {Macmillan::Utils::StatsdMiddleware}

Contributing

  1. Fork it ( github.com/springernature/macmillan-utils/fork )

  2. Create your feature branch (‘git checkout -b my-new-feature`)

  3. Commit your changes (‘git commit -am ’Add some feature’‘)

  4. Push to the branch (‘git push origin my-new-feature`)

  5. Create a new Pull Request

macmillan-utils's People

Contributors

baob avatar craigw avatar csutter avatar dazoakley avatar dfranciosi avatar ettomatic avatar gravityblast avatar hkalinowska avatar jasmomyer avatar lozette avatar mattrayner avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.