kamaze-project 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +18 -0
- data/bin/plop +5 -0
- data/lib/kamaze-project.rb +39 -0
- data/lib/kamaze/project.rb +155 -0
- data/lib/kamaze/project/boot/core_ext.rb +16 -0
- data/lib/kamaze/project/boot/listen.rb +38 -0
- data/lib/kamaze/project/concern.rb +13 -0
- data/lib/kamaze/project/concern/cli.rb +53 -0
- data/lib/kamaze/project/concern/cli/with_exit_on_failure.rb +36 -0
- data/lib/kamaze/project/concern/env.rb +63 -0
- data/lib/kamaze/project/concern/helper.rb +20 -0
- data/lib/kamaze/project/concern/mode.rb +19 -0
- data/lib/kamaze/project/concern/observable.rb +132 -0
- data/lib/kamaze/project/concern/sh.rb +91 -0
- data/lib/kamaze/project/concern/tasks.rb +55 -0
- data/lib/kamaze/project/concern/tools.rb +27 -0
- data/lib/kamaze/project/config.rb +58 -0
- data/lib/kamaze/project/core_ext/object.rb +27 -0
- data/lib/kamaze/project/core_ext/pp.rb +28 -0
- data/lib/kamaze/project/debug.rb +136 -0
- data/lib/kamaze/project/dsl.rb +16 -0
- data/lib/kamaze/project/dsl/definition.rb +43 -0
- data/lib/kamaze/project/dsl/setup.rb +11 -0
- data/lib/kamaze/project/helper.rb +63 -0
- data/lib/kamaze/project/helper/inflector.rb +44 -0
- data/lib/kamaze/project/helper/project.rb +34 -0
- data/lib/kamaze/project/helper/project/config.rb +25 -0
- data/lib/kamaze/project/observable.rb +20 -0
- data/lib/kamaze/project/observer.rb +37 -0
- data/lib/kamaze/project/resources/Vagrantfile +128 -0
- data/lib/kamaze/project/resources/config/tools.yml +15 -0
- data/lib/kamaze/project/struct.rb +34 -0
- data/lib/kamaze/project/tasks/cs.rb +23 -0
- data/lib/kamaze/project/tasks/cs/control.rb +17 -0
- data/lib/kamaze/project/tasks/cs/correct.rb +17 -0
- data/lib/kamaze/project/tasks/cs/pre_commit.rb +66 -0
- data/lib/kamaze/project/tasks/doc.rb +21 -0
- data/lib/kamaze/project/tasks/doc/watch.rb +41 -0
- data/lib/kamaze/project/tasks/gem.rb +14 -0
- data/lib/kamaze/project/tasks/gem/build.rb +34 -0
- data/lib/kamaze/project/tasks/gem/compile.rb +30 -0
- data/lib/kamaze/project/tasks/gem/gemspec.rb +20 -0
- data/lib/kamaze/project/tasks/gem/install.rb +32 -0
- data/lib/kamaze/project/tasks/gem/push.rb +27 -0
- data/lib/kamaze/project/tasks/misc/gitignore.rb +29 -0
- data/lib/kamaze/project/tasks/shell.rb +17 -0
- data/lib/kamaze/project/tasks/sources.rb +6 -0
- data/lib/kamaze/project/tasks/sources/license.rb +35 -0
- data/lib/kamaze/project/tasks/test.rb +16 -0
- data/lib/kamaze/project/tasks/vagrant.rb +71 -0
- data/lib/kamaze/project/tasks/version/edit.rb +16 -0
- data/lib/kamaze/project/tools.rb +18 -0
- data/lib/kamaze/project/tools/base_tool.rb +55 -0
- data/lib/kamaze/project/tools/console.rb +48 -0
- data/lib/kamaze/project/tools/console/output.rb +120 -0
- data/lib/kamaze/project/tools/console/output/buffer.rb +48 -0
- data/lib/kamaze/project/tools/gemspec.rb +33 -0
- data/lib/kamaze/project/tools/gemspec/builder.rb +99 -0
- data/lib/kamaze/project/tools/gemspec/concern.rb +13 -0
- data/lib/kamaze/project/tools/gemspec/concern/reading.rb +49 -0
- data/lib/kamaze/project/tools/gemspec/packager.rb +67 -0
- data/lib/kamaze/project/tools/gemspec/packer.rb +89 -0
- data/lib/kamaze/project/tools/gemspec/packer/command.rb +143 -0
- data/lib/kamaze/project/tools/gemspec/reader.rb +70 -0
- data/lib/kamaze/project/tools/gemspec/reader/decorator.rb +78 -0
- data/lib/kamaze/project/tools/gemspec/writer.rb +127 -0
- data/lib/kamaze/project/tools/gemspec/writer/dep_gen.rb +61 -0
- data/lib/kamaze/project/tools/gemspec/writer/dependency.rb +104 -0
- data/lib/kamaze/project/tools/git.rb +95 -0
- data/lib/kamaze/project/tools/git/hooks.rb +66 -0
- data/lib/kamaze/project/tools/git/hooks/base_hook.rb +33 -0
- data/lib/kamaze/project/tools/git/hooks/pre_commit.rb +81 -0
- data/lib/kamaze/project/tools/git/status.rb +101 -0
- data/lib/kamaze/project/tools/git/status/decorator.rb +39 -0
- data/lib/kamaze/project/tools/git/status/file.rb +180 -0
- data/lib/kamaze/project/tools/git/status/files_array.rb +39 -0
- data/lib/kamaze/project/tools/git/status/index.rb +77 -0
- data/lib/kamaze/project/tools/git/status/worktree.rb +19 -0
- data/lib/kamaze/project/tools/git/util.rb +35 -0
- data/lib/kamaze/project/tools/licenser.rb +197 -0
- data/lib/kamaze/project/tools/packager.rb +86 -0
- data/lib/kamaze/project/tools/packager/filesystem.rb +178 -0
- data/lib/kamaze/project/tools/packager/filesystem/operator.rb +83 -0
- data/lib/kamaze/project/tools/packager/filesystem/operator/utils.rb +77 -0
- data/lib/kamaze/project/tools/process_locker.rb +106 -0
- data/lib/kamaze/project/tools/rspec.rb +115 -0
- data/lib/kamaze/project/tools/rubocop.rb +128 -0
- data/lib/kamaze/project/tools/rubocop/arguments.rb +19 -0
- data/lib/kamaze/project/tools/rubocop/config.rb +43 -0
- data/lib/kamaze/project/tools/shell.rb +85 -0
- data/lib/kamaze/project/tools/vagrant.rb +182 -0
- data/lib/kamaze/project/tools/vagrant/composer.rb +88 -0
- data/lib/kamaze/project/tools/vagrant/composer/file.rb +79 -0
- data/lib/kamaze/project/tools/vagrant/remote.rb +79 -0
- data/lib/kamaze/project/tools/vagrant/shell.rb +102 -0
- data/lib/kamaze/project/tools/vagrant/writer.rb +81 -0
- data/lib/kamaze/project/tools/yardoc.rb +75 -0
- data/lib/kamaze/project/tools/yardoc/file.rb +55 -0
- data/lib/kamaze/project/tools/yardoc/watchable.rb +70 -0
- data/lib/kamaze/project/tools/yardoc/watcher.rb +106 -0
- data/lib/kamaze/project/tools_provider.rb +161 -0
- data/lib/kamaze/project/tools_provider/resolver.rb +42 -0
- data/lib/kamaze/project/version.rb +104 -0
- data/lib/kamaze/project/version.yml +17 -0
- metadata +321 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
|
4
|
+
# License GPLv3+: GNU GPL version 3 or later
|
5
|
+
# <http://www.gnu.org/licenses/gpl.html>.
|
6
|
+
# This is free software: you are free to change and redistribute it.
|
7
|
+
# There is NO WARRANTY, to the extent permitted by law.
|
8
|
+
|
9
|
+
require_relative '../status'
|
10
|
+
|
11
|
+
# Initialized using an Array representation of status
|
12
|
+
#
|
13
|
+
# A memento is kept.
|
14
|
+
# Given files are filtered by type.
|
15
|
+
#
|
16
|
+
# @abstract
|
17
|
+
class Kamaze::Project::Tools::Git::Status::FilesArray < Array
|
18
|
+
class << self
|
19
|
+
# Get type
|
20
|
+
#
|
21
|
+
# @return [Symbol]
|
22
|
+
attr_reader :type
|
23
|
+
end
|
24
|
+
|
25
|
+
# Initialize using given status array representation
|
26
|
+
#
|
27
|
+
# @param [Array] status
|
28
|
+
def initialize(status)
|
29
|
+
super status.clone
|
30
|
+
.keep_if { |file| file.public_send("#{self.class.type}?") }
|
31
|
+
|
32
|
+
@memento = status.clone.map(&:freeze).freeze
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
# @return [Array]
|
38
|
+
attr_reader :memento
|
39
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
|
4
|
+
# License GPLv3+: GNU GPL version 3 or later
|
5
|
+
# <http://www.gnu.org/licenses/gpl.html>.
|
6
|
+
# This is free software: you are free to change and redistribute it.
|
7
|
+
# There is NO WARRANTY, to the extent permitted by law.
|
8
|
+
|
9
|
+
require_relative 'files_array'
|
10
|
+
require_relative 'worktree'
|
11
|
+
|
12
|
+
# rubocop:disable Style/Documentation
|
13
|
+
|
14
|
+
class Kamaze::Project::Tools::Git::Status
|
15
|
+
class Index < FilesArray
|
16
|
+
@type = :index
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# rubocop:enable Style/Documentation
|
21
|
+
|
22
|
+
# Represent index status
|
23
|
+
class Kamaze::Project::Tools::Git::Status::Index
|
24
|
+
# Denote index is safe
|
25
|
+
#
|
26
|
+
# Unsafe index shares modifications with the worktree,
|
27
|
+
# thus, files SHOULD NOT be naively analyzed,
|
28
|
+
# for example, by running a static code analysis.
|
29
|
+
# Running a static code analysis on unsafe index files
|
30
|
+
# COULD lead to inconsistent results.
|
31
|
+
#
|
32
|
+
# @return [Boolean]
|
33
|
+
def safe?
|
34
|
+
unsafe_files.empty?
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [Boolean]
|
38
|
+
def unsafe?
|
39
|
+
!safe?
|
40
|
+
end
|
41
|
+
|
42
|
+
# Get present files in intersection between index and worktree
|
43
|
+
#
|
44
|
+
# @return [Array<File>]
|
45
|
+
def unsafe_files
|
46
|
+
c = [self, worktree].map do |a|
|
47
|
+
a.map { |f| f.absolute_path.to_s }
|
48
|
+
end.freeze
|
49
|
+
|
50
|
+
self.to_a.keep_if do |f|
|
51
|
+
(c[0] & c[1]).include?(f.absolute_path.to_s)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Get files present in index and considered as safe
|
56
|
+
#
|
57
|
+
# Safe files SHOULD NOT present divergent modifications
|
58
|
+
# between index and worktree. As seen in ``unsafe_files`` only
|
59
|
+
# the modified state is considered.
|
60
|
+
def safe_files
|
61
|
+
unsafe = self.unsafe_files.map { |f| f.absolute_path.to_s }
|
62
|
+
|
63
|
+
self.to_a
|
64
|
+
.reject { |f| unsafe.include?(f.absolute_path.to_s) }
|
65
|
+
end
|
66
|
+
|
67
|
+
protected
|
68
|
+
|
69
|
+
# Get a fresh (not frozen) copy of worktree as seen on initialization
|
70
|
+
#
|
71
|
+
# @return [Kamaze::Project::Tools::Git::Status::Worktree]
|
72
|
+
def worktree
|
73
|
+
memo = Array.new(memento)
|
74
|
+
|
75
|
+
Kamaze::Project::Tools::Git::Status::Worktree.new(memo)
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
|
4
|
+
# License GPLv3+: GNU GPL version 3 or later
|
5
|
+
# <http://www.gnu.org/licenses/gpl.html>.
|
6
|
+
# This is free software: you are free to change and redistribute it.
|
7
|
+
# There is NO WARRANTY, to the extent permitted by law.
|
8
|
+
|
9
|
+
require_relative 'files_array'
|
10
|
+
|
11
|
+
class Kamaze::Project::Tools::Git::Status
|
12
|
+
class Worktree < FilesArray
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Represent worktree status
|
17
|
+
class Kamaze::Project::Tools::Git::Status::Worktree
|
18
|
+
@type = :worktree
|
19
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
|
4
|
+
# License GPLv3+: GNU GPL version 3 or later
|
5
|
+
# <http://www.gnu.org/licenses/gpl.html>.
|
6
|
+
# This is free software: you are free to change and redistribute it.
|
7
|
+
# There is NO WARRANTY, to the extent permitted by law.
|
8
|
+
|
9
|
+
require_relative '../git'
|
10
|
+
|
11
|
+
# Provide base class for utils based on git
|
12
|
+
#
|
13
|
+
# Provide access to the repository
|
14
|
+
# @see http://www.rubydoc.info/github/libgit2/rugged/Rugged/Repository
|
15
|
+
#
|
16
|
+
# @abstract
|
17
|
+
class Kamaze::Project::Tools::Git::Util
|
18
|
+
attr_reader :repository
|
19
|
+
|
20
|
+
# @param [Rugged::Repository] repository
|
21
|
+
def initialize(repository)
|
22
|
+
@repository = repository
|
23
|
+
|
24
|
+
setup
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
# Setup
|
30
|
+
#
|
31
|
+
# Almost used for inheritance
|
32
|
+
def setup
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
|
4
|
+
# License GPLv3+: GNU GPL version 3 or later
|
5
|
+
# <http://www.gnu.org/licenses/gpl.html>.
|
6
|
+
# This is free software: you are free to change and redistribute it.
|
7
|
+
# There is NO WARRANTY, to the extent permitted by law.
|
8
|
+
|
9
|
+
require_relative '../tools'
|
10
|
+
|
11
|
+
# Apply provided license on project files
|
12
|
+
#
|
13
|
+
# Samples of use:
|
14
|
+
#
|
15
|
+
# ```ruby
|
16
|
+
# Licenser.process do |pr|
|
17
|
+
# pr.license = project.version.license_header
|
18
|
+
# pr.patterns = ['bin/*', 'lib/**/**.rb']
|
19
|
+
# end
|
20
|
+
# ```
|
21
|
+
#
|
22
|
+
# ```ruby
|
23
|
+
# Licenser.process do |pr|
|
24
|
+
# pr.files += Dir.glob('bin/*')
|
25
|
+
# end
|
26
|
+
# ```
|
27
|
+
#
|
28
|
+
# Sample of use (with DSL):
|
29
|
+
#
|
30
|
+
# ```ruby
|
31
|
+
# require 'kamaze/project/dsl'
|
32
|
+
# require 'kamaze/project/tools/licenser'
|
33
|
+
#
|
34
|
+
# project do |c|
|
35
|
+
# c.working_dir = "#{__dir__}/.."
|
36
|
+
# c.subject = Kamaze::Project
|
37
|
+
# c.name = 'kamaze-project'
|
38
|
+
# c.tasks = []
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# version = project.subject.const_get('VERSION')
|
42
|
+
# licenser = Kamaze::Project::Tools::Licenser.process do |process|
|
43
|
+
# process.working_dir = project.working_dir
|
44
|
+
# process.license = project.version.license_header
|
45
|
+
# process.patterns = ['bin/*', 'lib/**/**.rb']
|
46
|
+
# process.output = STDOUT
|
47
|
+
# end
|
48
|
+
# ```
|
49
|
+
class Kamaze::Project::Tools::Licenser < Kamaze::Project::Tools::BaseTool
|
50
|
+
# License chapter/header
|
51
|
+
#
|
52
|
+
# @return [String]
|
53
|
+
attr_writer :license
|
54
|
+
|
55
|
+
# Files to be licensed
|
56
|
+
#
|
57
|
+
# @type [Array<String|Pathname>]
|
58
|
+
# @return [Array<Pathname>]
|
59
|
+
attr_writer :files
|
60
|
+
|
61
|
+
# Patterns used to match files
|
62
|
+
#
|
63
|
+
# @return [Array<String>]
|
64
|
+
attr_reader :patterns
|
65
|
+
|
66
|
+
# Where (default is current opened file) to write output
|
67
|
+
#
|
68
|
+
# @return [Pathname|IO|nil]
|
69
|
+
attr_accessor :output
|
70
|
+
|
71
|
+
# @type [String|Pathname]
|
72
|
+
# @return [Pathname]
|
73
|
+
attr_writer :working_dir
|
74
|
+
|
75
|
+
class << self
|
76
|
+
def process(&block)
|
77
|
+
self.new.process(&block)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def initialize
|
82
|
+
yield self if block_given?
|
83
|
+
|
84
|
+
@working_dir ||= Dir.pwd
|
85
|
+
@patterns ||= []
|
86
|
+
@files ||= []
|
87
|
+
@license ||= '' # project.version.license_header
|
88
|
+
end
|
89
|
+
|
90
|
+
# Get working-dir
|
91
|
+
#
|
92
|
+
# @return [Pathname]
|
93
|
+
def working_dir
|
94
|
+
Pathname.new(@working_dir || Dir.pwd).freeze
|
95
|
+
end
|
96
|
+
|
97
|
+
# Set patterns
|
98
|
+
#
|
99
|
+
# @param [Array<String>] patterns
|
100
|
+
def patterns=(patterns)
|
101
|
+
@files ||= []
|
102
|
+
@patterns ||= []
|
103
|
+
|
104
|
+
patterns.each do |pattern|
|
105
|
+
@files += Dir.glob(working_dir.join(pattern))
|
106
|
+
end
|
107
|
+
|
108
|
+
@patterns += patterns
|
109
|
+
end
|
110
|
+
|
111
|
+
# Get files
|
112
|
+
#
|
113
|
+
# @return [Array<Pathname>]
|
114
|
+
def files
|
115
|
+
@files.map { |file| Pathname.new(file) }
|
116
|
+
.delete_if { |file| !file.file? }
|
117
|
+
.delete_if { |file| file.basename.to_s[0] == '.' }
|
118
|
+
.sort.uniq
|
119
|
+
.map(&:realpath)
|
120
|
+
end
|
121
|
+
|
122
|
+
# Get license, formatted (using comments)
|
123
|
+
#
|
124
|
+
# @return [String]
|
125
|
+
def license
|
126
|
+
@license.to_s.gsub(/\n{3}/mi, "\n\n").lines.map do |line|
|
127
|
+
line.chomp!
|
128
|
+
"# #{line}" if line and line[0] != '#'
|
129
|
+
end.join("\n")
|
130
|
+
end
|
131
|
+
|
132
|
+
# Get license regexp
|
133
|
+
#
|
134
|
+
# @return [Regexp]
|
135
|
+
def license_regexp
|
136
|
+
/#{Regexp.quote(license)}/mi
|
137
|
+
end
|
138
|
+
|
139
|
+
# Apply license on processable files
|
140
|
+
#
|
141
|
+
# @return [self]
|
142
|
+
def process
|
143
|
+
yield self if block_given?
|
144
|
+
|
145
|
+
files.each { |file| apply_license(file) }
|
146
|
+
|
147
|
+
self
|
148
|
+
end
|
149
|
+
|
150
|
+
protected
|
151
|
+
|
152
|
+
# Get an index, skipping comments
|
153
|
+
#
|
154
|
+
# @param [Array<String>] lines
|
155
|
+
# @return [Fixnum]
|
156
|
+
def index_lines(lines)
|
157
|
+
index = 0
|
158
|
+
loop do
|
159
|
+
break unless lines[index] and lines[index][0] == '#'
|
160
|
+
|
161
|
+
index += 1
|
162
|
+
end
|
163
|
+
|
164
|
+
index
|
165
|
+
end
|
166
|
+
|
167
|
+
# Apply license on a file
|
168
|
+
#
|
169
|
+
# @param [Pathname] file
|
170
|
+
# @return [Pathname] file
|
171
|
+
def apply_license(file)
|
172
|
+
content = file.read
|
173
|
+
licensable = !content.scan(license_regexp)[0] and !license.strip.empty?
|
174
|
+
output = self.output || file
|
175
|
+
|
176
|
+
if licensable
|
177
|
+
content = license_lines(content.lines).join('')
|
178
|
+
|
179
|
+
output.write(content)
|
180
|
+
end
|
181
|
+
|
182
|
+
file
|
183
|
+
end
|
184
|
+
|
185
|
+
# Apply license on lines
|
186
|
+
#
|
187
|
+
# @param [Array<String>] lines
|
188
|
+
# @return [Array<String>] with license applied
|
189
|
+
def license_lines(lines)
|
190
|
+
index = index_lines(lines)
|
191
|
+
lines = lines.clone
|
192
|
+
|
193
|
+
return lines if index <= 0
|
194
|
+
|
195
|
+
lines[0..index] + license.lines + ["\n"] + lines[index..-1]
|
196
|
+
end
|
197
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
|
4
|
+
# License GPLv3+: GNU GPL version 3 or later
|
5
|
+
# <http://www.gnu.org/licenses/gpl.html>.
|
6
|
+
# This is free software: you are free to change and redistribute it.
|
7
|
+
# There is NO WARRANTY, to the extent permitted by law.
|
8
|
+
|
9
|
+
require_relative '../tools'
|
10
|
+
require_relative 'base_tool'
|
11
|
+
|
12
|
+
# rubocop:disable Style/Documentation
|
13
|
+
|
14
|
+
module Kamaze::Project::Tools
|
15
|
+
class Packager < BaseTool
|
16
|
+
class Filesystem
|
17
|
+
class Operator
|
18
|
+
module Utils
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
require_relative 'packager/filesystem'
|
24
|
+
require_relative 'packager/filesystem/operator'
|
25
|
+
require_relative 'packager/filesystem/operator/utils'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# rubocop:enable Style/Documentation
|
30
|
+
|
31
|
+
# Provides a packager
|
32
|
+
#
|
33
|
+
# Packager is intended to provide basic packaging operations
|
34
|
+
# @abstract
|
35
|
+
class Kamaze::Project::Tools::Packager
|
36
|
+
# Get filesystem
|
37
|
+
#
|
38
|
+
# @return [Kamaze::Project::Tools::Packager::Filesystem]
|
39
|
+
attr_reader :fs
|
40
|
+
|
41
|
+
def initialize
|
42
|
+
@initialized = false
|
43
|
+
# fs mutable attributes are accessibles during initialization
|
44
|
+
# @see method_missing
|
45
|
+
@fs = Filesystem.new
|
46
|
+
|
47
|
+
yield self if block_given?
|
48
|
+
|
49
|
+
super
|
50
|
+
|
51
|
+
@initialized = true
|
52
|
+
end
|
53
|
+
|
54
|
+
# Denote class is initialized
|
55
|
+
#
|
56
|
+
# @return [Boolean]
|
57
|
+
def initialized?
|
58
|
+
@initialized
|
59
|
+
end
|
60
|
+
|
61
|
+
def method_missing(method, *args, &block)
|
62
|
+
if respond_to_missing?(method)
|
63
|
+
unless initialized?
|
64
|
+
mutable = fs.mutable_attribute?(method)
|
65
|
+
|
66
|
+
return fs.__send__(method, *args, &block) if mutable
|
67
|
+
end
|
68
|
+
|
69
|
+
return fs.public_send(method, *args, &block)
|
70
|
+
end
|
71
|
+
|
72
|
+
super
|
73
|
+
end
|
74
|
+
|
75
|
+
def respond_to_missing?(method, include_private = false)
|
76
|
+
if method.to_s[-1] == '='
|
77
|
+
unless initialized?
|
78
|
+
return true if fs.mutable_attribute?(method)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
return true if fs.respond_to?(method, include_private)
|
83
|
+
|
84
|
+
super(method, include_private)
|
85
|
+
end
|
86
|
+
end
|