bgem 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bgem.rb +42 -33
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ed05b7d214f5a77ec8095c02fafed93a5d0b748
4
- data.tar.gz: 19df71a50194389b49c4dd121e2b1e9ffcfe3afa
3
+ metadata.gz: a70b7967fc8d90e3bcc7532b61bfca8853acd161
4
+ data.tar.gz: 0c01f06e669f2a09d1fa22d683f64b006b707288
5
5
  SHA512:
6
- metadata.gz: 03131c1b4ff6f1ecd9e6dc726b3e5c2cda2a3467007ac30d31e40db8619ad7322f6d47d7ddf75653e3b7e66558e657c3266ce7b96ba2dc87ccf26ef3377b4831
7
- data.tar.gz: cf4ac4b56db04f9bcd868101ba991b97a6fe3c43ee5b732716acc18abf06bca4865a03b2480a81fb5c913045fba4c1c8d0406f82e1800c504adae37cdfbab162
6
+ metadata.gz: c740b22218e8e13d3ae22c292258982a706348859433a8cba36d9e0fd3504ee75d969a7823756cbfd10794fcdb12267e23ea5c96eb0181620aa2487274e0a3a8
7
+ data.tar.gz: 663f242e757c4b0144ef346c36c7e39c5b7e5e8f82fda4da43f2a106d8ff92c86a937f275d7e75a7560cdc333bba118c992e84bb3b8e1bccbd74a59fe0562dbf
@@ -12,39 +12,6 @@ module Bgem
12
12
  INDENT = 2
13
13
  SOURCE_FILE = Dir['src/*.rb'][0]
14
14
 
15
- class SourceFile
16
- def initialize file = SOURCE_FILE, indent: 0
17
- @file, @indent = (Pathname file), indent
18
- @source = @file.read
19
- @constant, @type, _rb = @file.basename.to_s.split '.'
20
- end
21
-
22
- def to_s
23
- "#{@type} #{@constant}\n#{source}end".indent @indent
24
- end
25
-
26
- private
27
- def source
28
- source = @source.indent INDENT
29
- source.prepend "#{before}\n\n" unless before.empty?
30
- source.concat "\n#{after}\n" unless after.empty?
31
- source
32
- end
33
-
34
- def self.concatenate_source_files *symbols
35
- symbols.each do |symbol|
36
- define_method symbol do
37
- pattern = @file.dirname.join "#{__method__}.#{@constant}/*.rb"
38
- Pathname.glob(pattern).map do |file|
39
- self.class.new(file, indent: INDENT).to_s
40
- end.join "\n\n"
41
- end
42
- end
43
- end
44
-
45
- concatenate_source_files :before, :after
46
- end
47
-
48
15
  module CLI
49
16
  def self.run
50
17
  options = parse_argv
@@ -78,4 +45,46 @@ module Bgem
78
45
  @path.write string
79
46
  end
80
47
  end
48
+
49
+ class SourceFile
50
+ def initialize file = SOURCE_FILE, indent: 0
51
+ @file, @indent = (Pathname file), indent
52
+ @source = @file.read
53
+ head, @type, _rb = @file.basename.to_s.split '.'
54
+ @constant, _colon, @ancestor = head.partition ':'
55
+ end
56
+
57
+ def to_s
58
+ "#{head}#{source}end".indent @indent
59
+ end
60
+
61
+ private
62
+ def head
63
+ if @ancestor.empty?
64
+ "#{@type} #{@constant}\n"
65
+ else
66
+ "#{@type} #{@constant} < #{@ancestor}\n"
67
+ end
68
+ end
69
+
70
+ def source
71
+ source = @source.indent INDENT
72
+ source.prepend "#{before}\n\n" unless before.empty?
73
+ source.concat "\n#{after}\n" unless after.empty?
74
+ source
75
+ end
76
+
77
+ def self.concatenate_source_files *symbols
78
+ symbols.each do |symbol|
79
+ define_method symbol do
80
+ pattern = @file.dirname.join "#{__method__}.#{@constant}/*.rb"
81
+ Pathname.glob(pattern).map do |file|
82
+ self.class.new(file, indent: INDENT).to_s
83
+ end.join "\n\n"
84
+ end
85
+ end
86
+ end
87
+
88
+ concatenate_source_files :before, :after
89
+ end
81
90
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bgem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoly Chernow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-07 00:00:00.000000000 Z
11
+ date: 2017-01-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: