Giter VIP home page Giter VIP logo

needs_resources's Introduction

needs_resources

DESCRIPTION:

Needs-resources is an extremely lightweight Inversion of Control provider of resources for an application. When an application needs to interact with any number of external resources or configurable components, this allows for a generic, standard way of externalizing those resources in a minimal effort sort of way.

SUPPORT:

The bug tracker is available here:

SYNOPSIS:

class LinuxHost
  include NeedsResources::NestedResourceType

  attr :ip, :required => true
  attr :hostname, :username, :required => false
end

class Service
  include NeedsResources::ResourceType

  attr :port, :required => true
  attr :admin_email, :default => '[email protected]'
end

class MyApplication
  extend NeedsResources

  needs_resource :linux_host
  linux_host.needs_resources :http_service, :https_service, :smtp_service

  def main
    NeedsResources.ensure_resources

    puts "My linux host is #{linux_host.ip} (#{linux_host.hostname})"

    puts "It has the following services:"
    linux_host.resources.each do |name, service|
      puts "  * #{name} - port #{service.port} [#{service.admin_email}]"
    end

    puts "We can also reference nested resources by name, e.g. #{linux_host.http_service.admin_email}"
  end
end

MyApplication.new.main

Resources can be specified in one of three places:

  • Home directory (~/.resources)
  • Current working directory (.resources)
  • Environment variable (RESOURCES=/home/foo/my.resources)

Only the latter option allows for a custom file name.

The following would be an example .resources file for the above setup:

---
linux_host:
  ip: 10.10.0.42
  hostname: archimedes
  resources:
    http_service:
      port: 8080
    https_service:
      port: 8443
    smtp_service:
      port: 587
      admin_email: [email protected]

Requirements

  • ruby 1.9.3 or higher

needs_resources's People

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.