Sha256: 3eabf44fa04b4c4d6c2b4c5e8e112cac4b504e1e6888821a77463da73a66e26d

Contents?: true

Size: 991 Bytes

Versions: 3

Compression:

Stored size: 991 Bytes

Contents

Dir[File.join(File.dirname(__FILE__), "adalog", "*.rb")].each do |rb_file|
  require rb_file
end

module Adalog

  def self.configuration
    @configuration || ((configure! { :defaults }) && @configuration)
  end


  def self.configure
    config = Adalog::Configuration.new
    yield(config)
    config.validate!
    config.freeze
    @configuration = config
    post_configuration(@configuration)
    :ok
  end


  def self.post_configuration(config)
    if config.singleton
      self.extend(RepoConvenienceMethods)
    end
    if config.html_erb
      Tilt.register(Tilt::ERBTemplate, 'html.erb')
    end
  end


  module RepoConvenienceMethods

    def repo
      configuration.repo
    end

    def all
      configuration.repo.all
    end


    def clear!
      configuration.repo.clear!
    end


    def fetch(**options)
      configuration.repo.fetch(**options)
    end


    def insert(entry = nil, **options)
      configuration.repo.insert(entry, **options)
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
adalog-0.5.0 lib/adalog.rb
adalog-0.4.1 lib/adalog.rb
adalog-0.4.0 lib/adalog.rb