Class: Zoom::Profile
- Inherits:
-
Hash
- Object
- Hash
- Zoom::Profile
show all
- Defined in:
- lib/zoom/profile.rb
Defined Under Namespace
Classes: Ack, Ag, Find, Grep, Pt, Rg
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(n = nil, t = nil, f = nil, b = nil, a = nil) ⇒ Profile
Returns a new instance of Profile.
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/zoom/profile.rb', line 135
def initialize(n = nil, t = nil, f = nil, b = nil, a = nil)
a ||= ""
b ||= ""
f ||= ""
n ||= camel_case_to_underscore(self.class.to_s)
t ||= "echo"
self["class"] = self.class.to_s
after(a)
before(b)
flags(f)
name(n)
tool(t)
@exts = Array.new @files = Array.new @regex = ""
@format_flags = ""
@grep_like_tags = true
@taggable = false
grep_like_format_flags
end
|
Instance Attribute Details
#exts ⇒ Object
Returns the value of attribute exts.
6
7
8
|
# File 'lib/zoom/profile.rb', line 6
def exts
@exts
end
|
#files ⇒ Object
Returns the value of attribute files.
7
8
9
|
# File 'lib/zoom/profile.rb', line 7
def files
@files
end
|
Returns the value of attribute format_flags.
8
9
10
|
# File 'lib/zoom/profile.rb', line 8
def format_flags
@format_flags
end
|
#regex ⇒ Object
Returns the value of attribute regex.
9
10
11
|
# File 'lib/zoom/profile.rb', line 9
def regex
@regex
end
|
#taggable ⇒ Object
Returns the value of attribute taggable.
10
11
12
|
# File 'lib/zoom/profile.rb', line 10
def taggable
@taggable
end
|
Class Method Details
.from_json(json) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/zoom/profile.rb', line 68
def self.from_json(json)
begin
return profile_by_name(json["class"]).new(
json["name"],
json["tool"].nil? ? "" : json["tool"],
json["flags"].nil? ? "" : json["flags"],
json["before"].nil? ? "" : json["before"],
json["after"].nil? ? "" : json["after"]
)
rescue NoMethodError
raise Zoom::Error::ProfileNotNamed.new(json)
rescue NameError
raise Zoom::Error::ProfileClassUnknown.new(json["class"])
end
end
|
.profile_by_name(clas) ⇒ Object
176
177
178
179
180
|
# File 'lib/zoom/profile.rb', line 176
def self.profile_by_name(clas)
clas.split("::").inject(Object) do |mod, class_name|
mod.const_get(class_name)
end
end
|
.subclasses ⇒ Object
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/zoom/profile.rb', line 182
def self.subclasses
ObjectSpace.each_object(Class).select do |clas|
if (clas < self)
begin
clas.new
true
rescue Zoom::Error::ExecutableNotFound
false
end
else
false
end
end
end
|
Instance Method Details
#after(a = nil) ⇒ Object
12
13
14
15
16
|
# File 'lib/zoom/profile.rb', line 12
def after(a = nil)
self["after"] = a.strip if (a)
self["after"] ||= ""
return self["after"]
end
|
#before(b = nil) ⇒ Object
18
19
20
21
22
|
# File 'lib/zoom/profile.rb', line 18
def before(b = nil)
self["before"] = b.strip if (b)
self["before"] ||= ""
return self["before"]
end
|
#class_name ⇒ Object
34
35
36
|
# File 'lib/zoom/profile.rb', line 34
def class_name
return self["class"]
end
|
#exe(header) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/zoom/profile.rb', line 38
def exe()
cmd = [
before,
tool,
@format_flags,
flags,
only_exts_and_files,
["translated"],
["args"],
"--",
["regex"].shellescape,
["paths"],
after
].join(" ").strip
if (.has_key?("debug") && ["debug"])
puts(cmd)
return ""
else
return %x(#{cmd})
end
end
|
#flags(f = nil) ⇒ Object
62
63
64
65
66
|
# File 'lib/zoom/profile.rb', line 62
def flags(f = nil)
self["flags"] = f.strip if (f)
self["flags"] ||= ""
return self["flags"]
end
|
84
85
86
87
|
# File 'lib/zoom/profile.rb', line 84
def grep_like_format_flags(all = false)
@format_flags = "" @taggable = false end
|
89
90
91
|
# File 'lib/zoom/profile.rb', line 89
def grep_like_tags?
return @grep_like_tags
end
|
#name(n = nil) ⇒ Object
161
162
163
164
165
|
# File 'lib/zoom/profile.rb', line 161
def name(n = nil)
self["name"] = n.strip if (n)
self["name"] ||= ""
return self["name"]
end
|
#only_exts_and_files ⇒ Object
167
168
169
170
|
# File 'lib/zoom/profile.rb', line 167
def only_exts_and_files
return ""
end
|
#preprocess(header) ⇒ Object
172
173
174
|
# File 'lib/zoom/profile.rb', line 172
def preprocess()
return
end
|
#to_s ⇒ Object
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
# File 'lib/zoom/profile.rb', line 197
def to_s
ret = Array.new
ret.push(hilight_name)
ret.push("#{hilight_class}\n")
ret.push(hilight_before(before)) if (!before.empty?)
ret.push(hilight_tool(tool)) if (!tool.empty?)
ret.push(hilight_flags(flags)) if (!flags.empty?)
if (@regex.nil? || @regex.empty?)
ret.push(hilight_regex("REGEX"))
else
ret.push(hilight_regex("\"#{@regex}\""))
end
ret.push(hilight_after(after)) if (!after.empty?)
return ret.join(" ").strip
end
|
213
214
215
216
217
218
219
220
221
|
# File 'lib/zoom/profile.rb', line 213
def tool(t = nil)
if (t)
t.strip!
tl = ScoobyDoo.where_are_you(t)
raise Zoom::Error::ExecutableNotFound.new(t) if (tl.nil?)
self["tool"] = t
end
return self["tool"]
end
|
#translate(from) ⇒ Object
223
224
225
|
# File 'lib/zoom/profile.rb', line 223
def translate(from)
return ""
end
|