Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Lev 7.0 #46

Closed
wants to merge 77 commits into from
Closed

WIP: Lev 7.0 #46

wants to merge 77 commits into from

Conversation

joemsak
Copy link
Contributor

@joemsak joemsak commented Nov 30, 2015

  • Adds outputs option which must declare all outputs and their sources
class MyRoutine
  lev_routine outputs: { title: :_self,
                         description: { name: DescriptionRoutine, as: :desc }
                         _verbatim: [SubRoutine, :totally_exists, { name: OtherSub, as: :other }] }
end
  • Adds a set function which sets the attributes mentioned in the outputs map
class MyRoutine
  lev_routine outputs: { title: :_self }

  def exec
    set(title: 'Hello, world')
  end
end

result = MyRoutine.call
result.title #=> 'Hello, world'
  • When you use run it sets all mapped attributes automatically
class OtherSub
  lev_routine outputs: { description: :_self }

  def exec
    set(description: 'Wow a description')
  end
end

class SubRoutine
  lev_routine outputs: { title: :_self, description: OtherSub }

  def exec
    set(title: 'Hello world')
    run(:other_sub)
  end
end

class MyRoutine
  lev_routine outputs: { _verbatim: { name: SubRoutine, as: :sub } }

  def exec
    run(:sub)
  end
end

result = MyRoutine.call

result.title #=> 'Hello world'
result.description #=> 'Wow a description'

@Dantemss
Copy link
Member

Dantemss commented Dec 8, 2015

Currently lev's fatal_error won't actually rollback the DB state if the lev routine is called from inside a non-lev transaction. We could potentially either use requires_new: true when creating the transaction (in which case Lev should rollback its own internal state but not the outer transaction) or, if we want to rollback the entire thing, have Lev raise its own class of rollback error and/or maybe monkeypatch ActiveRecord::Transaction to rollback properly when that error is caught.

@Dantemss
Copy link
Member

Dantemss commented Dec 8, 2015

This is because Lev raises ActiveRecord::Rollback, which is caught and silently ignored by nested transactions: http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html#module-ActiveRecord::Transactions::ClassMethods-label-Nested+transactions

@Dantemss
Copy link
Member

OBE

@Dantemss Dantemss closed this Jan 29, 2021
@Dantemss Dantemss deleted the ground-up-exercise branch January 29, 2021 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants