Sha256: 3d514736a0989025bf23f34e27379ffb91666e75d57ed10cc3992137d897b73b

Contents?: true

Size: 1.65 KB

Versions: 10

Compression:

Stored size: 1.65 KB

Contents

module Flipper
  class Expression
    module Builder
      def build(object)
        Expression.build(object)
      end

      def add(*expressions)
        group? ? build(name => args + expressions.flatten) : any.add(*expressions)
      end

      def remove(*expressions)
        group? ? build(name => args - expressions.flatten) : any.remove(*expressions)
      end

      def any
        any? ? self : build({ Any: [self] })
      end

      def all
        all? ? self : build({ All: [self] })
      end

      def equal(object)
        build({ Equal: [self, object] })
      end
      alias eq equal

      def not_equal(object)
        build({ NotEqual: [self, object] })
      end
      alias neq not_equal

      def greater_than(object)
        build({ GreaterThan: [self, object] })
      end
      alias gt greater_than

      def greater_than_or_equal_to(object)
        build({ GreaterThanOrEqualTo: [self, object] })
      end
      alias gte greater_than_or_equal_to
      alias greater_than_or_equal greater_than_or_equal_to

      def less_than(object)
        build({ LessThan: [self, object] })
      end
      alias lt less_than

      def less_than_or_equal_to(object)
        build({ LessThanOrEqualTo: [self, object] })
      end
      alias lte less_than_or_equal_to
      alias less_than_or_equal less_than_or_equal_to

      def percentage_of_actors(object)
        build({ PercentageOfActors: [self, build(object)] })
      end

      def any?
        is_a?(Expression) && function == Expressions::Any
      end

      def all?
        is_a?(Expression) && function == Expressions::All
      end

      def group?
        any? || all?
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
flipper-1.3.2 lib/flipper/expression/builder.rb
flipper-1.3.1 lib/flipper/expression/builder.rb
flipper-1.3.0 lib/flipper/expression/builder.rb
flipper-1.3.0.pre lib/flipper/expression/builder.rb
flipper-1.2.2 lib/flipper/expression/builder.rb
flipper-1.2.1 lib/flipper/expression/builder.rb
flipper-1.2.0 lib/flipper/expression/builder.rb
flipper-1.1.2 lib/flipper/expression/builder.rb
flipper-1.1.1 lib/flipper/expression/builder.rb
flipper-1.1.0 lib/flipper/expression/builder.rb