Module: Vinyl
- Defined in:
- lib/vinyl/base.rb,
lib/vinyl/rule.rb,
lib/vinyl/version.rb,
lib/vinyl/validator.rb,
lib/vinyl/variables.rb
Defined Under Namespace
Modules: Validators
Classes: Configuration, InvalidAclRule, Rule, UserVariables
Constant Summary
collapse
- VERSION =
"0.0.4"
Class Method Summary
collapse
Class Method Details
.access_level_with_no_validators ⇒ Object
40
41
42
|
# File 'lib/vinyl/base.rb', line 40
def self.access_level_with_no_validators
return Vinyl.config.force_access_control ? 0 : 1
end
|
.acl_routes_collection ⇒ Object
7
8
9
|
# File 'lib/vinyl/rule.rb', line 7
def self.acl_routes_collection
Rule.acl_routes_collection
end
|
.add_global_validator(name, block) ⇒ Object
7
8
9
10
|
# File 'lib/vinyl/validator.rb', line 7
def self.add_global_validator(name,block)
Validators.module_eval{define_singleton_method(Validators.prefix + name,block)}
global_validators << name
end
|
.add_validator(name, block) ⇒ Object
3
4
5
|
# File 'lib/vinyl/validator.rb', line 3
def self.add_validator(name,block)
Validators.module_eval{define_singleton_method(Validators.prefix + name,block)}
end
|
.bypass(names) ⇒ Object
16
17
18
19
|
# File 'lib/vinyl/validator.rb', line 16
def self.bypass(names)
Validators.exclude_global_validator(names)
self
end
|
.check_level(route, method) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/vinyl/base.rb', line 15
def self.check_level(route,method)
method_routes = Vinyl.acl_routes_collection[method]
return Vinyl.access_level_with_no_validators if method_routes.nil? || method_routes.empty?
validators_to_call = method_routes[route]
if validators_to_call.nil? || validators_to_call.empty?
if global_validators.empty?
return Vinyl.access_level_with_no_validators
else
validators_to_call = {1 => []}
end
end
keys = validators_to_call.keys.sort
highest_level = 0
keys.send("#{Vinyl::config.validators_iterate_strategy}") do |access_level|
pass = Vinyl::Validators.run_validators(validators_to_call[access_level])
if (pass==true) then
highest_level = access_level
break if Vinyl::config.api_acl_mode == Vinyl::Configuration::STRATEGY_DESCENDING
elsif (pass==false)
break if Vinyl::config.api_acl_mode == Vinyl::Configuration::STRATEGY_ASCENDING
end
end
return highest_level
end
|
.config ⇒ Object
11
12
13
|
# File 'lib/vinyl/base.rb', line 11
def self.config
@config ||=Configuration.new
end
|
.config=(config) ⇒ Object
7
8
9
|
# File 'lib/vinyl/base.rb', line 7
def self.config=(config)
@config = config
end
|
3
4
5
|
# File 'lib/vinyl/base.rb', line 3
def self.configure
yield config
end
|
.controller ⇒ Object
16
17
18
|
# File 'lib/vinyl/variables.rb', line 16
def self.controller
@@user_variables ||=UserVariables.new
end
|
.execute(name) ⇒ Object
12
13
14
|
# File 'lib/vinyl/validator.rb', line 12
def self.execute(name)
Validators.send(Validators.prefix + name)
end
|
.get(value) ⇒ Object
8
9
10
|
# File 'lib/vinyl/variables.rb', line 8
def self.get(value)
controller.variables[value]
end
|
.global_validators ⇒ Object
21
22
23
|
# File 'lib/vinyl/validator.rb', line 21
def self.global_validators
Validators.global_validators
end
|
.method_missing(*args) ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'lib/vinyl/variables.rb', line 20
def self.method_missing(*args)
if args.length == 2 then
Vinyl::put ({args[0].to_s.chomp('=').to_sym => args[1]})
elsif args.length == 1
return Vinyl::get(args.first)
else
super
end
end
|
.put(variable) ⇒ Object
3
4
5
6
|
# File 'lib/vinyl/variables.rb', line 3
def self.put(variable)
controller.put(variable)
return self
end
|
.reset_variables ⇒ Object
12
13
14
|
# File 'lib/vinyl/variables.rb', line 12
def self.reset_variables
controller.variables.clear
end
|
.when_route(route, *args) ⇒ Object
3
4
5
|
# File 'lib/vinyl/rule.rb', line 3
def self.when_route(route, *args)
Rule.add(route, args[0])
end
|