Skip to content

Instantly share code, notes, and snippets.

@mrkplt
Last active August 29, 2015 14:12
Show Gist options
  • Save mrkplt/35d6d1df5b0105fdd577 to your computer and use it in GitHub Desktop.
Save mrkplt/35d6d1df5b0105fdd577 to your computer and use it in GitHub Desktop.

Revisions

  1. mrkplt revised this gist Jan 6, 2015. 2 changed files with 6 additions and 6 deletions.
    2 changes: 1 addition & 1 deletion business_object.rb
    Original file line number Diff line number Diff line change
    @@ -32,4 +32,4 @@ def failure
    raise LambdaError, 'A lambda for failure must be provided'
    end
    end
    end
    end
    10 changes: 5 additions & 5 deletions naive_implementation.rb
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    class SaveObjekt < BusinessObject
    def intialize(some_objekt, lambda_hash)
    @objekt = some_objekt
    super(lambda_hash)
    def initialize(objekt, lambdas)
    @objekt = objekt
    super(lambdas)
    end

    def perform
    @objekt.action ? success : failure
    !@objekt.nil? ? success : failure
    end
    end
    end
  2. mrkplt revised this gist Jan 6, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion naive_implementation.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    def SaveObjekt < BusinessObject
    class SaveObjekt < BusinessObject
    def intialize(some_objekt, lambda_hash)
    @objekt = some_objekt
    super(lambda_hash)
  3. mrkplt revised this gist Jan 5, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions business_object.rb
    Original file line number Diff line number Diff line change
    @@ -12,9 +12,9 @@ def perform

    private

    def post_init(args)
    @success = args[:success]
    @failure = args[:failure]
    def post_init(lambda_hash)
    @success = lambda_hash[:success]
    @failure = lambda_hash[:failure]
    end

    def success
  4. mrkplt revised this gist Jan 5, 2015. 1 changed file with 4 additions and 6 deletions.
    10 changes: 4 additions & 6 deletions business_object.rb
    Original file line number Diff line number Diff line change
    @@ -12,24 +12,22 @@ def perform

    private

    attr_reader :success_lambda, :failure_lambda

    def post_init(args)
    @success_lambda = args[:success]
    @failure_lambda = args[:failure]
    @success = args[:success]
    @failure = args[:failure]
    end

    def success
    begin
    success_lambda.call
    @success.call
    rescue NoMethodError
    raise LambdaError, 'A lambda for success must be provided'
    end
    end

    def failure
    begin
    failure_lambda.call
    @failure.call
    rescue NoMethodError
    raise LambdaError, 'A lambda for failure must be provided'
    end
  5. mrkplt revised this gist Jan 5, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions naive_implementation.rb
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    def SaveObjekt < BusinessObject
    def intialize(some_objekt, *args)
    def intialize(some_objekt, lambda_hash)
    @objekt = some_objekt
    super(*args)
    super(lambda_hash)
    end

    def perform
  6. mrkplt revised this gist Jan 5, 2015. 1 changed file with 10 additions and 4 deletions.
    14 changes: 10 additions & 4 deletions business_object.rb
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,17 @@
    class BusinessObject
    class LambdaError < StandardError; end;
    def initialize(*args)
    post_init(args)
    class NotImplementedError < StandardError; end;

    def initialize(lambda_hash = {})
    post_init(lambda_hash)
    end

    def perform
    raise NotImplementedError, 'must implement perform.'
    end

    private

    attr_reader :success_lambda, :failure_lambda

    def post_init(args)
    @@ -20,7 +26,7 @@ def success
    raise LambdaError, 'A lambda for success must be provided'
    end
    end

    def failure
    begin
    failure_lambda.call
  7. mrkplt revised this gist Jan 5, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion business_object.rb
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ def initialize(*args)

    attr_reader :success_lambda, :failure_lambda

    def post_init(*args)
    def post_init(args)
    @success_lambda = args[:success]
    @failure_lambda = args[:failure]
    end
  8. mrkplt revised this gist Jan 5, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion business_object.rb
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    class BusinessObject
    class LambdaError < StandardError; end;
    def initialize(*args)
    post_init(*args)
    post_init(args)
    end

    private
  9. mrkplt revised this gist Jan 5, 2015. 1 changed file with 11 additions and 2 deletions.
    13 changes: 11 additions & 2 deletions business_object.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    class BusinessObject
    class LambdaError < StandardError; end;
    def initialize(*args)
    post_init(*args)
    end
    @@ -13,10 +14,18 @@ def post_init(*args)
    end

    def success
    success_lambda.call
    begin
    success_lambda.call
    rescue NoMethodError
    raise LambdaError, 'A lambda for success must be provided'
    end
    end

    def failure
    failure_lambda.call
    begin
    failure_lambda.call
    rescue NoMethodError
    raise LambdaError, 'A lambda for failure must be provided'
    end
    end
    end
  10. mrkplt revised this gist Jan 5, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion business_object.rb
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    class BusinessObject
    def initialize(*args)
    post_init(*args)
    end
    end

    private

  11. mrkplt revised this gist Jan 5, 2015. 2 changed files with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.rb → business_object.rb
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    class BusinessObject
    def initialize(*args)
    def initialize(*args)
    post_init(*args)
    end

    File renamed without changes.
  12. mrkplt revised this gist Jan 5, 2015. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions gistfile2.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    def SaveObjekt < BusinessObject
    def intialize(some_objekt, *args)
    @objekt = some_objekt
    super(*args)
    end

    def perform
    @objekt.action ? success : failure
    end
    end
  13. mrkplt created this gist Jan 5, 2015.
    22 changes: 22 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    class BusinessObject
    def initialize(*args)
    post_init(*args)
    end

    private

    attr_reader :success_lambda, :failure_lambda

    def post_init(*args)
    @success_lambda = args[:success]
    @failure_lambda = args[:failure]
    end

    def success
    success_lambda.call
    end

    def failure
    failure_lambda.call
    end
    end