Class: Entitlements::Data::Groups::Calculated::Base
- Inherits:
-
Object
- Object
- Entitlements::Data::Groups::Calculated::Base
show all
- Includes:
- Contracts::Core
- Defined in:
- lib/entitlements.rb,
lib/entitlements/data/groups/calculated/base.rb
Constant Summary
collapse
- C =
::Contracts
- ALIAS_METHODS =
{
"entitlements_group" => "group"
}
- MAX_MODIFIER_ITERATIONS =
100
- MODIFIERS =
%w[
expiration
]
Instance Attribute Summary collapse
Instance Method Summary
collapse
common, extended, included
Constructor Details
#initialize(filename:, config: nil, options: {}) ⇒ Base
Returns a new instance of Base.
86
87
88
89
90
91
92
|
# File 'lib/entitlements/data/groups/calculated/base.rb', line 86
def initialize(filename:, config: nil, options: {})
@filename = filename
@config = config
@options = options
@metadata = initialize_metadata
@filters = initialize_filters
end
|
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
31
32
33
|
# File 'lib/entitlements/data/groups/calculated/base.rb', line 31
def filename
@filename
end
|
#filters ⇒ Object
Returns the value of attribute filters.
31
32
33
|
# File 'lib/entitlements/data/groups/calculated/base.rb', line 31
def filters
@filters
end
|
Returns the value of attribute metadata.
31
32
33
|
# File 'lib/entitlements/data/groups/calculated/base.rb', line 31
def metadata
@metadata
end
|
Instance Method Details
#description ⇒ Object
55
56
57
58
59
|
# File 'lib/entitlements/data/groups/calculated/base.rb', line 55
def description
raise "Must be implemented in child class"
end
|
#fatal_message(message) ⇒ Object
100
101
102
103
|
# File 'lib/entitlements/data/groups/calculated/base.rb', line 100
def fatal_message(message)
Entitlements.logger.fatal(message)
raise RuntimeError, message
end
|
#filtered_members ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/entitlements/data/groups/calculated/base.rb', line 111
def filtered_members
return :calculating if members == :calculating
@filtered_members ||= begin
result = members.dup
filters.reject { |_, filter_val| filter_val == :all }.each do |filter_name, filter_val|
filter_cfg = Entitlements::Data::Groups::Calculated.filters_index[filter_name]
clazz = filter_cfg.fetch(:class)
obj = clazz.new(filter: filter_val, config: filter_cfg.fetch(:config, {}))
unless filter_cfg[:config]["excluded_paths"].nil?
unless filter_cfg[:config]["excluded_paths"].any? { |excluded_path| filename.include?(excluded_path) }
result.reject! { |member| obj.filtered?(member) }
end
end
unless filter_cfg[:config]["included_paths"].nil?
if filter_cfg[:config]["included_paths"].any? { |included_path| filename.include?(included_path) }
result.reject! { |member| obj.filtered?(member) }
end
end
if filter_cfg[:config]["included_paths"].nil? and filter_cfg[:config]["excluded_paths"].nil?
result.reject! { |member| obj.filtered?(member) }
end
end
result
end
end
|
#members ⇒ Object
43
44
45
46
47
|
# File 'lib/entitlements/data/groups/calculated/base.rb', line 43
def members
raise "Must be implemented in child class"
end
|
#modified_filtered_members ⇒ Object
164
165
166
167
|
# File 'lib/entitlements/data/groups/calculated/base.rb', line 164
def modified_filtered_members
return :calculating if filtered_members == :calculating
@modified_filtered_members ||= apply_modifiers(filtered_members)
end
|
#modified_members ⇒ Object
153
154
155
156
|
# File 'lib/entitlements/data/groups/calculated/base.rb', line 153
def modified_members
return :calculating if members == :calculating
@modified_members ||= apply_modifiers(members)
end
|
#modifiers ⇒ Object
68
69
70
|
# File 'lib/entitlements/data/groups/calculated/base.rb', line 68
def modifiers
{}
end
|