Module: ActsAsSpan::ClassMethods

Defined in:
lib/acts_as_span.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_span(*args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/acts_as_span.rb', line 31

def acts_as_span(*args)
  self.send(:extend, ActsAsSpan::ExtendedClassMethods)
  self.send(:include, ActsAsSpan::IncludedInstanceMethods)

  options = OpenStruct.new(args.last.is_a?(Hash) ? ActsAsSpan.options.merge(args.pop) : ActsAsSpan.options)

  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_definitionsObject



70
71
72
# File 'lib/acts_as_span.rb', line 70

def acts_as_span_definitions
  @_acts_as_span_definitions ||= {}
end