Class: ControllerHelpers::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/controller_helpers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Model

Returns a new instance of Model.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/controller_helpers.rb', line 33

def initialize(file_path)
  # puts "file_path = #{file_path}"
  self.file_path = file_path
  # puts "self.file_path = #{self.file_path}"
  self.file_name = File.basename(file_path, File.extname(file_path))
  # puts "self.file_name = #{self.file_name}"
  self.directory = File.dirname(file_path)
  # puts "self.directory = #{self.directory}"
  self.class_name = self.file_name
  # puts "self.class_name = #{self.class_name}"
  if self.directory.match(/\/controllers/)
    # handle if they're controllers
    self.class_with_module = self.file_path.gsub("#{RAILS_ROOT}/app/controllers/", "").gsub(File.extname(self.file_path), "")
  elsif self.directory.match(/\/controller_helpers/)
    # handle if they're controller helpers
    self.class_with_module = self.file_path.gsub("#{RAILS_ROOT}/app/controller_helpers/", "").gsub(File.extname(self.file_path), "")
  else
    raise "What the hell!?! #{self.directory}"
  end
  # puts "self.class_with_module = #{self.class_with_module}"
  if self.class_name == "application"
    self.class_name = "application_controller"
    # puts "self.class_name = #{self.class_name}"
    self.class_with_module = self.class_name
    # puts "self.class_with_module = #{self.class_with_module}"
  end
  self.class_name_camel = self.class_name.camelcase
  # puts "self.class_name_camel = #{self.class_name_camel}"
  self.class_with_module_camel = self.class_with_module.camelcase
  # puts "self.class_with_module_camel = #{self.class_with_module_camel}"
  if self.class_with_module.match(/\//)
    self.module = self.class_with_module.gsub("/#{self.class_name}", "")
    # puts "self.module = #{self.module}"
    self.module_camel = self.module.camelcase
    # puts "self.module_camel = #{self.module_camel}"
  else
    self.module = "module"
    self.module_camel = "Module"
  end
end

Instance Attribute Details

#class_nameObject

Returns the value of attribute class_name.



26
27
28
# File 'lib/controller_helpers.rb', line 26

def class_name
  @class_name
end

#class_name_camelObject

Returns the value of attribute class_name_camel.



28
29
30
# File 'lib/controller_helpers.rb', line 28

def class_name_camel
  @class_name_camel
end

#class_with_moduleObject

Returns the value of attribute class_with_module.



27
28
29
# File 'lib/controller_helpers.rb', line 27

def class_with_module
  @class_with_module
end

#class_with_module_camelObject

Returns the value of attribute class_with_module_camel.



29
30
31
# File 'lib/controller_helpers.rb', line 29

def class_with_module_camel
  @class_with_module_camel
end

#directoryObject

Returns the value of attribute directory.



25
26
27
# File 'lib/controller_helpers.rb', line 25

def directory
  @directory
end

#file_nameObject

Returns the value of attribute file_name.



24
25
26
# File 'lib/controller_helpers.rb', line 24

def file_name
  @file_name
end

#file_pathObject

Returns the value of attribute file_path.



23
24
25
# File 'lib/controller_helpers.rb', line 23

def file_path
  @file_path
end

#moduleObject

Returns the value of attribute module.



30
31
32
# File 'lib/controller_helpers.rb', line 30

def module
  @module
end

#module_camelObject

Returns the value of attribute module_camel.



31
32
33
# File 'lib/controller_helpers.rb', line 31

def module_camel
  @module_camel
end

Instance Method Details

#to_sObject



74
75
76
# File 'lib/controller_helpers.rb', line 74

def to_s
  self.class_with_module_camel
end