Sha256: 99619432ba1c54eb8653a87efc123e3a6d0291f07c6daca45749a7205d4528e0

Contents?: true

Size: 1.04 KB

Versions: 31

Compression:

Stored size: 1.04 KB

Contents

module Startback
  module Support
    class World
      include DataObject

      attr_accessor :_factory
      protected :_factory=

      def factory(who, &block)
        dup.tap do |x|
          x._factory = (self._factory || {}).merge(who => block)
        end
      end

      attr_accessor :_scope
      protected :_scope=

      def with_scope(scope)
        dup.tap do |x|
          x._scope = scope
        end
      end

      def with(hash)
        dup.tap do |x|
          x._data = to_data.merge(hash)
        end
      end

    private

      def _data_allow_camelize
        false
      end

      def _data_allow_query
        false
      end

      def _data_key_not_found(key)
        raise Startback::Error, "Scope must be defined" unless s = _scope

        block = (_factory || {})[key]
        if block
          factored = s.instance_exec(&block)
          @_data = @_data.dup.merge(key => factored).freeze
          [key, false]
        else
          nil
        end
      end
    end # class World
  end # module Support
end # module Startback

Version data entries

31 entries across 31 versions & 3 rubygems

Version Path
startback-1.0.3 lib/startback/support/world.rb
startback-1.0.2 lib/startback/support/world.rb
startback-1.0.1 lib/startback/support/world.rb
startback-1.0.0 lib/startback/support/world.rb
startback-0.19.4 lib/startback/support/world.rb
startback-0.19.3 lib/startback/support/world.rb
startback-0.19.1 lib/startback/support/world.rb
startback-0.19.0 lib/startback/support/world.rb
startback-0.18.2 lib/startback/support/world.rb
startback-0.18.1 lib/startback/support/world.rb
startback-0.18.0 lib/startback/support/world.rb
startback-0.17.4 lib/startback/support/world.rb
startback-0.17.3 lib/startback/support/world.rb
startback-0.17.2 lib/startback/support/world.rb
startback-0.17.1 lib/startback/support/world.rb
startback-0.17.0 lib/startback/support/world.rb
startback-0.16.0 lib/startback/support/world.rb
startback-0.15.5 lib/startback/support/world.rb
startback-0.15.4 lib/startback/support/world.rb
startback-0.15.3 lib/startback/support/world.rb