procemon 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -1
- data/Rakefile +1 -170
- data/VERSION +1 -1
- data/lib/procemon/function/meta/inject_methods.rb +2 -0
- data/lib/procemon/function/require.rb +53 -12
- data/lib/procemon/mpatch/array.rb +12 -2
- data/lib/procemon/mpatch/object.rb +79 -0
- data/procemon.gemspec +2 -5
- data/test/bump/test2.rb +1 -0
- data/test/test.rb +1 -9
- metadata +9 -5
- data/README.rdoc +0 -19
data/README.md
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
procemon
|
2
2
|
========
|
3
3
|
|
4
|
-
Gotta catch em all!
|
4
|
+
Gotta catch em all!
|
5
|
+
This is a collection of my Ruby Procs in the adventure of becoming the best!
|
6
|
+
|
7
|
+
|
8
|
+
This is including Tons of monkey_patch for new features to classes,
|
9
|
+
meta-programing tricks, terminal argument controls, daemonise trick,
|
10
|
+
tmp folder helpers, Application centralized datas, folder structure logic ,
|
11
|
+
meta data control, dynamic lib read etc
|
data/Rakefile
CHANGED
@@ -1,170 +1 @@
|
|
1
|
-
|
2
|
-
require 'bundler'
|
3
|
-
module Bundler
|
4
|
-
class GemHelper
|
5
|
-
include Rake::DSL if defined? Rake::DSL
|
6
|
-
|
7
|
-
class << self
|
8
|
-
# set when install'd.
|
9
|
-
attr_accessor :instance
|
10
|
-
|
11
|
-
def install_tasks(opts = {})
|
12
|
-
new(opts[:dir], opts[:name]).install
|
13
|
-
end
|
14
|
-
|
15
|
-
def gemspec(&block)
|
16
|
-
gemspec = instance.gemspec
|
17
|
-
block.call(gemspec) if block
|
18
|
-
gemspec
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
attr_reader :spec_path, :base, :gemspec
|
23
|
-
|
24
|
-
def initialize(base = nil, name = nil)
|
25
|
-
Bundler.ui = UI::Shell.new
|
26
|
-
@base = (base ||= Dir.pwd)
|
27
|
-
gemspecs = name ? [File.join(base, "#{name}.gemspec")] : Dir[File.join(base, "{,*}.gemspec")]
|
28
|
-
#raise "Unable to determine name from existing gemspec. Use :name => 'gemname' in #install_tasks to manually set it." unless gemspecs.size == 1
|
29
|
-
@spec_path = gemspecs.first
|
30
|
-
@gemspec = Bundler.load_gemspec(@spec_path)
|
31
|
-
end
|
32
|
-
|
33
|
-
def install
|
34
|
-
built_gem_path = nil
|
35
|
-
|
36
|
-
desc "Build #{name}-#{version}.gem into the pkg directory."
|
37
|
-
task 'build' do
|
38
|
-
built_gem_path = build_gem
|
39
|
-
end
|
40
|
-
|
41
|
-
desc "Build and install #{name}-#{version}.gem into system gems."
|
42
|
-
task 'install' => 'build' do
|
43
|
-
install_gem(built_gem_path)
|
44
|
-
end
|
45
|
-
|
46
|
-
#desc "NOT this: Create tag #{version_tag} and build and push #{name}-#{version}.gem to Rubygems"
|
47
|
-
#task 'release' => 'build' do
|
48
|
-
# #release_gem(built_gem_path)
|
49
|
-
#end
|
50
|
-
|
51
|
-
GemHelper.instance = self
|
52
|
-
end
|
53
|
-
|
54
|
-
def build_gem
|
55
|
-
file_name = nil
|
56
|
-
sh("gem build -V '#{spec_path}'") { |out, code|
|
57
|
-
file_name = File.basename(built_gem_path)
|
58
|
-
FileUtils.mkdir_p(File.join(base, 'pkg'))
|
59
|
-
FileUtils.mv(built_gem_path, 'pkg')
|
60
|
-
Bundler.ui.confirm "#{name} #{version} built to pkg/#{file_name}."
|
61
|
-
}
|
62
|
-
File.join(base, 'pkg', file_name)
|
63
|
-
end
|
64
|
-
|
65
|
-
def install_gem(built_gem_path=nil)
|
66
|
-
built_gem_path ||= build_gem
|
67
|
-
out, _ = sh_with_code("gem install '#{built_gem_path}' --local")
|
68
|
-
raise "Couldn't install gem, run `gem install #{built_gem_path}' for more detailed output" unless out[/Successfully installed/]
|
69
|
-
Bundler.ui.confirm "#{name} (#{version}) installed."
|
70
|
-
end
|
71
|
-
|
72
|
-
def release_gem(built_gem_path=nil)
|
73
|
-
#guard_clean
|
74
|
-
#built_gem_path ||= build_gem
|
75
|
-
#tag_version { git_push } unless already_tagged?
|
76
|
-
#rubygem_push(built_gem_path) if gem_push?
|
77
|
-
end
|
78
|
-
|
79
|
-
protected
|
80
|
-
def rubygem_push(path)
|
81
|
-
if Pathname.new("~/.gem/credentials").expand_path.exist?
|
82
|
-
sh("gem push '#{path}'")
|
83
|
-
Bundler.ui.confirm "Pushed #{name} #{version} to rubygems.org."
|
84
|
-
else
|
85
|
-
raise "Your rubygems.org credentials aren't set. Run `gem push` to set them."
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def built_gem_path
|
90
|
-
Dir[File.join(base, "#{name}-*.gem")].sort_by{|f| File.mtime(f)}.last
|
91
|
-
end
|
92
|
-
|
93
|
-
def git_push
|
94
|
-
perform_git_push
|
95
|
-
perform_git_push ' --tags'
|
96
|
-
Bundler.ui.confirm "Pushed git commits and tags."
|
97
|
-
end
|
98
|
-
|
99
|
-
def perform_git_push(options = '')
|
100
|
-
cmd = "git push #{options}"
|
101
|
-
out, code = sh_with_code(cmd)
|
102
|
-
raise "Couldn't git push. `#{cmd}' failed with the following output:\n\n#{out}\n" unless code == 0
|
103
|
-
end
|
104
|
-
|
105
|
-
def already_tagged?
|
106
|
-
if sh('git tag').split(/\n/).include?(version_tag)
|
107
|
-
Bundler.ui.confirm "Tag #{version_tag} has already been created."
|
108
|
-
true
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def guard_clean
|
113
|
-
clean? && committed? or raise("There are files that need to be committed first.")
|
114
|
-
end
|
115
|
-
|
116
|
-
def clean?
|
117
|
-
sh_with_code("git diff --exit-code")[1] == 0
|
118
|
-
end
|
119
|
-
|
120
|
-
def committed?
|
121
|
-
sh_with_code("git diff-index --quiet --cached HEAD")[1] == 0
|
122
|
-
end
|
123
|
-
|
124
|
-
def tag_version
|
125
|
-
sh "git tag -a -m \"Version #{version}\" #{version_tag}"
|
126
|
-
Bundler.ui.confirm "Tagged #{version_tag}."
|
127
|
-
yield if block_given?
|
128
|
-
rescue
|
129
|
-
Bundler.ui.error "Untagging #{version_tag} due to error."
|
130
|
-
sh_with_code "git tag -d #{version_tag}"
|
131
|
-
raise
|
132
|
-
end
|
133
|
-
|
134
|
-
def version
|
135
|
-
gemspec.version
|
136
|
-
end
|
137
|
-
|
138
|
-
def version_tag
|
139
|
-
"v#{version}"
|
140
|
-
end
|
141
|
-
|
142
|
-
def name
|
143
|
-
gemspec.name
|
144
|
-
end
|
145
|
-
|
146
|
-
def sh(cmd, &block)
|
147
|
-
out, code = sh_with_code(cmd, &block)
|
148
|
-
code == 0 ? out : raise(out.empty? ? "Running `#{cmd}' failed. Run this command directly for more detailed output." : out)
|
149
|
-
end
|
150
|
-
|
151
|
-
def sh_with_code(cmd, &block)
|
152
|
-
cmd << " 2>&1"
|
153
|
-
outbuf = ''
|
154
|
-
Bundler.ui.debug(cmd)
|
155
|
-
Dir.chdir(base) {
|
156
|
-
outbuf = `#{cmd}`
|
157
|
-
if $? == 0
|
158
|
-
block.call(outbuf) if block
|
159
|
-
end
|
160
|
-
}
|
161
|
-
[outbuf, $?]
|
162
|
-
end
|
163
|
-
|
164
|
-
def gem_push?
|
165
|
-
! %w{n no nil false off 0}.include?(ENV['gem_push'].to_s.downcase)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
Bundler::GemHelper.install_tasks
|
1
|
+
require "bundler/gem_tasks"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
@@ -1,23 +1,64 @@
|
|
1
1
|
module Kernel
|
2
2
|
|
3
3
|
# load meta-s
|
4
|
-
def meta_load
|
5
|
-
|
4
|
+
def meta_load(app_folder= Dir.pwd)
|
6
5
|
# find elements
|
7
6
|
begin
|
8
|
-
Dir.glob( File.join(
|
7
|
+
Dir.glob( File.join(app_folder, "lib", "**","meta" ,"*.{rb,ru}") ).each do |one_rb_file|
|
9
8
|
require one_rb_file
|
10
9
|
end
|
11
10
|
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_meta_config(app_folder= Dir.pwd)
|
14
|
+
|
15
|
+
# defaults
|
16
|
+
begin
|
17
|
+
require "yaml"
|
18
|
+
target_config_hash= Hash.new()
|
19
|
+
end
|
20
|
+
|
21
|
+
# find elements
|
22
|
+
begin
|
23
|
+
|
24
|
+
Dir.glob(File.join(app_folder, "lib", "**","meta" ,"*.{yaml,yml}")).each do |config_object|
|
25
|
+
|
26
|
+
# defaults
|
27
|
+
begin
|
28
|
+
config_name_elements= config_object.split(File::SEPARATOR)
|
29
|
+
type= config_name_elements.pop.split('.')[0]
|
30
|
+
config_name_elements.pop
|
31
|
+
category= config_name_elements.pop
|
32
|
+
tmp_hash= Hash.new()
|
33
|
+
yaml_data= YAML.load(File.open(config_object))
|
34
|
+
end
|
35
|
+
|
36
|
+
# processing
|
37
|
+
begin
|
38
|
+
if target_config_hash[category].nil?
|
39
|
+
target_config_hash[category]= { type => yaml_data }
|
40
|
+
else
|
41
|
+
target_config_hash[category][type]= yaml_data
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
# return data
|
50
|
+
begin
|
51
|
+
return target_config_hash
|
52
|
+
end
|
12
53
|
|
13
54
|
end
|
14
55
|
|
15
56
|
# mount libs
|
16
|
-
def mount_libs
|
57
|
+
def mount_libs(app_folder= Dir.pwd)
|
17
58
|
|
18
59
|
# load lib files
|
19
60
|
begin
|
20
|
-
Dir.glob(File.join(
|
61
|
+
Dir.glob(File.join(app_folder, "lib","*.{rb,ru}")).uniq.each do |one_rb_file|
|
21
62
|
require one_rb_file
|
22
63
|
end
|
23
64
|
end
|
@@ -25,9 +66,9 @@ module Kernel
|
|
25
66
|
end
|
26
67
|
|
27
68
|
# Offline repo activate
|
28
|
-
def mount_modules
|
69
|
+
def mount_modules(app_folder= Dir.pwd)
|
29
70
|
|
30
|
-
Dir.glob(File.join(
|
71
|
+
Dir.glob(File.join(app_folder, "{module,modules}","{gem,gems}","**","lib")).select{|f| File.directory?(f)}.each do |one_path|
|
31
72
|
$LOAD_PATH << one_path
|
32
73
|
end
|
33
74
|
|
@@ -117,7 +158,7 @@ module Kernel
|
|
117
158
|
end
|
118
159
|
|
119
160
|
# generate config from yaml
|
120
|
-
def generate_config(target_config_hash= Application.config)
|
161
|
+
def generate_config(target_config_hash= Application.config,app_folder= Dir.pwd)
|
121
162
|
|
122
163
|
# defaults
|
123
164
|
begin
|
@@ -130,7 +171,7 @@ module Kernel
|
|
130
171
|
# find elements
|
131
172
|
begin
|
132
173
|
|
133
|
-
Dir.glob(File.join(
|
174
|
+
Dir.glob(File.join(app_folder, "lib", "**","meta" ,"*.{yaml,yml}")).each do |config_object|
|
134
175
|
|
135
176
|
# defaults
|
136
177
|
begin
|
@@ -161,7 +202,7 @@ module Kernel
|
|
161
202
|
# get config files
|
162
203
|
begin
|
163
204
|
config_yaml_paths= Array.new()
|
164
|
-
Dir.glob(File.join(
|
205
|
+
Dir.glob(File.join(app_folder, "{config,conf}","*.{yaml,yml}")).uniq.each do |one_path|
|
165
206
|
|
166
207
|
case true
|
167
208
|
|
@@ -218,12 +259,12 @@ module Kernel
|
|
218
259
|
|
219
260
|
end
|
220
261
|
|
221
|
-
def generate_documentation(boolean= false,keyword= "generate")
|
262
|
+
def generate_documentation(boolean= false,keyword= "generate",app_folder= Dir.pwd)
|
222
263
|
boolean= false if boolean.nil?
|
223
264
|
if boolean == true
|
224
265
|
|
225
266
|
document_generators= Array.new
|
226
|
-
tmp_path_container= Dir.glob(File.join(
|
267
|
+
tmp_path_container= Dir.glob(File.join(app_folder, "docs", "**", "*.{rb,ru}"))
|
227
268
|
tmp_path_container.each do |one_path|
|
228
269
|
if one_path.include? keyword
|
229
270
|
document_generators.push one_path
|
@@ -31,9 +31,19 @@ class Array
|
|
31
31
|
return hash[target_element]
|
32
32
|
end
|
33
33
|
|
34
|
-
# remove n. element
|
34
|
+
# remove n. element from the end
|
35
|
+
# and return a new object
|
35
36
|
def pinch n=1
|
36
|
-
return self[0..(self.count-
|
37
|
+
return self[0..(self.count-(n+1))]
|
38
|
+
end
|
39
|
+
|
40
|
+
# remove n. element from the end
|
41
|
+
# and return the original object
|
42
|
+
def pinch! n=1
|
43
|
+
n.times do
|
44
|
+
self.pop
|
45
|
+
end
|
46
|
+
return self
|
37
47
|
end
|
38
48
|
|
39
49
|
# return boolean by other array
|
@@ -165,6 +165,85 @@ class Object
|
|
165
165
|
|
166
166
|
end
|
167
167
|
|
168
|
+
# this will check that the class is
|
169
|
+
# defined or not in the runtime memory
|
170
|
+
def class_exists?
|
171
|
+
klass = Module.const_get(self)
|
172
|
+
return klass.is_a?(Class)
|
173
|
+
rescue NameError
|
174
|
+
return false
|
175
|
+
end
|
176
|
+
|
177
|
+
# This will convert a symbol or string and format to be a valid
|
178
|
+
# constant name and create from it a class with instance attribute accessors
|
179
|
+
# Best use is when you get raw data in string from external source
|
180
|
+
# and you want make them class objects
|
181
|
+
#
|
182
|
+
# :hello_world.to_class(:test)
|
183
|
+
# HelloWorld.to_class(:sup)
|
184
|
+
# hw_var = HelloWorld.new
|
185
|
+
# hw_var.sup = "Fine thanks!"
|
186
|
+
# hw_var.test = 5
|
187
|
+
#
|
188
|
+
# puts hw_var.test
|
189
|
+
#
|
190
|
+
# #> produce 5 :Integer
|
191
|
+
#
|
192
|
+
# you can also use this formats
|
193
|
+
# :HelloWorld , "hello.world",
|
194
|
+
# "hello/world", "Hello::World",
|
195
|
+
# "hello:world"...
|
196
|
+
def to_class(*attributes) #name
|
197
|
+
|
198
|
+
unless self.class == Symbol || self.class == String || self.class == Class
|
199
|
+
raise ArgumentError, "object must be symbol or string to make able build class to it"
|
200
|
+
end
|
201
|
+
|
202
|
+
class_name= self.to_s
|
203
|
+
|
204
|
+
unless self.class == Class
|
205
|
+
|
206
|
+
class_name= class_name[0].upcase+class_name[1..class_name.length]
|
207
|
+
%w[ _ . : / ].each do |one_sym|
|
208
|
+
|
209
|
+
#sym_length= one_sym.length
|
210
|
+
loop do
|
211
|
+
index_nmb= class_name.index(one_sym)
|
212
|
+
break if index_nmb.nil?
|
213
|
+
class_name[index_nmb..index_nmb+1]= class_name[index_nmb+1].upcase
|
214
|
+
end
|
215
|
+
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
create_attribute = Proc.new do |*args|
|
221
|
+
|
222
|
+
end
|
223
|
+
|
224
|
+
unless class_name.class_exists?
|
225
|
+
|
226
|
+
Object.const_set(
|
227
|
+
class_name,
|
228
|
+
Class.new
|
229
|
+
)
|
230
|
+
|
231
|
+
end
|
232
|
+
|
233
|
+
|
234
|
+
class_name.constantize.class_eval do
|
235
|
+
attributes.each do |one_attribute|
|
236
|
+
attr_accessor one_attribute.to_s.to_sym
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
|
241
|
+
|
242
|
+
return true
|
243
|
+
|
244
|
+
end
|
245
|
+
|
246
|
+
alias :create_attributes :to_class
|
168
247
|
alias :map_sample :map_object
|
169
248
|
alias :each_univ :each_universal
|
170
249
|
alias :fnr :find_and_replace
|
data/procemon.gemspec
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
#lib = File.expand_path('../lib', __FILE__)
|
4
|
-
#$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
|
6
3
|
### Get Files from dir
|
7
4
|
begin
|
8
5
|
|
@@ -30,10 +27,10 @@ end
|
|
30
27
|
Gem::Specification.new do |spec|
|
31
28
|
|
32
29
|
spec.name = "procemon"
|
33
|
-
spec.version = File.open(File.join(File.dirname(__FILE__),"VERSION")).read.chomp
|
30
|
+
spec.version = File.open(File.join(File.dirname(__FILE__),"VERSION")).read.split("\n")[0].chomp.gsub(' ','')
|
34
31
|
spec.authors = ["Adam Luzsi"]
|
35
32
|
spec.email = ["adamluzsi@gmail.com"]
|
36
|
-
spec.description = %q{This is a collection of my Ruby Procs in the adventure of becoming the best!}
|
33
|
+
spec.description = %q{This is a collection of my Ruby Procs in the adventure of becoming the best! This is including Tons of monkey_patch for new features to classes, meta-programing tricks, terminal argument controls, daemonise trick, tmp folder helpers, Application centralized datas, folder structure logic , meta data control, dynamic lib read etc}
|
37
34
|
spec.summary = %q{Gotta catch em all!}
|
38
35
|
spec.homepage = "https://github.com/adamluzsi/procemon"
|
39
36
|
spec.license = "MIT"
|
data/test/bump/test2.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
puts "hello world"
|
data/test/test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: procemon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,10 +9,13 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
12
|
+
date: 2013-10-19 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: This is a collection of my Ruby Procs in the adventure of becoming the
|
15
|
-
best!
|
15
|
+
best! This is including Tons of monkey_patch for new features to classes, meta-programing
|
16
|
+
tricks, terminal argument controls, daemonise trick, tmp folder helpers, Application
|
17
|
+
centralized datas, folder structure logic , meta data control, dynamic lib read
|
18
|
+
etc
|
16
19
|
email:
|
17
20
|
- adamluzsi@gmail.com
|
18
21
|
executables: []
|
@@ -23,7 +26,6 @@ files:
|
|
23
26
|
- Gemfile.lock
|
24
27
|
- LICENSE.txt
|
25
28
|
- README.md
|
26
|
-
- README.rdoc
|
27
29
|
- Rakefile
|
28
30
|
- VERSION
|
29
31
|
- dump/macaddr.rb
|
@@ -53,6 +55,7 @@ files:
|
|
53
55
|
- lib/procemon/mpatch/string.rb
|
54
56
|
- lib/procemon/mpatch/yml.rb
|
55
57
|
- procemon.gemspec
|
58
|
+
- test/bump/test2.rb
|
56
59
|
- test/test.rb
|
57
60
|
homepage: https://github.com/adamluzsi/procemon
|
58
61
|
licenses:
|
@@ -69,7 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
72
|
version: '0'
|
70
73
|
segments:
|
71
74
|
- 0
|
72
|
-
hash:
|
75
|
+
hash: 2972704028512550261
|
73
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
77
|
none: false
|
75
78
|
requirements:
|
@@ -83,4 +86,5 @@ signing_key:
|
|
83
86
|
specification_version: 3
|
84
87
|
summary: Gotta catch em all!
|
85
88
|
test_files:
|
89
|
+
- test/bump/test2.rb
|
86
90
|
- test/test.rb
|
data/README.rdoc
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
= procemon
|
2
|
-
|
3
|
-
Description goes here.
|
4
|
-
|
5
|
-
== Contributing to procemon
|
6
|
-
|
7
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
-
* Fork the project.
|
10
|
-
* Start a feature/bugfix branch.
|
11
|
-
* Commit and push until you are happy with your contribution.
|
12
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
-
|
15
|
-
== Copyright
|
16
|
-
|
17
|
-
Copyright (c) 2013 Adam Luzsi. See LICENSE.txt for
|
18
|
-
further details.
|
19
|
-
|