Sha256: 2fe1c2b1914bf96dd6865f52bdff51af27c84ca6855d27a8b2774421883964d2

Contents?: true

Size: 845 Bytes

Versions: 1

Compression:

Stored size: 845 Bytes

Contents

module BlueprintsBoy::Helper
  def set(name, value)
    instance_eval <<-RUBY, __FILE__, __LINE__ + 1
      def self.#{name}
        @_blueprint_data[:#{name}]
      end
    RUBY
    @_blueprint_data[name] = value
  end

  def autoset(name, value)
    if respond_to?(name)
      @_blueprint_data[name] ||= value
    else
      set(name, value)
    end
    value
  end

  def blueprint_data(name = nil)
    if name
      @_blueprint_data[name]
    else
      @_blueprint_data
    end
  end

  def build(*names)
    build_with nil, *names
  end

  def build!(*names)
    build_with :create, *names
  end

  def build_new(*names)
    build_with :new, *names
  end

  def build_attributes(*names)
    build_with :attributes, *names
  end

  def build_with(strategy, *names)
    BlueprintsBoy.manager.build(self, names, strategy: strategy)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blueprints_boy-1.0.0 lib/blueprints_boy/helper.rb