sequelinha 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +11 -0
- data/VERSION +1 -0
- data/lib/sequelinha.rb +59 -0
- data/lib/sequelinha/adapters/postgres.rb +14 -0
- data/lib/sequelinha/adapters/sqlite.rb +22 -0
- data/lib/sequelinha/config.rb +27 -0
- data/lib/sequelinha/connection_url.rb +47 -0
- data/lib/sequelinha/connection_url_factory.rb +14 -0
- data/lib/sequelinha/tasks.rb +19 -0
- data/lib/tasks/migrations.rb +7 -0
- data/sequelinha.gemspec +20 -0
- data/spec/sequelinha_spec.rb +3 -0
- data/spec/spec_helper.rb +0 -0
- metadata +76 -0
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1,11 @@ | |
| 1 | 
            +
            $LOAD_PATH.unshift File.expand_path('../lib/', __FILE__)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            task :default => [:specs]
         | 
| 4 | 
            +
            task :specs => [:"specs:all"]
         | 
| 5 | 
            +
            namespace :specs do
         | 
| 6 | 
            +
              require 'rspec/core/rake_task'
         | 
| 7 | 
            +
              RSpec::Core::RakeTask.new "all" do |t|
         | 
| 8 | 
            +
                t.pattern = "spec/**/*_spec.rb"
         | 
| 9 | 
            +
                t.rspec_opts = ['--color', '--format documentation', '--require spec_helper']
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
            end
         | 
    
        data/VERSION
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            0.0.1
         | 
    
        data/lib/sequelinha.rb
    ADDED
    
    | @@ -0,0 +1,59 @@ | |
| 1 | 
            +
            require "sequel"
         | 
| 2 | 
            +
            require "sequelinha/config"
         | 
| 3 | 
            +
            require "sequelinha/connection_url"
         | 
| 4 | 
            +
            require "sequelinha/connection_url_factory"
         | 
| 5 | 
            +
            require "sequelinha/adapters/sqlite"
         | 
| 6 | 
            +
            require "sequelinha/adapters/postgres"
         | 
| 7 | 
            +
            require "sequelinha/tasks"
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            module Sequelinha
         | 
| 10 | 
            +
              def self.implementations
         | 
| 11 | 
            +
                @implementations ||= []
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              def self.register(klass, &block)
         | 
| 15 | 
            +
                self.implementations << klass
         | 
| 16 | 
            +
                self
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              def self.config
         | 
| 20 | 
            +
                @config ||= Config.new
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              def self.configure
         | 
| 24 | 
            +
                yield(self.config) if block_given?
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                self.config.database_yml ||= "#{self.config.application_root}/config/database.yml"
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                # prepares interestie to run like a boss on heroku
         | 
| 29 | 
            +
                ENV["DATABASE_URL"] ||= Sequelinha.database_url
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                self.config
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
              def self.database_url
         | 
| 35 | 
            +
                env = ENV["RACK_ENV"] || "development"
         | 
| 36 | 
            +
                config = self.database_config[env]
         | 
| 37 | 
            +
                connection_url = ConnectionURLFactory.url_for config
         | 
| 38 | 
            +
                connection_url
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              def self.establish
         | 
| 42 | 
            +
                ENV["DATABASE_URL"] = Sequelinha.database_url
         | 
| 43 | 
            +
                Sequel.connect(ENV["DATABASE_URL"])
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
              private
         | 
| 47 | 
            +
              def self.database_config
         | 
| 48 | 
            +
                @database_yml_file ||= proc {
         | 
| 49 | 
            +
                  require "yaml"
         | 
| 50 | 
            +
                  require "erb"
         | 
| 51 | 
            +
                  database_yml = config["database_yml"]
         | 
| 52 | 
            +
                  File.read(database_yml)
         | 
| 53 | 
            +
                }.call
         | 
| 54 | 
            +
                YAML.load(ERB.new(@database_yml_file).result(binding))
         | 
| 55 | 
            +
              end
         | 
| 56 | 
            +
            end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
            Sequelinha.register Sequelinha::Adapters::Postgres
         | 
| 59 | 
            +
            Sequelinha.register Sequelinha::Adapters::Sqlite
         | 
| @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            module Sequelinha
         | 
| 2 | 
            +
              module Adapters
         | 
| 3 | 
            +
                class Sqlite < ConnectionURL
         | 
| 4 | 
            +
                  def host
         | 
| 5 | 
            +
                    nil
         | 
| 6 | 
            +
                  end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  def adapter
         | 
| 9 | 
            +
                    super == "sqlite3" ? "sqlite" : super
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  def database
         | 
| 13 | 
            +
                    File.join(self.application_root, super)
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  def self.=~(adapter)
         | 
| 17 | 
            +
                    adapter =~ /sqlite/
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
| 22 | 
            +
             | 
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            module Sequelinha
         | 
| 2 | 
            +
              class Config
         | 
| 3 | 
            +
                def initialize(data={})
         | 
| 4 | 
            +
                  @data = data
         | 
| 5 | 
            +
                end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def [](key)
         | 
| 8 | 
            +
                  @data[key.to_sym]
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def []=(key, value)
         | 
| 12 | 
            +
                  if value.class == Hash
         | 
| 13 | 
            +
                    @data[key.to_sym] = Config.new(value)
         | 
| 14 | 
            +
                  else
         | 
| 15 | 
            +
                    @data[key.to_sym] = value
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def method_missing(sym, *args)
         | 
| 20 | 
            +
                  if sym.to_s =~ /(.+)=$/
         | 
| 21 | 
            +
                    self[$1] = args.first
         | 
| 22 | 
            +
                  else
         | 
| 23 | 
            +
                    self[sym]
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
| @@ -0,0 +1,47 @@ | |
| 1 | 
            +
            module Sequelinha
         | 
| 2 | 
            +
              class ConnectionURL
         | 
| 3 | 
            +
                def initialize(config)
         | 
| 4 | 
            +
                  @config = config
         | 
| 5 | 
            +
                end
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                attr_accessor :config
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                class << self
         | 
| 10 | 
            +
                  def =~(adapter)
         | 
| 11 | 
            +
                    nil
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def application_root
         | 
| 16 | 
            +
                  @config["application_root"]
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def username
         | 
| 20 | 
            +
                  @config["username"]
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                def password
         | 
| 24 | 
            +
                  @config["password"]
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                def adapter
         | 
| 28 | 
            +
                  @config["adapter"]
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                def database
         | 
| 32 | 
            +
                  @config["database"]
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                def host
         | 
| 36 | 
            +
                  @config["host"] || "localhost"
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                def string
         | 
| 40 | 
            +
                  final_url =  "#{self.adapter}://"
         | 
| 41 | 
            +
                  final_url << "#{self.username}:" if self.username
         | 
| 42 | 
            +
                  final_url << "#{self.password}" if self.password
         | 
| 43 | 
            +
                  final_url << "@#{self.host}" if self.host
         | 
| 44 | 
            +
                  final_url << "/#{self.database}" if self.database
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
            end
         | 
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            module Sequelinha
         | 
| 2 | 
            +
              class ConnectionURLFactory
         | 
| 3 | 
            +
                def self.url_for config
         | 
| 4 | 
            +
                  config["application_root"] = Sequelinha.config.application_root
         | 
| 5 | 
            +
                  implementation(config).string
         | 
| 6 | 
            +
                end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                private
         | 
| 9 | 
            +
                def self.implementation config
         | 
| 10 | 
            +
                  implementation = Sequelinha.implementations.find { |klass| klass =~ config["adapter"] }
         | 
| 11 | 
            +
                  implementation.new(config)
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
            end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            module Sequelinha
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              class Tasks
         | 
| 4 | 
            +
                class << self
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  def load(application_root = Sequelinha.config.application_root)
         | 
| 7 | 
            +
                    Sequelinha.config.application_root ||= aplication_root
         | 
| 8 | 
            +
                    require migrations
         | 
| 9 | 
            +
                  end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  def migrations(application_root = Sequelinha.config.application_root)
         | 
| 12 | 
            +
                    tasks_dir = File.expand_path("../../tasks/", __FILE__)
         | 
| 13 | 
            +
                    File.join(tasks_dir, "migrations")
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                end# class methods
         | 
| 17 | 
            +
              end# Tasks
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            end
         | 
    
        data/sequelinha.gemspec
    ADDED
    
    | @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            Gem::Specification.new do |s|
         | 
| 3 | 
            +
              s.name        = "sequelinha"
         | 
| 4 | 
            +
              s.version     = File.read(File.expand_path("../VERSION",__FILE__)).strip
         | 
| 5 | 
            +
              s.platform    = Gem::Platform::RUBY
         | 
| 6 | 
            +
              s.authors     = ["Ricardo Valeriano"]
         | 
| 7 | 
            +
              s.email       = ["ricardo.valeriano@gmail.com"]
         | 
| 8 | 
            +
              s.homepage    = "http://github.com/ricardovaleriano/sequelinha"
         | 
| 9 | 
            +
              s.summary     = "Easy environment based configurations for Sequel"
         | 
| 10 | 
            +
              s.description = <<SUM
         | 
| 11 | 
            +
              A tool to facilitates the use of rails like config/database.yml and db/migrate/ directories.
         | 
| 12 | 
            +
              Also give you a way to establish a connection based on the current environment.
         | 
| 13 | 
            +
            SUM
         | 
| 14 | 
            +
              s.required_rubygems_version = ">= 0"
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              s.require_path = 'lib'
         | 
| 17 | 
            +
              s.files        = `git ls-files | sed 's/examples.*//'`.split("\n").reject{|f| f == ""}
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              s.add_dependency 'sequel', '~>3.37.0'
         | 
| 20 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    | 
            File without changes
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,76 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: sequelinha
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.1
         | 
| 5 | 
            +
              prerelease: 
         | 
| 6 | 
            +
            platform: ruby
         | 
| 7 | 
            +
            authors:
         | 
| 8 | 
            +
            - Ricardo Valeriano
         | 
| 9 | 
            +
            autorequire: 
         | 
| 10 | 
            +
            bindir: bin
         | 
| 11 | 
            +
            cert_chain: []
         | 
| 12 | 
            +
            date: 2012-07-13 00:00:00.000000000 Z
         | 
| 13 | 
            +
            dependencies:
         | 
| 14 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 15 | 
            +
              name: sequel
         | 
| 16 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 | 
            +
                none: false
         | 
| 18 | 
            +
                requirements:
         | 
| 19 | 
            +
                - - ~>
         | 
| 20 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 21 | 
            +
                    version: 3.37.0
         | 
| 22 | 
            +
              type: :runtime
         | 
| 23 | 
            +
              prerelease: false
         | 
| 24 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 25 | 
            +
                none: false
         | 
| 26 | 
            +
                requirements:
         | 
| 27 | 
            +
                - - ~>
         | 
| 28 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 29 | 
            +
                    version: 3.37.0
         | 
| 30 | 
            +
            description: ! "  A tool to facilitates the use of rails like config/database.yml
         | 
| 31 | 
            +
              and db/migrate/ directories.\n  Also give you a way to establish a connection based
         | 
| 32 | 
            +
              on the current environment.\n"
         | 
| 33 | 
            +
            email:
         | 
| 34 | 
            +
            - ricardo.valeriano@gmail.com
         | 
| 35 | 
            +
            executables: []
         | 
| 36 | 
            +
            extensions: []
         | 
| 37 | 
            +
            extra_rdoc_files: []
         | 
| 38 | 
            +
            files:
         | 
| 39 | 
            +
            - Rakefile
         | 
| 40 | 
            +
            - VERSION
         | 
| 41 | 
            +
            - lib/sequelinha.rb
         | 
| 42 | 
            +
            - lib/sequelinha/adapters/postgres.rb
         | 
| 43 | 
            +
            - lib/sequelinha/adapters/sqlite.rb
         | 
| 44 | 
            +
            - lib/sequelinha/config.rb
         | 
| 45 | 
            +
            - lib/sequelinha/connection_url.rb
         | 
| 46 | 
            +
            - lib/sequelinha/connection_url_factory.rb
         | 
| 47 | 
            +
            - lib/sequelinha/tasks.rb
         | 
| 48 | 
            +
            - lib/tasks/migrations.rb
         | 
| 49 | 
            +
            - sequelinha.gemspec
         | 
| 50 | 
            +
            - spec/sequelinha_spec.rb
         | 
| 51 | 
            +
            - spec/spec_helper.rb
         | 
| 52 | 
            +
            homepage: http://github.com/ricardovaleriano/sequelinha
         | 
| 53 | 
            +
            licenses: []
         | 
| 54 | 
            +
            post_install_message: 
         | 
| 55 | 
            +
            rdoc_options: []
         | 
| 56 | 
            +
            require_paths:
         | 
| 57 | 
            +
            - lib
         | 
| 58 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 59 | 
            +
              none: false
         | 
| 60 | 
            +
              requirements:
         | 
| 61 | 
            +
              - - ! '>='
         | 
| 62 | 
            +
                - !ruby/object:Gem::Version
         | 
| 63 | 
            +
                  version: '0'
         | 
| 64 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
              none: false
         | 
| 66 | 
            +
              requirements:
         | 
| 67 | 
            +
              - - ! '>='
         | 
| 68 | 
            +
                - !ruby/object:Gem::Version
         | 
| 69 | 
            +
                  version: '0'
         | 
| 70 | 
            +
            requirements: []
         | 
| 71 | 
            +
            rubyforge_project: 
         | 
| 72 | 
            +
            rubygems_version: 1.8.22
         | 
| 73 | 
            +
            signing_key: 
         | 
| 74 | 
            +
            specification_version: 3
         | 
| 75 | 
            +
            summary: Easy environment based configurations for Sequel
         | 
| 76 | 
            +
            test_files: []
         |