Module: Constraintable

Included in:
ActiveEndpoint::Routes::ConstraintRule, ActiveEndpoint::Routes::Constraints
Defined in:
lib/active_endpoint/concerns/constraintable.rb

Instance Method Summary collapse

Instance Method Details

#constraints(options) ⇒ Object



2
3
4
5
6
7
# File 'lib/active_endpoint/concerns/constraintable.rb', line 2

def constraints(options)
  {
    rule: rule_constraints(options),
    storage: storage_constraints(options)
  }
end

#default_constraintsObject



31
32
33
34
35
36
# File 'lib/active_endpoint/concerns/constraintable.rb', line 31

def default_constraints
  {
    rule: default_rule_constraints,
    storage: default_storage_constraints
  }
end

#default_rule_constraintsObject



38
39
40
41
42
43
# File 'lib/active_endpoint/concerns/constraintable.rb', line 38

def default_rule_constraints
  {
    limit: ActiveEndpoint.constraint_limit,
    period: ActiveEndpoint.constraint_period
  }
end

#default_storage_constraintsObject



45
46
47
48
49
50
# File 'lib/active_endpoint/concerns/constraintable.rb', line 45

def default_storage_constraints
  {
    limit: ActiveEndpoint.storage_limit,
    period: ActiveEndpoint.storage_period
  }
end

#rule_constraints(options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/active_endpoint/concerns/constraintable.rb', line 9

def rule_constraints(options)
  rule_options = fetch_rule(options)

  defined_rule_constraints = {
    limit: fetch_limit(rule_options),
    period: fetch_period(rule_options)
  }.reject { |_key, value| value.nil? }

  default_rule_constraints.merge(defined_rule_constraints)
end

#storage_constraints(options) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/active_endpoint/concerns/constraintable.rb', line 20

def storage_constraints(options)
  storage_options = fetch_storage(options)

  defined_storage_constraints = {
    limit: fetch_limit(storage_options),
    period: fetch_period(storage_options)
  }.reject { |_key, value| value.nil? }

  default_storage_constraints.merge(defined_storage_constraints)
end