module ActsAsSpan::ClassMethods

Public Instance Methods

acts_as_span(*args) click to toggle source
# File lib/acts_as_span.rb, line 36
def acts_as_span(*args)
  self.send(:extend, ActsAsSpan::ExtendedClassMethods)
  self.send(:include, ActsAsSpan::IncludedInstanceMethods)

  # TODO: There's some refactoring that could be done here using keyword args (or the more standard old hash arg pattern)
  options = OpenStruct.new(args.last.is_a?(Hash) ? ActsAsSpan.options.merge(args.pop) : ActsAsSpan.options)

  unsupported_options =
    options.to_h.keys.reject { |opt| OPTIONS.include? opt }
  unless unsupported_options.empty?
    raise ArgumentError,
      'Unsupported option(s): ' <<
      unsupported_options.map { |o| "'#{o}'" }.join(', ')
  end

  acts_as_span_definitions[options.name] = options

  # TODO add tests that check delegation of all methos in span
  delegate :span_status,
           :span_status_on,
           :current?,
           :current_on?,
           :future?,
           :future_on?,
           :expired?,
           :expired_on?,
           :past?,
           :past_on?, to: :span

  delegate :acts_as_span_definitions, to: :class

  # TODO idem above
  class << self
    delegate :current,
             :current_on,
             :future,
             :future_on,
             :expired,
             :expired_on,
             :past_on,
             :past,
             :current_or_future_on,
             :current_or_future, to: :span
  end

  validate :validate_spans
end
acts_as_span_definitions() click to toggle source
# File lib/acts_as_span.rb, line 84
def acts_as_span_definitions
  @_acts_as_span_definitions ||= {}
end