Code Monkey home page Code Monkey logo

sisal's People

Contributors

wicz avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sisal's Issues

README needs updating

Two minor issues:

  1. I'm pretty sure this is a typo. It's syntactically possible (but unidiomatic), and it's not how your code seems to be implemented.
Sisal::Providers::TropoProvider(token: '123')
  1. All your examples should use the syntactic sugar you just integrated, to hide the *Provider implementation details from the user. You can decide whether or not to expose that as a developer API later but I'd consider it a private detail for now.

Configuration issues

Your Sisal module feels very overengineered :-/

I suggest moving all of its contents to a Sisal::Configuration object and having it look like this:

module Sisal
  class Configuration
    def self.default
      config = new

      config.provider(:twilio,     :class => TwilioProvider)
      config.provider(:tropo,      :class => TropoProvider)
      config.provider(:clickatell, :class => ClickatellProvider)

      config
    end

    def initialize
      self.providers = Hash.new { |h,k| h[k] = {} }
    end

    def provider(name, params)
      providers[name].update(params)
    end

    # override the provide rather than merging
    def provider!(name, params)
      providers[name] = params
    end

    def default_provider
      providers[default_provider]
    end

    attr_accessor :providers
    attr_writer :default_provider
  end
end

Then in lib/sisal.rb

module Sisal
  class << self
    def configuration
      self.configuration ||= Configuration.default
    end

    attr_writer :configuration
  end
end

Usage for most users:

config = Sisal.configuration

config.default_provider = :tropo

config.provider(:tropo, token: '123')
config.provider(:clickatell, api_id: '123', user: 'user', password: 'pass')
config.provider(:twilio, account_id: '123', token: '123', from: '552500')

For advanced users:

config = Sisal.configuration

config.default_provider = :something

# add a new kind of provider
config.provider(:something, :class => SomethingProvider, ...)

# edit an existing provider
config.provider(:twilio, :token => "...")

# replace an existing provider's params
config.provider!(:tropo, :class => MyCustomTropoProvider, ...)

For crazy users:

Sisal.configuration = ZomgObject
# ... you're on your own, buddy.

But this still avoids weird instance_eval hacks, and dynamic class lookups, name based dependencies, and awkward reset logic on a singleton object. Each time you (as the maintainer) add a new provider you need to update only one line of code in the Configuration.default method, a small price to pay for arbitrary naming and explicit mapping.

Add a license

Your code will need a license before you release, and ideally I'd like to see it added before the end of the course. See the discussion at the bottom of this ticket for thoughts on that.

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.