magicfile 0.0.1 → 0.0.2
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 +4 -4
- data/lib/magicfile.rb +92 -3
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec222168eabe89ef31639152cb3b96a2df72715b
|
4
|
+
data.tar.gz: 607c3b42f32d5d1896239ab68437e8081628039a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3fd9e7812ba11363324bcbc7198326b716ee514baebb2798da86af0d9c30a9d9e9992dba99a2d9d67badf6033e6a402e5ca596b68cf44642588714f342c8b53
|
7
|
+
data.tar.gz: 1dc136d6c557efcc479f42d06b3d511e11b500756c21bdc7fa72def8ff6f5025abd17a8a49b378b4b22e5f4e93ca411d62702353387dbb4f384dec19fae745b9
|
data/lib/magicfile.rb
CHANGED
@@ -1,5 +1,94 @@
|
|
1
|
+
require 'awesome_print'
|
2
|
+
require 'active_support'
|
3
|
+
require 'active_support/core_ext/string'
|
4
|
+
|
5
|
+
class MagicLine
|
6
|
+
attr_accessor :content, :space_num
|
7
|
+
|
8
|
+
def initialize(content='', space_num=0)
|
9
|
+
@content = content
|
10
|
+
@space_num = space_num
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
1
14
|
class Magicfile
|
2
|
-
|
3
|
-
|
15
|
+
|
16
|
+
def initialize(lines=[], current_line_index=-1, current_line_space_num=-2)
|
17
|
+
@lines = lines
|
18
|
+
@current_line_index = current_line_index
|
19
|
+
@current_line_space_num = current_line_space_num
|
20
|
+
end
|
21
|
+
|
22
|
+
def append_class(name, parent_class_name=nil)
|
23
|
+
|
24
|
+
if parent_class_name
|
25
|
+
class_start_line = MagicLine.new("class #{name.camelize} < #{parent_class_name}")
|
26
|
+
else
|
27
|
+
class_start_line = MagicLine.new("class #{name.camelize}")
|
28
|
+
end
|
29
|
+
|
30
|
+
append_after_current(class_start_line, true, 2)
|
31
|
+
append_after_current(MagicLine.new("end"), false, 0)
|
32
|
+
end
|
33
|
+
|
34
|
+
def append_module(name)
|
35
|
+
module_start_line = MagicLine.new("module #{name.camelize}")
|
36
|
+
module_end_line = MagicLine.new("end")
|
37
|
+
|
38
|
+
append_after_current(module_start_line, true, 2)
|
39
|
+
append_after_current(module_end_line, false, 0)
|
40
|
+
end
|
41
|
+
|
42
|
+
def append_modules(names)
|
43
|
+
names.each do |name|
|
44
|
+
append_module(name)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def append_string_lines(line_contents)
|
49
|
+
space_num = @current_line_space_num + 2
|
50
|
+
content = line_contents.join("\n" + " " * space_num)
|
51
|
+
ap content
|
52
|
+
line = MagicLine.new(content, space_num)
|
53
|
+
@lines.insert(@current_line_index + 1, line)
|
54
|
+
end
|
55
|
+
|
56
|
+
def append_after_current(line, enable_move_down=true, spaces=2)
|
57
|
+
|
58
|
+
|
59
|
+
line.space_num = @current_line_space_num + spaces
|
60
|
+
@lines.insert(@current_line_index + 1, line)
|
61
|
+
|
62
|
+
|
63
|
+
if enable_move_down
|
64
|
+
@current_line_space_num = line.space_num
|
65
|
+
@current_line_index += 1
|
66
|
+
end
|
67
|
+
|
68
|
+
ap "after start======"
|
69
|
+
ap @lines
|
70
|
+
ap @current_line_index
|
71
|
+
ap @current_line_space_num
|
72
|
+
ap "end======"
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
def to_file(name)
|
77
|
+
infos = @lines.map { |line| " " * line.instance_variable_get("@space_num") + line.instance_variable_get("@content") }
|
78
|
+
ap infos.join("\n")
|
79
|
+
File.open(name, 'w') { |file| file.write(infos.join("\n")) }
|
80
|
+
end
|
81
|
+
|
82
|
+
def display
|
83
|
+
@lines.each do |line|
|
84
|
+
ap ' ' * line.instance_variable_get("@space_num") + line.instance_variable_get("@content")
|
85
|
+
end
|
4
86
|
end
|
5
|
-
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
a = Magicfile.new
|
91
|
+
a.append_modules(['api', 'v1', 'entities'])
|
92
|
+
a.append_class('screen', 'Grape::Entity')
|
93
|
+
a.append_string_lines(['expose :id', 'expose :name'])
|
94
|
+
a.to_file('tmp.txt')
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magicfile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- seaify
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
email:
|
13
|
+
description: used to create file, modify file, read file information
|
14
|
+
email: dilin.life@gmail.com
|
15
15
|
executables:
|
16
16
|
- magicfile
|
17
17
|
extensions: []
|
@@ -42,6 +42,6 @@ rubyforge_project:
|
|
42
42
|
rubygems_version: 2.4.7
|
43
43
|
signing_key:
|
44
44
|
specification_version: 4
|
45
|
-
summary:
|
45
|
+
summary: used to create file, modify file, read file information
|
46
46
|
test_files: []
|
47
47
|
has_rdoc:
|