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

- old
+ new

@@ -1,6 +1,6 @@ -module Hyperloop +module Hyperstack class InternalClassPolicy def initialize(regulated_klass) unless regulated_klass.is_a?(Class) @@ -103,25 +103,25 @@ end def get_ar_model(str) if str.is_a?(Class) unless str <= ActiveRecord::Base - Hyperloop::InternalPolicy.raise_operation_access_violation(:non_ar_class, "#{str} is not a subclass of ActiveRecord::Base") + Hyperstack::InternalPolicy.raise_operation_access_violation(:non_ar_class, "#{str} is not a subclass of ActiveRecord::Base") end str else # we used to cache this here, but during eager loading the cache may get partially filled and never updated # so this guard will fail, now performance will be suckish, as this guard, required for security, takes some ms # def self.ar_base_descendants_map_cache # @ar_base_descendants_map_cache ||= ActiveRecord::Base.descendants.map(&:name) # end - # if Rails.env.production? && !Hyperloop::InternalClassPolicy.ar_base_descendants_map_cache.include?(str) + # if Rails.env.production? && !Hyperstack::InternalClassPolicy.ar_base_descendants_map_cache.include?(str) if Rails.application.config.eager_load && !ActiveRecord::Base.descendants.map(&:name).include?(str) # AR::Base.descendants is eager loaded in production -> this guard works. # In development it may be empty or partially filled -> this guard may fail. # Thus guarded here only in production. - Hyperloop::InternalPolicy.raise_operation_access_violation(:non_ar_class, "#{str} is either not defined or is not a subclass of ActiveRecord::Base") + Hyperstack::InternalPolicy.raise_operation_access_violation(:non_ar_class, "#{str} is either not defined or is not a subclass of ActiveRecord::Base") end Object.const_get(str) end end @@ -200,11 +200,11 @@ policy_klass = regulation.binding.receiver rescue raise "Could not determine the class when regulating. This is probably caused by doing something like &:send_all" end wrapped_policy = policy_klass.new(nil, nil) - wrapped_policy.hyperloop_internal_policy_object = policy + wrapped_policy.hyperstack_internal_policy_object = policy wrapped_policy end def allowed_opts [] @@ -351,11 +351,11 @@ module AutoConnect def self.channels(session, acting_user) channels = ClassConnectionRegulation.connections_for(acting_user, true) + InstanceConnectionRegulation.connections_for(acting_user, true) - channels << "Hyperloop::Session-#{session.split('-').last}" if Hyperloop.connect_session && session + channels << "Hyperstack::Session-#{session.split('-').last}" if Hyperstack.connect_session && session channels.uniq.each { |channel| Connection.open(channel, session) } end end class InternalPolicy @@ -377,20 +377,20 @@ def obj @obj end def self.raise_operation_access_violation(message, details) - Hyperloop.on_error(Hyperloop::AccessViolation, message, details) - raise Hyperloop::AccessViolation + Hyperstack.on_error(Hyperstack::AccessViolation, message, details) + raise Hyperstack::AccessViolation end def self.regulate_connection(acting_user, channel_string) channel = channel_string.split("-") if channel.length > 1 id = channel[1..-1].join("-") - unless Hyperloop::InternalClassPolicy.regulated_klasses.include?(channel[0]) - Hyperloop::InternalPolicy.raise_operation_access_violation(:not_a_channel, "#{channel[0]} is not regulated channel class") + unless Hyperstack::InternalClassPolicy.regulated_klasses.include?(channel[0]) + Hyperstack::InternalPolicy.raise_operation_access_violation(:not_a_channel, "#{channel[0]} is not regulated channel class") end object = Object.const_get(channel[0]).find(id) InstanceConnectionRegulation.connect(object, acting_user) else ClassConnectionRegulation.connect(channel[0], acting_user) @@ -521,30 +521,30 @@ end end module ClassPolicyMethods - def hyperloop_internal_policy_object - @hyperloop_internal_policy_object ||= InternalClassPolicy.new(name || self) + def hyperstack_internal_policy_object + @hyperstack_internal_policy_object ||= InternalClassPolicy.new(name || self) end InternalClassPolicy::EXPOSED_METHODS.each do |policy_method| define_method policy_method do |*klasses, &block| - hyperloop_internal_policy_object.send policy_method, *klasses, &block + hyperstack_internal_policy_object.send policy_method, *klasses, &block end unless respond_to? policy_method end end module PolicyMethods def self.included(base) base.class_eval do extend ClassPolicyMethods end end - attr_accessor :hyperloop_internal_policy_object + attr_accessor :hyperstack_internal_policy_object InternalPolicy::EXPOSED_METHODS.each do |method| define_method method do |*args, &block| - hyperloop_internal_policy_object.send method, *args, &block + hyperstack_internal_policy_object.send method, *args, &block end unless respond_to? method end define_method :initialize do |*args| end unless instance_methods(false).include?(:initialize) end @@ -557,37 +557,37 @@ end end end class Module - alias pre_hyperloop_const_set const_set + alias pre_hyperstack_const_set const_set def const_set(name, value) - pre_hyperloop_const_set(name, value).tap do - Hyperloop::PolicyAutoLoader.load(name, value) + pre_hyperstack_const_set(name, value).tap do + Hyperstack::PolicyAutoLoader.load(name, value) end end end class Class - alias pre_hyperloop_inherited inherited + alias pre_hyperstack_inherited inherited def inherited(child_class) - pre_hyperloop_inherited(child_class).tap do - Hyperloop::PolicyAutoLoader.load(child_class.name, child_class) + pre_hyperstack_inherited(child_class).tap do + Hyperstack::PolicyAutoLoader.load(child_class.name, child_class) end end - Hyperloop::ClassPolicyMethods.instance_methods.each do |method| + Hyperstack::ClassPolicyMethods.instance_methods.each do |method| define_method method do |*args, &block| if name.end_with?("Policy".freeze) - @hyperloop_internal_policy_object = Hyperloop::InternalClassPolicy.new(name.sub(/Policy$/,"")) - include Hyperloop::PolicyMethods + @hyperstack_internal_policy_object = Hyperstack::InternalClassPolicy.new(name.sub(/Policy$/,"")) + include Hyperstack::PolicyMethods send method, *args, &block else class << self - Hyperloop::ClassPolicyMethods.instance_methods.each do |method| + Hyperstack::ClassPolicyMethods.instance_methods.each do |method| undef_method method end end method_missing(method, *args, &block) end