Class: ActiveRecord::Base
- Inherits:
-
Object
show all
- Extended by:
- ClassMethods
- Includes:
- InstanceMethods
- Defined in:
- lib/reactive_record/active_record/base.rb,
lib/reactive_record/active_record/aggregations.rb,
lib/reactive_record/active_record/associations.rb,
lib/reactive_record/reactive_scope.rb,
lib/reactive_record/permissions.rb
Class Attribute Summary collapse
Instance Attribute Summary collapse
#backing_record
Class Method Summary
collapse
Instance Method Summary
collapse
_react_param_conversion, abstract_class=, abstract_class?, all, all=, base_class, column_names, composed_of, enum, find, find_by, inheritance_column, inheritance_column=, method_missing, model_name, primary_key, primary_key=, scope
#==, #attributes, #changed?, #destroy, #destroyed?, #dup, #errors, #id, #id=, #initialize, #load, #method_missing, #model_name, #new?, #primary_key, #revert, #save, #saving?
Class Attribute Details
.reactive_record_association_keys ⇒ Object
Returns the value of attribute reactive_record_association_keys.
59
60
61
|
# File 'lib/reactive_record/permissions.rb', line 59
def reactive_record_association_keys
@reactive_record_association_keys
end
|
Instance Attribute Details
#acting_user ⇒ Object
Returns the value of attribute acting_user.
11
12
13
|
# File 'lib/reactive_record/permissions.rb', line 11
def acting_user
@acting_user
end
|
Class Method Details
.belongs_to_with_reactive_record_add_is_method(attr_name, scope = nil, options = {}) ⇒ Object
72
73
74
75
76
77
|
# File 'lib/reactive_record/permissions.rb', line 72
def belongs_to_with_reactive_record_add_is_method(attr_name, scope = nil, options = {})
define_method "#{attr_name}_is?".to_sym do |model|
send(options[:foreign_key] || "#{attr_name}_id") == model.id
end
belongs_to_without_reactive_record_add_is_method(attr_name, scope, options)
end
|
.reflect_on_aggregation(attribute) ⇒ Object
9
10
11
|
# File 'lib/reactive_record/active_record/aggregations.rb', line 9
def self.reflect_on_aggregation(attribute)
reflect_on_all_aggregations.detect { |aggregation| aggregation.attribute == attribute }
end
|
.reflect_on_all_aggregations ⇒ Object
5
6
7
|
# File 'lib/reactive_record/active_record/aggregations.rb', line 5
def self.reflect_on_all_aggregations
base_class.instance_eval { @aggregations ||= [] }
end
|
.reflect_on_all_associations ⇒ Object
5
6
7
|
# File 'lib/reactive_record/active_record/associations.rb', line 5
def self.reflect_on_all_associations
base_class.instance_eval { @associations ||= superclass.instance_eval { (@associations && @associations.dup) || [] } }
end
|
.reflect_on_association(attribute) ⇒ Object
9
10
11
12
13
14
15
16
17
|
# File 'lib/reactive_record/active_record/associations.rb', line 9
def self.reflect_on_association(attribute)
if found = reflect_on_all_associations.detect { |association| association.attribute == attribute and association.owner_class == self }
found
elsif superclass == Base
nil
else
superclass.reflect_on_association(attribute)
end
end
|
.to_sync(scope_name, opts = {}, &block) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/reactive_record/reactive_scope.rb', line 3
def self.to_sync(scope_name, opts={}, &block)
watch_list = if opts[:watch]
[*opts.delete[:watch]]
else
[self]
end
if RUBY_ENGINE=='opal'
watch_list.each do |klass_to_watch|
ReactiveRecord::Base.sync_blocks[klass_to_watch][self][scope_name] << block
end
else
end
end
|
Instance Method Details
#all_changed?(*attributes) ⇒ Boolean
50
51
52
53
54
55
|
# File 'lib/reactive_record/permissions.rb', line 50
def all_changed?(*attributes)
attributes.each do |key|
return false unless self.send("#{key}_changed?")
end
true
end
|
#any_changed?(*attributes) ⇒ Boolean
43
44
45
46
47
48
|
# File 'lib/reactive_record/permissions.rb', line 43
def any_changed?(*attributes)
attributes.each do |key|
return true if self.send("#{key}_changed?")
end
false
end
|
#check_permission_with_acting_user(user, permission, *args) ⇒ Object
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/reactive_record/permissions.rb', line 84
def check_permission_with_acting_user(user, permission, *args)
old = acting_user
self.acting_user = user
if self.send(permission, *args)
self.acting_user = old
self
else
raise ReactiveRecord::AccessViolation, "for #{permission}(#{args})"
end
end
|
#create_permitted? ⇒ Boolean
13
14
15
|
# File 'lib/reactive_record/permissions.rb', line 13
def create_permitted?
true
end
|
#destroy_permitted? ⇒ Boolean
21
22
23
|
# File 'lib/reactive_record/permissions.rb', line 21
def destroy_permitted?
true
end
|
#none_changed?(*attributes) ⇒ Boolean
36
37
38
39
40
41
|
# File 'lib/reactive_record/permissions.rb', line 36
def none_changed?(*attributes)
attributes.each do |key|
return false if self.send("#{key}_changed?")
end
true
end
|
#only_changed?(*attributes) ⇒ Boolean
29
30
31
32
33
34
|
# File 'lib/reactive_record/permissions.rb', line 29
def only_changed?(*attributes)
(self.attributes.keys + self.class.reactive_record_association_keys).each do |key|
return false if self.send("#{key}_changed?") and !attributes.include? key
end
true
end
|
#update_permitted? ⇒ Boolean
17
18
19
|
# File 'lib/reactive_record/permissions.rb', line 17
def update_permitted?
true
end
|
#view_permitted?(attribute) ⇒ Boolean
25
26
27
|
# File 'lib/reactive_record/permissions.rb', line 25
def view_permitted?(attribute)
true
end
|