Class: ParamsReady::Helpers::InterfaceDefiner

Inherits:
Object
  • Object
show all
Defined in:
lib/params_ready/helpers/interface_definer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action_names, user) ⇒ InterfaceDefiner

Returns a new instance of InterfaceDefiner.



4
5
6
7
# File 'lib/params_ready/helpers/interface_definer.rb', line 4

def initialize(action_names, user)
  @action_names = action_names
  @user = user
end

Class Method Details

.complete_list(singular, plural) ⇒ Object



38
39
40
41
# File 'lib/params_ready/helpers/interface_definer.rb', line 38

def self.complete_list(singular, plural)
  list = singular.nil? ? plural : [singular, *plural]
  normalize_list(list)
end

.normalize_list(list) ⇒ Object



43
44
45
# File 'lib/params_ready/helpers/interface_definer.rb', line 43

def self.normalize_list(list)
  list.map(&:to_sym)
end

Instance Method Details

#define(parameter: nil, relation: nil, parameters: [], relations: [], &block) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/params_ready/helpers/interface_definer.rb', line 29

def define(parameter: nil, relation: nil, parameters: [], relations: [], &block)
  parameters = self.class.complete_list(parameter, parameters)
  parameters(*parameters)
  relations = self.class.complete_list(relation, relations)
  relations(*relations)
  instance_eval(&block) unless block.nil?
  @option
end

#parameter(name) ⇒ Object



21
22
23
# File 'lib/params_ready/helpers/interface_definer.rb', line 21

def parameter(name)
  @user.use_parameter(name, only: @action_names)
end

#parameters(*names) ⇒ Object



9
10
11
12
13
# File 'lib/params_ready/helpers/interface_definer.rb', line 9

def parameters(*names)
  names.each do |name|
    parameter(name)
  end
end

#relation(name) ⇒ Object



25
26
27
# File 'lib/params_ready/helpers/interface_definer.rb', line 25

def relation(name)
  @user.use_relation(name, only: @action_names)
end

#relations(*names) ⇒ Object



15
16
17
18
19
# File 'lib/params_ready/helpers/interface_definer.rb', line 15

def relations(*names)
  names.each do |name|
    relation(name)
  end
end