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.



193
194
195
# File 'lib/brut/junk_drawer.rb', line 193

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.



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

def parts_of_module
  @parts_of_module
end

Class Method Details

.from_string(string) ⇒ Object



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

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



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

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

#in_module(module_name) ⇒ Object



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

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



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

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



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

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