Sha256: 92582106e5efb34038d7cd6f54b882eeeae5861cc2150a79da5f681400f6e22b

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module AuditTracker
  # AuditTracker DSL modules
  module DSL
    def self.build(&block)
      Setup.module_eval(&block)
    end

    # AuditTracker::DSL::Setup is the DSL cotext of the block in AuditTracker.setup
    #
    module Setup
    module_function

      def tracker(key, &block)
        ::AuditTracker.trackers[key] = Tracking.build(&block)
      end
    end

    # AuditTracker::DSL::Setup is the DSL cotext of the block in `DSL::Setup.tracker`
    #
    class Tracking
      def self.build(&block)
        tracker = new
        tracker.instance_eval(&block)
        tracker.tracker
      end

      def tracker
        ::AuditTracker::Tracker.new(on: @on, value: @value)
      end

      def on(event, relation, **options)
        @on ||= []
        @on << [event, relation, options]
      end

      def update(relation, **options)
        on(:save, relation, **options)
      end

      def create(relation, **options)
        on(:create, relation, **options)
      end

      def value(&block)
        @value = block
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
audit_tracker-0.1.0 lib/audit_tracker/dsl.rb