Class: ModuleName

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parts_of_module) ⇒ ModuleName

Returns a new instance of ModuleName.



191
192
193
# File 'lib/brut/junk_drawer.rb', line 191

def initialize(parts_of_module)
  @parts_of_module = parts_of_module
end

Instance Attribute Details

#parts_of_moduleObject (readonly)

Returns the value of attribute parts_of_module.



189
190
191
# File 'lib/brut/junk_drawer.rb', line 189

def parts_of_module
  @parts_of_module
end

Class Method Details

.from_string(string) ⇒ Object



181
182
183
184
185
186
187
# File 'lib/brut/junk_drawer.rb', line 181

def self.from_string(string)
  string = RichString.from_string(string)
  if string.nil?
    raise ArgumentError, "ClassName cannot be initialized with a blank string"
  end
  self.new(string.camelize.split(/::/).map { RichString.new(it) })
end

Instance Method Details

#append(module_name) ⇒ Object



203
204
205
# File 'lib/brut/junk_drawer.rb', line 203

def append(module_name)
  self.class.new(@parts_of_module + module_name.parts_of_module)
end

#in_module(module_name) ⇒ Object



195
196
197
198
199
200
201
# File 'lib/brut/junk_drawer.rb', line 195

def in_module(module_name)
  if in_module?(module_name)
    return self
  else
    module_name.append(self)
  end
end

#path_from(base_path, extname: ".rb") ⇒ Object



209
210
211
212
213
214
215
216
217
218
219
# File 'lib/brut/junk_drawer.rb', line 209

def path_from(base_path, extname: ".rb")
  parts_as_path_segment = @parts_of_module.map { |part|
    if part.to_s == "DB"
      "db"
    else
      part.underscorized.to_s
    end
  }
  *subdir_parts,file_name_part = parts_as_path_segment
  base_path.join(*subdir_parts,file_name_part + extname)
end

#to_sObject



207
# File 'lib/brut/junk_drawer.rb', line 207

def to_s = @parts_of_module.join("::")