Module: Cantango::Generators::PermitGenerator

Includes:
Basic
Included in:
AccountPermitGenerator, RolePermitGenerator, RolePermitsGenerator, UserPermitGenerator
Defined in:
lib/generators/cantango/permit_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Basic

#account, #admin_logic, #base_logic, #guest_logic, #license_logic, #rules_logic

Instance Attribute Details

#permit_logicObject

Returns the value of attribute permit_logic.



6
7
8
# File 'lib/generators/cantango/permit_generator.rb', line 6

def permit_logic
  @permit_logic
end

#permit_nameObject

Returns the value of attribute permit_name.



6
7
8
# File 'lib/generators/cantango/permit_generator.rb', line 6

def permit_name
  @permit_name
end

Instance Method Details

#load_permit_template(name) ⇒ Object



24
25
26
27
# File 'lib/generators/cantango/permit_generator.rb', line 24

def load_permit_template name
  template = ERB.new File.open(template_filepath).read.gsub(/\n/, "\n\s\s")
  template.result(binding)
end

#permit_sourceObject



37
38
39
40
41
42
# File 'lib/generators/cantango/permit_generator.rb', line 37

def permit_source
  return "user_permit.erb" if is_user?
  return "account_permit.erb" if is_account?

  is_group? ? "role_group_permit.erb" : "role_permit.erb"
end

#permit_target(name) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/generators/cantango/permit_generator.rb', line 44

def permit_target name
  name = name.to_s.underscore
  return "#{name}_permit.rb" if is_user?
  return "#{name}_account_permit.rb" if is_account?

  is_group? ? "#{name}_role_group_permit.rb" : "#{name}_role_permit.rb"
end

#set_logic(name) ⇒ Object



52
53
54
55
# File 'lib/generators/cantango/permit_generator.rb', line 52

def set_logic name
  meth = "#{name}_logic"
  @permit_logic = respond_to?(meth) ? send(meth) : base_logic
end

#source_pathObject



33
34
35
# File 'lib/generators/cantango/permit_generator.rb', line 33

def source_path
  source_paths.first
end

#template_account_permit(name, account) ⇒ Object



20
21
22
# File 'lib/generators/cantango/permit_generator.rb', line 20

def  name, 
  template "account_permit.erb" , "app/permits/#{}/#{permit_target(name)}"
end

#template_filepathObject



29
30
31
# File 'lib/generators/cantango/permit_generator.rb', line 29

def template_filepath
  File.join source_path, permit_source
end

#template_permit(name, account = nil) ⇒ Object



10
11
12
13
14
# File 'lib/generators/cantango/permit_generator.rb', line 10

def template_permit name,  = nil
  @permit_name = name
  set_logic name
  .present? ? (name, ) : template_simple_permit(name)
end

#template_simple_permit(name) ⇒ Object



16
17
18
# File 'lib/generators/cantango/permit_generator.rb', line 16

def template_simple_permit name
  template permit_source, "app/permits/#{permit_target(name)}"
end