module Subledger

additional requires at bottom

additional requires at bottom

Constants

API_VERSION
AWS_CRED_FILE
AWS_PATH
BACKUP_BUCKET
BALANCE_SETTLE_DELAY
COVER
DOMAIN
EARLIEST_TIME

my.safaribooksonline.com/book/programming/regular-expressions/9780596802837/4dot-validation-and-formatting/id2983571 Modified to accept optional punctuation and fractional seconds of 1 to 3 digits

ENV
FORMAT
ISO8601_REGEXP

Thanks to Jan Goyvaerts, Steven Levithan, O'Reilly Media, Inc.

LATEST_TIME
LOG
PROGRESS_FAIL
PROGRESS_INITIAL
PROGRESS_RETRY
RENDERED_REPORTS_BUCKET
RENDERED_REPORT_CATEGORIES_BUCKET
ROOT
ROOT_CONFIG
ROOT_LIB
ROOT_SPEC
SCHEME
SLOW_POST_DELAY
STORE
VERSION

Public Class Methods

log_environment() click to toggle source
# File lib/subledger.rb, line 230
def self.log_environment
  LOG.info "SUBLEDGER_STORE: #{STORE}"
  LOG.info "SUBLEDGER_ENV:   #{ENV}"
end
new(args = { }) click to toggle source
# File lib/subledger.rb, line 129
def self.new args = { }
  args = args.dup

  # auth args

  identity    = args[:identity]
  identity_id = args[:identity_id]

  if identity.nil? and not identity_id.nil?
    args.merge! :identity => Domain::Identity.
                               new( :id => identity_id )

    args.delete :identity_id
  end

  key    = args[:key]
  key_id = args[:key_id]

  if key.nil? and not key_id.nil?
    args.merge! :auth_key => Domain::Key.
                               new( :id       => key_id,
                                    :identity => args[:identity],
                                    :secret   => args[:secret] )

    args.delete :key_id
    args.delete :secret
  end

  # instance args

  org    = args[:org]
  org_id = args[:org_id]

  if org.nil? and not org_id.nil?
    args.merge! :org => Domain::Org.
                          new( :id => org_id )

    args.delete :org_id
  end

  book    = args[:book]
  book_id = args[:book_id]

  if book.nil? and not book_id.nil?
    args.merge! :book => Domain::Book.
                           new( :id  => book_id,
                                :org => args[:org] )

    args.delete :book_id
  end

  args.merge! :store => store( args )

  Interface::Client.new args
end
parse_time(parameter_name, time_string) click to toggle source
# File lib/subledger.rb, line 208
def self.parse_time parameter_name, time_string
  if time_string.nil?
    raise DateError, "#{parameter_name} is required"
  end

  unless time_string.match ISO8601_REGEXP
    raise DateError, "#{parameter_name} must be ISO 8601 datetime with timezone, optional punctuation, optional fractional seconds (1-3 digits)"
  end

  time = begin
           Time.parse( time_string ).utc
         rescue ArgumentError => e
           raise DateError, "#{parameter_name}: not a parsable time"
         end

  unless time >= EARLIEST_TIME and time <= LATEST_TIME
    raise DateError, "#{parameter_name} must be between #{EARLIEST_TIME.iso8601(3)} and #{LATEST_TIME.iso8601(3)} inclusive"
  end

  time
end
store(args = { }) click to toggle source
# File lib/subledger.rb, line 185
def self.store args = { }
  store_sym = args[:store] || STORE

  begin
    require "subledger/store/#{store_sym}"
  rescue LoadError => e
    raise Error, "Store: #{store_sym}: #{e}"
  end

  Object.const_get(       'Subledger'          ).
           const_get(     'Store'                ).
             const_get(    store_sym.capitalize    ).
               const_get( 'Store'                    ).new args
end