Module: ParamsReady::Helpers::ParameterStorageClassMethods

Defined in:
lib/params_ready/helpers/parameter_storage_class_methods.rb

Instance Method Summary collapse

Instance Method Details

#add_parameter(definition) ⇒ Object



45
46
47
# File 'lib/params_ready/helpers/parameter_storage_class_methods.rb', line 45

def add_parameter(definition)
  params_ready_storage.add_parameter(definition)
end

#add_relation(definition) ⇒ Object



58
59
60
# File 'lib/params_ready/helpers/parameter_storage_class_methods.rb', line 58

def add_relation(definition)
  params_ready_storage.add_relation(definition)
end

#include_parameters(parameter_definer, rule = nil) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/params_ready/helpers/parameter_storage_class_methods.rb', line 36

def include_parameters(parameter_definer, rule = nil)
  rule = Helpers::Rule(rule)
  parameter_definer.all_parameters.each do |key, definition|
    next if rule && !rule.include?(key)

    add_parameter(definition)
  end
end

#include_relations(parameter_definer, rule = nil) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/params_ready/helpers/parameter_storage_class_methods.rb', line 49

def include_relations(parameter_definer, rule = nil)
  rule = Helpers::Rule(rule)
  parameter_definer.all_relations.each do |key, definition|
    next if rule && !rule.include?(key)

    add_relation(definition)
  end
end

#parameter_definition(key) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/params_ready/helpers/parameter_storage_class_methods.rb', line 24

def parameter_definition(key)
  parameters = params_ready_storage.parameters
  sym_key = key.to_sym
  if parameters.key? sym_key
    parameters[sym_key]
  elsif superclass.respond_to? :parameter_definition
    superclass.parameter_definition sym_key
  else
    raise ParamsReadyError, "Unknown parameter '#{sym_key}'"
  end
end

#params_ready_storageObject



8
9
10
# File 'lib/params_ready/helpers/parameter_storage_class_methods.rb', line 8

def params_ready_storage
  @params_ready_storage ||= Storage.new
end

#relation_definition(key) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/params_ready/helpers/parameter_storage_class_methods.rb', line 12

def relation_definition(key)
  relations = params_ready_storage.relations
  sym_key = key.to_sym
  if relations.key?(sym_key)
    relations[sym_key]
  elsif superclass.respond_to? :relation_definition
    superclass.relation_definition sym_key
  else
    raise ParamsReadyError, "Unknown relation '#{sym_key}'"
  end
end