rubygoods 0.0.0.12 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fdaa8e681f76bd55ddc4e17a258027c993a16fee
4
- data.tar.gz: 41cfe126148d0d689b8a1e04142fb6199562ff03
3
+ metadata.gz: 8c390e17b33a0641a769a0684b70ca3f3d1b4f29
4
+ data.tar.gz: 0c46ca5fe92f46f963a16e3ee8297475cc511cdf
5
5
  SHA512:
6
- metadata.gz: d610fcdf7a45bec1eea3fd5a335b3e59657ce7be28e2908a4b6b59fc400d018779cda7befd0fa9ec2eecd3340d89e2498389c1c683d7fbd53e662dc790d189e6
7
- data.tar.gz: c4281e2d1cd0640700af3a8297846fb857ccd7618856135e829366b0f7a1d77b0a5a3fae83a4599146c9696f8d2c37b423596b07280eb8d93d30ecdf5f362952
6
+ metadata.gz: '094b463d59815b69fde2722c5f2af87c02bc645b95d5e3ad9092ef667735b1d9e3ca41386c53b38579f8cf368433e66628ca2d9591918ed71ad97572adccf77a'
7
+ data.tar.gz: 7efce29a2576e508bb54690e013696fca89fe8313b9fa22c66773d64fd353743ea4f47c17743c33e65b489cca9bb8ba8307cb7dbc67351aa88309e52fa03de2e
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Rubygoods
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rubygoods`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Some utils for Ruby
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,18 +20,26 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
26
-
27
- ## Development
23
+ This library includes:
28
24
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
25
+ 1. Some kind of logger
26
+ 2. Shortcut for gem-version getter
27
+ 3. Multi-Class Proxy
28
+ 4. `RG::Utils.notnil` method which returns `false` if ANY argument is `nil` and true in all other cases
29
+ 5. Some anti-code-inject utils
30
30
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
31
+ ## Proxy
32
32
 
33
- ## Contributing
33
+ Syntax for proxies is simple:
34
34
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rubygoods. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
35
+ ```ruby
36
+ p = RG::Proxy.new :multiple, [[1,2,3],[4,5,6]] # :multiple mode takes array of objects with same class
37
+ p.sum # => [6, 15] # All unknown methods are redirected to stored objects
36
38
 
39
+ # Instance Evals and Inspects
40
+ p.p_eval "self.sum" # => [6, 15] # Proxy#p_eval calls `instance_eval` method for each object
41
+ p.p_inspect # => ["[1,2,3]","[4,5,6]"] # You see
42
+ ```
37
43
 
38
44
  ## License
39
45
 
@@ -1,4 +1,5 @@
1
1
  require "rubygoods/version"
2
2
  require "rubygoods/log"
3
3
  require "rubygoods/string"
4
- require "rubygoods/utils"
4
+ require "rubygoods/utils"
5
+ require "rubygoods/proxy"
@@ -1,6 +1,8 @@
1
1
  require "date"
2
2
  require "rainbow"
3
3
 
4
+ $RG_LOG_LEVEL = :info
5
+
4
6
  module RG
5
7
  module Log
6
8
  def self._queue
@@ -8,6 +10,7 @@ module RG
8
10
  Thread.new do
9
11
  loop do
10
12
  puts @queue.pop
13
+ sleep 0.01
11
14
  end
12
15
  end
13
16
  end
@@ -16,18 +19,33 @@ module RG
16
19
  @queue << msg
17
20
  end
18
21
 
19
- def self.write(input, ln=true, color=true)
22
+ def self.write(input, ln=true, color=true, code=1)
23
+ case $RG_LOG_LEVEL
24
+ when :info
25
+ self.info input, ln, color
26
+ when :warn
27
+ self.warn input, ln, color
28
+ when :err
29
+ self.err input, ln, color
30
+ when :crash
31
+ self.crash input, code, ln, color
32
+ else
33
+ self.err "Wrong logger-level!"
34
+ end
35
+ end
36
+
37
+ def self.info(input, ln=true, color=true)
20
38
  msg = input.to_s
21
39
 
22
40
  datencstr = "%d.%m.%Y|%H:%M:%S"
23
41
  datestr = if color
24
- Rainbow("%d").green.underline + Rainbow(".").cyan.underline +
25
- Rainbow("%m").green.underline + Rainbow(".").cyan.underline +
26
- Rainbow("%Y").green.underline +
27
- Rainbow("|").cyan.underline +
28
- Rainbow("%H").green.underline + Rainbow(":").cyan.underline +
29
- Rainbow("%M").green.underline + Rainbow(":").cyan.underline +
30
- Rainbow("%S").green.underline
42
+ Rainbow("%d").green + Rainbow(".").cyan +
43
+ Rainbow("%m").green + Rainbow(".").cyan +
44
+ Rainbow("%Y").green +
45
+ Rainbow("|").cyan +
46
+ Rainbow("%H").green + Rainbow(":").cyan +
47
+ Rainbow("%M").green + Rainbow(":").cyan +
48
+ Rainbow("%S").green
31
49
  else
32
50
  datencstr
33
51
  end
@@ -36,9 +54,9 @@ module RG
36
54
  dateout = date.strftime datestr
37
55
  datencout = date.strftime datencstr
38
56
  out = if color
39
- Rainbow("[").cyan.underline +
57
+ Rainbow("[").cyan +
40
58
  dateout +
41
- Rainbow("]").cyan.underline + Rainbow("-> ").green.underline +
59
+ Rainbow("]").cyan + Rainbow("-> ").green +
42
60
  msg
43
61
  else
44
62
  "[" + datencout + "]-> " + msg
@@ -57,13 +75,13 @@ module RG
57
75
 
58
76
  datencstr = "%d.%m.%Y|%H:%M:%S"
59
77
  datestr = if color
60
- Rainbow("%d").orange.underline + Rainbow(".").red.underline +
61
- Rainbow("%m").orange.underline + Rainbow(".").red.underline +
62
- Rainbow("%Y").orange.underline +
63
- Rainbow("|").red.underline +
64
- Rainbow("%H").orange.underline + Rainbow(":").red.underline +
65
- Rainbow("%M").orange.underline + Rainbow(":").red.underline +
66
- Rainbow("%S").orange.underline
78
+ Rainbow("%d").orange + Rainbow(".").red +
79
+ Rainbow("%m").orange + Rainbow(".").red +
80
+ Rainbow("%Y").orange +
81
+ Rainbow("|").red +
82
+ Rainbow("%H").orange + Rainbow(":").red +
83
+ Rainbow("%M").orange + Rainbow(":").red +
84
+ Rainbow("%S").orange
67
85
  else
68
86
  datencstr
69
87
  end
@@ -72,9 +90,9 @@ module RG
72
90
  dateout = date.strftime datestr
73
91
  datencout = date.strftime datencstr
74
92
  out = if color
75
- Rainbow("[").red.underline +
93
+ Rainbow("[").red +
76
94
  dateout +
77
- Rainbow("]").red.underline + Rainbow("WARN> ").orange.underline +
95
+ Rainbow("]").red + Rainbow("WARN> ").orange +
78
96
  msg
79
97
  else
80
98
  "[" + datencout + "]WARN>" + " " + msg
@@ -93,13 +111,13 @@ module RG
93
111
 
94
112
  datencstr = "%d.%m.%Y|%H:%M:%S"
95
113
  datestr = if color
96
- Rainbow("%d").red.underline + Rainbow(".").orange.underline +
97
- Rainbow("%m").red.underline + Rainbow(".").orange.underline +
98
- Rainbow("%Y").red.underline +
99
- Rainbow("|").orange.underline +
100
- Rainbow("%H").red.underline + Rainbow(":").orange.underline +
101
- Rainbow("%M").red.underline + Rainbow(":").orange.underline +
102
- Rainbow("%S").red.underline
114
+ Rainbow("%d").red + Rainbow(".").orange +
115
+ Rainbow("%m").red + Rainbow(".").orange +
116
+ Rainbow("%Y").red +
117
+ Rainbow("|").orange +
118
+ Rainbow("%H").red + Rainbow(":").orange +
119
+ Rainbow("%M").red + Rainbow(":").orange +
120
+ Rainbow("%S").red
103
121
  else
104
122
  datencstr
105
123
  end
@@ -108,9 +126,9 @@ module RG
108
126
  dateout = date.strftime datestr
109
127
  datencout = date.strftime datencstr
110
128
  out = if color
111
- Rainbow("[").orange.underline +
129
+ Rainbow("[").orange +
112
130
  dateout +
113
- Rainbow("]").orange.underline + Rainbow("ERR> ").red.underline +
131
+ Rainbow("]").orange + Rainbow("ERR> ").red +
114
132
  msg
115
133
  else
116
134
  "[" + datencout + "]ERR> " + msg
@@ -129,13 +147,13 @@ module RG
129
147
 
130
148
  datencstr = "%d.%m.%Y|%H:%M:%S"
131
149
  datestr = if color
132
- Rainbow("%d").magenta.underline + Rainbow(".").red.underline +
133
- Rainbow("%m").magenta.underline + Rainbow(".").red.underline +
134
- Rainbow("%Y").magenta.underline +
135
- Rainbow("|").red.underline +
136
- Rainbow("%H").magenta.underline + Rainbow(":").red.underline +
137
- Rainbow("%M").magenta.underline + Rainbow(":").red.underline +
138
- Rainbow("%S").magenta.underline
150
+ Rainbow("%d").magenta + Rainbow(".").red +
151
+ Rainbow("%m").magenta + Rainbow(".").red +
152
+ Rainbow("%Y").magenta +
153
+ Rainbow("|").red +
154
+ Rainbow("%H").magenta + Rainbow(":").red +
155
+ Rainbow("%M").magenta + Rainbow(":").red +
156
+ Rainbow("%S").magenta
139
157
  else
140
158
  datencstr
141
159
  end
@@ -144,9 +162,9 @@ module RG
144
162
  dateout = date.strftime datestr
145
163
  datencout = date.strftime datencstr
146
164
  out = if color
147
- Rainbow("[").red.underline +
165
+ Rainbow("[").red +
148
166
  dateout +
149
- Rainbow("]").red.underline + Rainbow("CRASH> ").magenta.underline +
167
+ Rainbow("]").red + Rainbow("CRASH> ").magenta +
150
168
  msg
151
169
  else
152
170
  "[" + datencout + "]CRASH>" + " " + msg
@@ -0,0 +1,53 @@
1
+ module RG
2
+ class Proxy
3
+ attr_reader :objs
4
+
5
+ def initialize(mode, objs)
6
+ case mode
7
+ when :single
8
+ p_init_single(objs)
9
+ when :multiple
10
+ p_init_multiple(objs)
11
+ else
12
+ fail ArgumentError, "Invalid mode"
13
+ end
14
+ end
15
+
16
+ def p_init_single(obj)
17
+ @objs = [obj]
18
+ end
19
+
20
+ def p_init_multiple(objs)
21
+ init_single(objs) if objs.class != Array
22
+ @objs = objs
23
+ cl = @objs[0].class
24
+ @objs.each do |o|
25
+ fail(ArgumentError, "Objects' Classes are not same!") if (o.class != cl)
26
+ end
27
+ end
28
+
29
+ def method_missing(m, *args, &block)
30
+ results = []
31
+ @objs.each do |o|
32
+ results << o.send(m, *args, &block)
33
+ end
34
+ results
35
+ end
36
+
37
+ def p_eval(dat)
38
+ results = []
39
+ @objs.each do |o|
40
+ results << o.instance_eval(dat)
41
+ end
42
+ results
43
+ end
44
+
45
+ def p_inspect()
46
+ results = []
47
+ @objs.each do |o|
48
+ results << o.inspect
49
+ end
50
+ results
51
+ end
52
+ end
53
+ end
@@ -1,7 +1,7 @@
1
1
  module RG
2
- VERSION = "0.0.0.12"
2
+ VERSION = "0.0.1"
3
3
 
4
4
  def self.getgemver(name)
5
5
  Gem.loaded_specs[name].version.version
6
6
  end
7
- end
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubygoods
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.12
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nickolay Ilyushin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-09 00:00:00.000000000 Z
11
+ date: 2017-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -65,11 +65,11 @@ files:
65
65
  - LICENSE.txt
66
66
  - README.md
67
67
  - Rakefile
68
- - TODO
69
68
  - bin/console
70
69
  - bin/setup
71
70
  - lib/rubygoods.rb
72
71
  - lib/rubygoods/log.rb
72
+ - lib/rubygoods/proxy.rb
73
73
  - lib/rubygoods/string.rb
74
74
  - lib/rubygoods/utils.rb
75
75
  - lib/rubygoods/version.rb
data/TODO DELETED
@@ -1 +0,0 @@
1
- Stop creating weird errors, handi...