Class: Renamespace::Paths

Inherits:
Struct
  • Object
show all
Defined in:
lib/renamespace/paths.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#destinationObject

Returns the value of attribute destination

Returns:

  • (Object)

    the current value of destination



4
5
6
# File 'lib/renamespace/paths.rb', line 4

def destination
  @destination
end

#sourceObject

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



4
5
6
# File 'lib/renamespace/paths.rb', line 4

def source
  @source
end

Class Method Details

.all_ruby_file_pathsObject



33
34
35
# File 'lib/renamespace/paths.rb', line 33

def self.all_ruby_file_paths
  (Dir.glob('**/*.rb') - %w[invert_namespaces.rb renamespace.rb])
end

.custom_camelcasingsObject



26
27
28
29
30
31
# File 'lib/renamespace/paths.rb', line 26

def self.custom_camelcasings
  {
    'greensync' => 'GreenSync',
    'goodwe' => 'GoodWe',
  }
end

.namespace_element_from_path_element(path_element) ⇒ Object



22
23
24
# File 'lib/renamespace/paths.rb', line 22

def self.namespace_element_from_path_element(path_element)
  custom_camelcasings.fetch(path_element) { path_element.upper_camelcase }
end

.namespace_elements_for_path(path) ⇒ Object



13
14
15
16
# File 'lib/renamespace/paths.rb', line 13

def self.namespace_elements_for_path(path)
  path_elements_for_require(path)
    .map(&method(:namespace_element_from_path_element))
end

.namespace_for_path(path) ⇒ Object



5
6
7
# File 'lib/renamespace/paths.rb', line 5

def self.namespace_for_path(path)
  namespace_elements_for_path(path).join('::')
end

.path_elements_for_require(path) ⇒ Object



18
19
20
# File 'lib/renamespace/paths.rb', line 18

def self.path_elements_for_require(path)
  path.sub(%r{^lib/}, '').chomp('.rb').split('/')
end

.require_for_path(path) ⇒ Object



9
10
11
# File 'lib/renamespace/paths.rb', line 9

def self.require_for_path(path)
  path_elements_for_require(path).join('/')
end

Instance Method Details

#destination_namespaceObject



41
42
43
# File 'lib/renamespace/paths.rb', line 41

def destination_namespace
  self.class.namespace_for_path(destination)
end

#destination_namespace_elementsObject



49
50
51
# File 'lib/renamespace/paths.rb', line 49

def destination_namespace_elements
  self.class.namespace_elements_for_path(destination)
end

#destination_require_pathObject



57
58
59
# File 'lib/renamespace/paths.rb', line 57

def destination_require_path
  self.class.require_for_path(destination)
end

#same?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/renamespace/paths.rb', line 61

def same?
  source == destination
end

#source_namespaceObject



37
38
39
# File 'lib/renamespace/paths.rb', line 37

def source_namespace
  self.class.namespace_for_path(source)
end

#source_namespace_elementsObject



45
46
47
# File 'lib/renamespace/paths.rb', line 45

def source_namespace_elements
  self.class.namespace_elements_for_path(source)
end

#source_require_pathObject



53
54
55
# File 'lib/renamespace/paths.rb', line 53

def source_require_path
  self.class.require_for_path(source)
end