Skip to content

Commit

Permalink
[dm-constraints] added a method to wrap changed method visibility tasks
Browse files Browse the repository at this point in the history
Signed-off-by: Balint Erdi <balint.erdi@gmail.com>
  • Loading branch information
balinterdi authored and Dan Kubb committed Jan 15, 2009
1 parent 7e0dcc4 commit 692cb39
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions dm-constraints/lib/dm-constraints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class Relationship
# initialize is a private method in Relationship
# and private methods can not be "advised" (hooked into)
# in extlib.
public(:initialize)
before :initialize, :add_delete_constraint_option
private(:initialize)
with_changed_method_visibility(:initialize, :private, :public) do
before :initialize, :add_delete_constraint_option
end
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions dm-constraints/lib/dm-constraints/delete_constraint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ def check_delete_constraint_type(cardinality, name, options = {})
raise ArgumentError, ":constraint option must be one of #{delete_constraint_options * ', '}"
end
end

# TODO: that should be moved to a 'util-like' module
def with_changed_method_visibility(method, from_visibility, to_visibility, &block)
send(to_visibility, method)
yield
send(from_visibility, method)
end

end

def add_delete_constraint_option(name, repository_name, child_model, parent_model, options = {})
Expand Down

0 comments on commit 692cb39

Please sign in to comment.