lib/hyper-operation/transport/policy.rb in hyper-operation-1.0.alpha1.2 vs lib/hyper-operation/transport/policy.rb in hyper-operation-1.0.alpha1.3

- old
+ new

@@ -19,11 +19,11 @@ attr_reader :regulated_klass EXPOSED_METHODS = [ :regulate_class_connection, :always_allow_connection, :regulate_instance_connections, :regulate_all_broadcasts, :regulate_broadcast, - :dispatch_to, :regulate_dispatches_from, :always_dispatch_from, + :regulate_dispatches_from, :always_dispatch_from, :allow_change, :allow_create, :allow_read, :allow_update, :allow_destroy ] def regulate_class_connection(*args, &regulation) regulate(ClassConnectionRegulation, :class_connection, args, &regulation) @@ -56,25 +56,10 @@ def always_dispatch_from(*args, &regulation) regulate_dispatches_from(*args) { true } end - def dispatch_to(*args, &regulation) - actual_klass = if regulated_klass.is_a?(Class) - regulated_klass - else - begin - regulated_klass.constantize - rescue NameError - nil - end - end - raise 'you can only dispatch_to Operation classes' unless actual_klass.respond_to? :dispatch_to - actual_klass.dispatch_to(actual_klass) - actual_klass.dispatch_to(*args, &regulation) - end - CHANGE_POLICIES = [:create, :update, :destroy] def self.allow_policy(policy, method) define_method "allow_#{policy}" do |*args, &regulation| process_args(policy, [], args, regulation) do |model| @@ -377,12 +362,11 @@ def obj @obj end def self.raise_operation_access_violation(message, details) - Hyperstack.on_error(Hyperstack::AccessViolation, message, details) - raise Hyperstack::AccessViolation + raise Hyperstack::AccessViolation.new(message, details) end def self.regulate_connection(acting_user, channel_string) channel = channel_string.split("-") if channel.length > 1 @@ -404,19 +388,20 @@ ChannelBroadcastRegulation.broadcast(internal_policy) InstanceBroadcastRegulation.broadcast(model, internal_policy) internal_policy.broadcast &block end - def initialize(obj, attribute_names, available_channels) + def initialize(obj, attribute_names, available_channels = :all) @obj = obj - attribute_names = attribute_names.map(&:to_sym).to_set + @attribute_names = attribute_names.map(&:to_sym).to_set @unassigned_send_sets = [] - @channel_sets = Hash.new { |hash, key| hash[key] = attribute_names } + @channel_sets = Hash.new { |hash, key| hash[key] = @attribute_names } @available_channels = available_channels end def channel_available?(channel) - channel && @available_channels.include?(channel_to_string(channel)) + return false unless channel + @available_channels == :all || @available_channels.include?(channel_to_string(channel)) end def id @id ||= "#{self.object_id}-#{Time.now.to_f}" end