namespace_editor 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 63b7d29138537c4a982880873af503309315d08b
4
+ data.tar.gz: 499f1ae429c9d24d77a7ea54e00dea8fe4f58219
5
+ SHA512:
6
+ metadata.gz: 67f9c42e44549485baca58ab08c17a54015f79b245c0a56ea2b5ed2008502b0f703e021af68af8f5ae4c0a8c5f457e1832f805397e960638d88dd7b4eeef484e
7
+ data.tar.gz: f0431484b1306ea6a9ab144f3c4416098bf1efad34fca4f38dea51c5c0d6f68496451ded617873efce2422e6fe3d4c64508e593b22f86c0837baff73c34027b8
@@ -0,0 +1,57 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require_relative '../lib/NamespaceEditor.rb'
5
+ require_relative '../lib/namespace_editor_version.rb'
6
+
7
+ options = {:list=>false, :overwrite=>false}
8
+
9
+ option_parser = OptionParser.new do |opts|
10
+ executable_name = File.basename($PROGRAM_NAME)
11
+ opts.banner = "\tReplace namespaces in src files
12
+
13
+ Usage: #{executable_name} [options]"
14
+
15
+ opts.on("--list", "output changed files as a list") do
16
+ options[:list] = true
17
+ end
18
+
19
+ opts.on("-x EXISTING", "--existing_namespace EXISTING", "the existing namespace") do |existing_namespace|
20
+ options[:existing_namespace] = existing_namespace
21
+ end
22
+
23
+ opts.on("-n NEW", "--new_namespace NEW", "the new namespace") do |new_namespace|
24
+ options[:new_namespace] = new_namespace
25
+ end
26
+
27
+ opts.on("-s SRCPATH", "--src_path SRCPATH", "path to the folder containing the src files to be processed. SRCPATH will be searched and all of its sub-folders") do |src_path|
28
+ options[:src_path] = src_path.gsub("\\", "/")
29
+ end
30
+
31
+ opts.on("-e EXTNS", "--extensions EXTNS", Array, "the list of file extensions to be searched for, comma separated. E.g. cpp,h,java") do |extensions|
32
+ options[:extensions] = extensions
33
+ end
34
+
35
+ opts.on("--overwrite", "makes the changes to the source files as opposed to the default of just reporting the number of src file discovered") do
36
+ options[:overwrite] = true
37
+ end
38
+ opts.on("-v", "--version", "version number. All other options will be ignored") do
39
+ puts "Version #{Licence_Injector::VERSION}"
40
+ exit
41
+ end
42
+ end
43
+
44
+ option_parser.parse!
45
+
46
+ if options[:new_namespace].nil? || options[:existing_namespace].nil? || options[:src_path].nil? || options[:extensions].nil?
47
+ puts "\tError: you must supply a new namespace, an existing namespace, path to src and some file extensions"
48
+ puts
49
+ puts option_parser.help
50
+ STDERR.puts "ERROR: There are missing arguments"
51
+ exit 1
52
+ end
53
+
54
+ #puts options.inspect
55
+
56
+ namespace_editor = NamespaceEditor.new options[:new_namespace], options[:existing_namespace], options[:src_path], options[:extensions], options[:list], options[:overwrite]
57
+ namespace_editor.replace_namespace
@@ -0,0 +1,76 @@
1
+ class NamespaceEditor
2
+
3
+ attr_accessor :new_namespace, :old_namespace, :src_path, :extensions
4
+ attr_reader :changed_files_count
5
+
6
+ def initialize(new_namespace, old_namespace, src_path, file_extensions, list = false, overwrite = true)
7
+ @new_namespace = new_namespace
8
+ @old_namespace = old_namespace
9
+ @src_path = src_path
10
+ @extensions = file_extensions
11
+ @list = list
12
+ @overwrite = overwrite
13
+
14
+ @changed_files_count = 0
15
+ end
16
+
17
+ def read_file file_path
18
+ File.open file_path, "r" do | file |
19
+ file.read
20
+ end
21
+ end
22
+
23
+ def replace_namespace
24
+ @changed_files_count = 0
25
+ @extensions.each do | extension |
26
+ unless @list
27
+ puts "\tprocessing #{extension} files in #{@src_path}"
28
+ print "\t"
29
+ end
30
+ Dir.glob(@src_path + "/**/*.#{extension}") do |file| #find src files in current folder and all subfolders
31
+ do_replace_namespace file
32
+ end
33
+ unless @list
34
+ puts
35
+ end
36
+ end
37
+ unless @list
38
+ puts
39
+ end
40
+ unless @list
41
+ if @overwrite
42
+ puts "There were #{@changed_files_count} changes made"
43
+ else
44
+ puts "#{@changed_files_count} file(s) were found. Use the --overwrite flag to make changes to the files"
45
+ end
46
+ end
47
+ end
48
+
49
+ def do_replace_namespace file
50
+ src = read_file file
51
+
52
+ src_after_replacing_namespace = src.gsub(@old_namespace, @new_namespace)
53
+
54
+ unless src_after_replacing_namespace === src
55
+ if @overwrite
56
+ begin
57
+ output = File.new(file, "w")
58
+ output.write src_after_replacing_namespace
59
+ output.close
60
+ rescue
61
+ puts
62
+ STDERR.puts "ERROR: There was a problem writing to '#{file}"
63
+ exit 1
64
+ end
65
+ end
66
+
67
+ if @list
68
+ puts File.absolute_path(file)
69
+ else
70
+ print "."
71
+ end
72
+ @changed_files_count += 1
73
+ end
74
+ @changed_files_count
75
+ end
76
+ end
@@ -0,0 +1,3 @@
1
+ module Namespace_Editor
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: namespace_editor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Barry Drinkwater
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.14.1
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.14.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 10.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 10.1.0
55
+ description: namespace_editor replaces existing namespaces with a new namespace in
56
+ each source file found at the given source path whose extension is one of those
57
+ in the given list of extensions. Useful for Android white label apps
58
+ email:
59
+ - barry@penrillian.com
60
+ executables:
61
+ - namespace_editor
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - lib/NamespaceEditor.rb
66
+ - lib/namespace_editor_version.rb
67
+ - bin/namespace_editor
68
+ homepage: https://github.com/Penrillian/NamespaceEditor
69
+ licenses:
70
+ - BSD Clause 2
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.0.3
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Replaces namespaces in source files
92
+ test_files: []