Sha256: 557e0a4e35d1ab361cde0bb5ad629c94fddf9a192a0146d7962c0f50cd416c46

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

module Prospectus
  ##
  # Define item objects that defined expected vs actual state
  class Item
    attr_reader :list

    def initialize(params = {})
      @options = params
      @list = List.new(params)
    end

    def name
      @name ||= File.basename Dir.pwd
    end

    def expected
      @expected || fail("No expected state was loaded for #{name}")
    end

    def actual
      @actual || fail("No actual state was loaded for #{name}")
    end
  end

  ##
  # DSL for wrapping eval of item files
  class ItemDSL
    def initialize(item, params)
      @item = item
      @options = params
    end

    def name(value)
      @item.instance_variable_set(:@name, value)
    end

    def expected(&block)
      state(:@expected, &block)
    end

    def actual(&block)
      state(:@actual, &block)
    end

    def deps(&block)
      dsl = ListDSL.new(@item.list, @options)
      dsl.instance_eval(&block)
      @item.list.items.each do |dep|
        dep.instance_variable_set(:@name, "#{@item.name}::#{dep.name}")
      end
    end

    private

    def state(name, &block)
      state = State.new(@options)
      dsl = StateDSL.new(state, @options)
      dsl.instance_eval(&block)
      dsl.load!
      @item.instance_variable_set(name, state.value)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
prospectus-0.0.5 lib/prospectus/item.rb
prospectus-0.0.4 lib/prospectus/item.rb
prospectus-0.0.3 lib/prospectus/item.rb
prospectus-0.0.2 lib/prospectus/item.rb