Sha256: 478832964db3bdef0e678eea69a011feac8d6053f142b7912dcde336b3aad591

Contents?: true

Size: 968 Bytes

Versions: 30

Compression:

Stored size: 968 Bytes

Contents

module Refine::Blueprints
  class Blueprint
    # DSL-based model for building filter blueprints
    attr_reader :blueprint

    def initialize
      @blueprint = []
      @depth = 0
    end

    def group(&block)
      @depth = @depth += 1
      instance_eval(&block)
      @depth = @depth -= 1
      self
    end

    def criterion(condition_id, input)
      if !@blueprint.blank? && @blueprint.last[:type] == "criterion"
        raise "Conjunction missing"
      end

      add({
        depth: @depth,
        type: "criterion",
        condition_id: condition_id,
        input: input,
      })
      self
    end

    def conjunction(word)
      add({
        depth: @depth,
        type: "conjunction",
        word: word
      })
    end

    def and
      conjunction("and")
      self
    end

    def or
      conjunction("or")
      self
    end

    def add(item)
      @blueprint.append(item)
    end

    def to_array
      @blueprint
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
refine-rails-2.12.0 app/models/refine/blueprints/blueprint.rb
refine-rails-2.11.12 app/models/refine/blueprints/blueprint.rb
refine-rails-2.11.11 app/models/refine/blueprints/blueprint.rb
refine-rails-2.11.10 app/models/refine/blueprints/blueprint.rb
refine-rails-2.11.9 app/models/refine/blueprints/blueprint.rb
refine-rails-2.11.8 app/models/refine/blueprints/blueprint.rb
refine-rails-2.11.6 app/models/refine/blueprints/blueprint.rb
refine-rails-2.11.5 app/models/refine/blueprints/blueprint.rb
refine-rails-2.11.4 app/models/refine/blueprints/blueprint.rb
refine-rails-2.11.3 app/models/refine/blueprints/blueprint.rb
refine-rails-2.11.2 app/models/refine/blueprints/blueprint.rb
refine-rails-2.11.1 app/models/refine/blueprints/blueprint.rb
refine-rails-2.11.0 app/models/refine/blueprints/blueprint.rb
refine-rails-2.10.1 app/models/refine/blueprints/blueprint.rb
refine-rails-2.10.0 app/models/refine/blueprints/blueprint.rb
refine-rails-2.9.14 app/models/refine/blueprints/blueprint.rb
refine-rails-2.9.13 app/models/refine/blueprints/blueprint.rb
refine-rails-2.9.12 app/models/refine/blueprints/blueprint.rb
refine-rails-2.9.11 app/models/refine/blueprints/blueprint.rb
refine-rails-2.9.10 app/models/refine/blueprints/blueprint.rb