Code Monkey home page Code Monkey logo

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

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

Stargazers

Rodrigo Figueroa avatar Dan Palmer avatar Andriy Matchyshyn avatar

Watchers

 avatar Paul McKibbin avatar Mehmet Duran avatar Isaiah avatar Jonathan Tweed avatar  avatar Hanna Kalinowska avatar Vesa Marttila avatar  avatar Tiest Vilee avatar Cronix avatar Jamie Draper avatar Neale Upstone avatar  avatar Francis Rhys-Jones avatar Mike Howsden avatar Phil Parker avatar James Langridge avatar Gregory Bigwood avatar Leandro Nunes avatar  avatar Florencio Sarmiento avatar shakil siddique avatar Andrew Walker avatar Abhay PS avatar Sebastian Bustamante avatar James Cloos avatar Emver Hidalgo avatar Rob Lloyd avatar  avatar Romulo De Lazzari avatar Chinmay Naik avatar  avatar Nicholas Call avatar Sara Morueta avatar Kevin Hinde avatar  avatar Panagiotis Papageorgiou avatar christine ballisty avatar Shaun Adams avatar Jan avatar  avatar Sijy Mathew avatar Rashmi Verma avatar Deepak Sharma avatar Adele Zhou avatar Supriya Peddisetty avatar Tom Meredith avatar Jack Watkins avatar Zal Shevket avatar Krishna Chaithanya Dhulipala avatar Hamid Aitsaadi avatar Chris Hale avatar Aleksandr Kotin avatar Pooja Chugh avatar caoilTe O'Connor avatar  avatar FedeQuintas avatar Sam Leach avatar Angela Cesaro avatar Philipp Eder avatar  avatar Erik Schulze avatar Jorma Pajunen avatar Krishna Gaur avatar Deepraj Agrawal avatar Remya Krishnankutty avatar Jeff Destine avatar  avatar Nestor Bustamante avatar Nuno Graca avatar Rakesh Sharma avatar Wai Cheung avatar Ramneet Bhasin avatar Andrew Gaffney avatar Ekin Sökmen avatar Chris Ryan avatar Richard Bangay avatar Carlos Esteves avatar  avatar Hui Zhang avatar Elysia Altuntas avatar Christoph Oppawsky avatar Alex Pearson avatar Joe Reddie avatar Flora Graham avatar Bruno Silva avatar Dan Griffin avatar Andrew Peter Martin avatar Daniel Shearer avatar Jordan Dalton avatar  avatar Ravinder Kumar avatar Isabel Batista avatar  avatar Binit Bhaskar avatar Jose Chavez avatar Jamie Sampson avatar Luke Stavenhagen avatar Christopher Clough avatar

macmillan-utils's Issues

Logger::Syslog (& related) documentation.

Reasons behind

https://github.com/springernature/macmillan-utils/blob/db8dd08176760c2e065f09689dcddc261f910829/lib/macmillan/utils/logger/factory.rb

are not clear. Documentation needed, possibly starting with comments in the code.

Why are we using Logger::Syslog (from syslog-logger gem) ? Presumably to map from Rails log severities to the Syslog counterparts .

Potential confusion with Syslog::Logger. --> http://ruby-doc.org/stdlib-2.0.0/libdoc/syslog/rdoc/Syslog/Logger.html

Syslog Severity Levels --> https://en.wikipedia.org/wiki/Syslog#Severity_level

Ruby Logger Levels --> https://ruby-doc.org/stdlib-2.1.0/libdoc/logger/rdoc/Logger.html

hound

We don't appear to be using hound in a manner consistent with their docs. Apparently the hound.yml should reference the rubocop.yml ... they should not be the same thing, i.e. symlinked as they are at present.

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.