fedux_org-stdlib 0.0.1 → 0.0.2
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.
- data/Gemfile +29 -2
- data/Rakefile +94 -1
- data/lib/fedux_org/stdlib/command/command_result.rb +14 -0
- data/lib/fedux_org/stdlib/command.rb +51 -0
- data/lib/fedux_org/stdlib/environment.rb +29 -0
- data/lib/fedux_org/stdlib/filesystem/exceptions.rb +13 -0
- data/lib/fedux_org/stdlib/filesystem.rb +247 -0
- data/lib/fedux_org/stdlib/logger.rb +9 -0
- data/lib/fedux_org/stdlib/logging/logger.rb +66 -0
- data/lib/fedux_org/stdlib/models/{base.rb → base_model.rb} +4 -4
- data/lib/fedux_org/stdlib/models/class_based_model.rb +5 -5
- data/lib/fedux_org/stdlib/models/exceptions.rb +32 -0
- data/lib/fedux_org/stdlib/models/filesystem_based_model.rb +7 -3
- data/lib/fedux_org/stdlib/models.rb +5 -0
- data/lib/fedux_org/stdlib/version.rb +2 -1
- data/spec/spec_helper.rb +28 -0
- metadata +14 -3
data/Gemfile
CHANGED
@@ -1,4 +1,31 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
group :test do
|
6
|
+
gem 'rake'
|
7
|
+
gem 'rspec'
|
8
|
+
gem 'simplecov'
|
9
|
+
gem 'aruba'
|
10
|
+
gem 'fuubar'
|
11
|
+
gem 'ffaker'
|
12
|
+
end
|
13
|
+
|
14
|
+
group :documentation do
|
15
|
+
gem 'yard'
|
16
|
+
gem 'redcarpet'
|
17
|
+
gem 'github-markup'
|
18
|
+
end
|
19
|
+
|
20
|
+
group :development do
|
21
|
+
gem 'tmrb'
|
22
|
+
gem 'debugger'
|
23
|
+
gem 'pry'
|
24
|
+
gem 'pry-doc'
|
25
|
+
gem 'pry-debugger'
|
26
|
+
gem 'debugger-completion'
|
27
|
+
gem 'awesome_print'
|
28
|
+
gem 'travis-lint'
|
29
|
+
gem 'fuubar'
|
30
|
+
gem 'churn'
|
31
|
+
end
|
data/Rakefile
CHANGED
@@ -1 +1,94 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
unless ENV['TRAVIS_CI'] == 'true'
|
4
|
+
namespace :gem do
|
5
|
+
require 'bundler/gem_tasks'
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'yard'
|
9
|
+
require 'rubygems/package_task'
|
10
|
+
require 'active_support/core_ext/string/strip'
|
11
|
+
end
|
12
|
+
|
13
|
+
YARD::Rake::YardocTask.new() do |y|
|
14
|
+
# y.options << '--verbose'
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'start tmux'
|
18
|
+
task :terminal do
|
19
|
+
sh "script/terminal"
|
20
|
+
end
|
21
|
+
|
22
|
+
task :term => :terminal
|
23
|
+
task :t => :terminal
|
24
|
+
|
25
|
+
namespace :version do
|
26
|
+
version_file = Dir.glob('lib/**/version.rb').first
|
27
|
+
|
28
|
+
desc 'bump version of library to new version'
|
29
|
+
task :bump do
|
30
|
+
|
31
|
+
new_version = ENV['VERSION'] || ENV['version']
|
32
|
+
|
33
|
+
raw_module_name = File.open(version_file, "r").readlines.grep(/module/).first
|
34
|
+
module_name = raw_module_name.chomp.match(/module\s+(\S+)/) {$1}
|
35
|
+
|
36
|
+
version_string = %Q{#main #{module_name}
|
37
|
+
module #{module_name}
|
38
|
+
VERSION = '#{new_version}'
|
39
|
+
end}
|
40
|
+
|
41
|
+
File.open(version_file, "w") do |f|
|
42
|
+
f.write version_string.strip_heredoc
|
43
|
+
end
|
44
|
+
|
45
|
+
sh "git add #{version_file}"
|
46
|
+
sh "git commit -m 'version bump to #{new_version}'"
|
47
|
+
#project = 'the_array_comparator'
|
48
|
+
#sh "git tag #{project}-v#{new_version}"
|
49
|
+
end
|
50
|
+
|
51
|
+
desc 'show version of library'
|
52
|
+
task :show do
|
53
|
+
raw_version = File.open(version_file, "r").readlines.grep(/VERSION/).first
|
54
|
+
|
55
|
+
if raw_version
|
56
|
+
version = raw_version.chomp.match(/VERSION\s+=\s+["']([^'"]+)["']/) { $1 }
|
57
|
+
puts version
|
58
|
+
else
|
59
|
+
warn "Could not parse version file \"#{version_file}\""
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
desc 'Restore version file from git repository'
|
65
|
+
task :restore do
|
66
|
+
sh "git checkout #{version_file}"
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
namespace :travis do
|
72
|
+
desc 'Runs travis-lint to check .travis.yml'
|
73
|
+
task :check do
|
74
|
+
sh 'travis-lint'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
namespace :test do
|
79
|
+
desc 'Run specs'
|
80
|
+
task :specs do
|
81
|
+
sh 'bundle exec rspec spec'
|
82
|
+
end
|
83
|
+
|
84
|
+
desc 'Run tests in "travis mode"'
|
85
|
+
task :travis_specs do
|
86
|
+
ENV['TRAVIS_CI'] = 'true'
|
87
|
+
sh 'rspec spec'
|
88
|
+
sh 'cucumber -p all'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
task :console do
|
93
|
+
sh 'script/console'
|
94
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
require 'fedux_org/stdlib/environment'
|
4
|
+
require 'fedux_org/stdlib/command/command_result'
|
5
|
+
|
6
|
+
module FeduxOrg
|
7
|
+
module Stdlib
|
8
|
+
module Command
|
9
|
+
include Environment
|
10
|
+
|
11
|
+
# Execute command
|
12
|
+
#
|
13
|
+
# @param [String] cmd
|
14
|
+
# the command
|
15
|
+
#
|
16
|
+
# @param [Hash] options
|
17
|
+
# the options for command execution
|
18
|
+
#
|
19
|
+
# @option options [Hash] env ({])
|
20
|
+
# the environment variables for the command ('VAR' => 'CONTENT')
|
21
|
+
#
|
22
|
+
# @option options [String] stdin (nil)
|
23
|
+
# the string for stdin of the command
|
24
|
+
#
|
25
|
+
# @option options [TrueClass,FalseClass] binmode (false)
|
26
|
+
# should the stdin be read a binary or not
|
27
|
+
#
|
28
|
+
# @return [CommandResult]
|
29
|
+
# the result of the command execution
|
30
|
+
#
|
31
|
+
# @return [CommandResult]
|
32
|
+
# the result of the command execution
|
33
|
+
def run_command(cmd,options={})
|
34
|
+
opts = {
|
35
|
+
env: nil,
|
36
|
+
stdin: nil,
|
37
|
+
binmode: false,
|
38
|
+
}.merge options
|
39
|
+
|
40
|
+
env = opts[:env] || ENV.to_hash
|
41
|
+
stdin = opts[:stdin]
|
42
|
+
binmode = opts[:binmode]
|
43
|
+
|
44
|
+
result = CommandResult.new
|
45
|
+
result.stdout, result.stderr, result.status = Open3.capture3(env, cmd, stdin_data: stdin, chdir: working_directory, binmode: binmode)
|
46
|
+
|
47
|
+
result
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module FeduxOrg
|
2
|
+
module Stdlib
|
3
|
+
module Environment
|
4
|
+
|
5
|
+
# Set environment variable for code block
|
6
|
+
#
|
7
|
+
# @param [Hash] variables
|
8
|
+
# the variables which should be set for that environment
|
9
|
+
#
|
10
|
+
# @yield
|
11
|
+
# the block which should be run which the change environment
|
12
|
+
def isolated_environment(variables, &block)
|
13
|
+
#backup
|
14
|
+
old_env = ENV.to_hash
|
15
|
+
#change env
|
16
|
+
ENV.update variables
|
17
|
+
|
18
|
+
block_result = block.call
|
19
|
+
|
20
|
+
#cleanup
|
21
|
+
ENV.clear
|
22
|
+
#install backuped information
|
23
|
+
ENV.update old_env
|
24
|
+
|
25
|
+
block_result
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module FeduxOrg
|
2
|
+
module Stdlib
|
3
|
+
module FileSystem
|
4
|
+
module Exceptions
|
5
|
+
# Raise if path with '..' given
|
6
|
+
class InvalidPath < Exception; end
|
7
|
+
|
8
|
+
#Raised if library is not used correctly
|
9
|
+
class InvalidUsageOfLibrary < Exception; end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,247 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'fedux_org/stdlib/filesystem/exceptions'
|
3
|
+
|
4
|
+
# helper for file system
|
5
|
+
module FeduxOrg
|
6
|
+
module Stdlib
|
7
|
+
module Filesystem
|
8
|
+
|
9
|
+
# The root directory of the project
|
10
|
+
#
|
11
|
+
# @return [String]
|
12
|
+
# the root directory
|
13
|
+
def root_directory
|
14
|
+
#::File.expand_path('../../../', __FILE__)
|
15
|
+
raise Exceptions::InvalidUsageOfLibrary , "Sorry, but you need to define the root directory yourself"
|
16
|
+
end
|
17
|
+
|
18
|
+
# The temporary directory for the project
|
19
|
+
#
|
20
|
+
# @return [String]
|
21
|
+
# the directory created for the tests
|
22
|
+
def working_directory
|
23
|
+
::File.join(root_directory, 'tmp', 'test')
|
24
|
+
end
|
25
|
+
|
26
|
+
# Create temporary directory
|
27
|
+
def create_working_directory
|
28
|
+
FileUtils.mkdir_p(working_directory) unless ::File.exists? working_directory
|
29
|
+
end
|
30
|
+
|
31
|
+
# Delete temporary directory
|
32
|
+
def delete_working_directory
|
33
|
+
FileUtils.rm_rf(working_directory) if ::File.exists? working_directory
|
34
|
+
end
|
35
|
+
|
36
|
+
# Clean up test directory
|
37
|
+
def cleanup_working_directory
|
38
|
+
delete_working_directory
|
39
|
+
create_working_directory
|
40
|
+
end
|
41
|
+
|
42
|
+
# Switch the current working directory to
|
43
|
+
# the temporary one and execute code block
|
44
|
+
def switch_to_working_directory(&block)
|
45
|
+
Dir.chdir(working_directory, &block)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Create directory(ies)
|
49
|
+
#
|
50
|
+
# @param [String,Array] dir
|
51
|
+
# the directories to be created, multiple arguments are possible as well
|
52
|
+
#
|
53
|
+
# @return [String,Array]
|
54
|
+
# returns a string if there was only one file given, and an array with
|
55
|
+
# muliple files
|
56
|
+
def create_directory(*dirs)
|
57
|
+
raise_if_forbidden_path_for_create_operation(dirs)
|
58
|
+
|
59
|
+
directories = expand_path(dirs.flatten)
|
60
|
+
FileUtils.mkdir_p(directories)
|
61
|
+
|
62
|
+
if directories.size == 1
|
63
|
+
return directories.first
|
64
|
+
else
|
65
|
+
return directories
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Delete directory(ies)
|
70
|
+
#
|
71
|
+
# @param [String, Array] dir
|
72
|
+
# the directories to be deleted, multiple arguments are possible as well
|
73
|
+
#
|
74
|
+
# @return [String,Array]
|
75
|
+
# returns a string if there was only one file given, and an array with
|
76
|
+
# muliple files
|
77
|
+
def delete_directory(*dirs)
|
78
|
+
raise_if_forbidden_path_for_delete_operation(dirs)
|
79
|
+
|
80
|
+
directories = expand_path(dirs.flatten)
|
81
|
+
FileUtils.rm_r(directories)
|
82
|
+
|
83
|
+
if directories.size == 1
|
84
|
+
return directories.first
|
85
|
+
else
|
86
|
+
return directories
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Check existence of path(s)
|
91
|
+
#
|
92
|
+
# @param [String,Array] paths
|
93
|
+
# which path(s) should be checked, multiple arguments are possible as well
|
94
|
+
#
|
95
|
+
# @return [TrueClass,FalseClass]
|
96
|
+
# the result of all checks done
|
97
|
+
def path_exists?(*paths)
|
98
|
+
raise_if_forbidden_path_for_create_operation(paths)
|
99
|
+
|
100
|
+
paths_expanded = expand_path(paths.flatten)
|
101
|
+
paths_expanded.flatten.all? { |p| ::File.exists?(p) }
|
102
|
+
end
|
103
|
+
|
104
|
+
# Check absence of path(s)
|
105
|
+
#
|
106
|
+
# @param [String,Array] paths
|
107
|
+
# which path(s) should be checked, multiple arguments are possible as well
|
108
|
+
#
|
109
|
+
# @return [TrueClass,FalseClass]
|
110
|
+
# the result of all checks done
|
111
|
+
def path_does_not_exist?(*paths)
|
112
|
+
not path_exists?(paths)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Create a single file
|
116
|
+
#
|
117
|
+
# @param [String] file_path
|
118
|
+
# the path for the new file (can include directories)
|
119
|
+
#
|
120
|
+
# @param [String] content
|
121
|
+
# the content written to the file
|
122
|
+
#
|
123
|
+
# @return [String]
|
124
|
+
# the path to the created file
|
125
|
+
def create_file(path, content='')
|
126
|
+
raise_if_forbidden_path_for_create_operation(path)
|
127
|
+
|
128
|
+
file = expand_path(path).first
|
129
|
+
directory = ::File.dirname(file)
|
130
|
+
|
131
|
+
FileUtils.mkdir_p(directory) unless directory == '.'
|
132
|
+
::File.open(file, "wb") do |f|
|
133
|
+
f.write content
|
134
|
+
end
|
135
|
+
|
136
|
+
file
|
137
|
+
end
|
138
|
+
|
139
|
+
# Delete a single file
|
140
|
+
#
|
141
|
+
# @param [String] file_path
|
142
|
+
# the path for the new file (can include directories)
|
143
|
+
#
|
144
|
+
# @param [String] content
|
145
|
+
# the content written to the file
|
146
|
+
#
|
147
|
+
# @return [String]
|
148
|
+
# the path to the created file
|
149
|
+
def delete_file(*files)
|
150
|
+
raise_if_forbidden_path_for_delete_operation(files)
|
151
|
+
|
152
|
+
files_to_be_deleted = expand_path(files.flatten)
|
153
|
+
FileUtils.rm(files_to_be_deleted)
|
154
|
+
|
155
|
+
if files_to_be_deleted.size == 1
|
156
|
+
return files_to_be_deleted.first
|
157
|
+
else
|
158
|
+
return files_to_be_deleted
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
# Read the content of a file
|
163
|
+
#
|
164
|
+
# @param [String] file_path
|
165
|
+
# the path to the file
|
166
|
+
#
|
167
|
+
# @return [String,Binary]
|
168
|
+
# the content of the file
|
169
|
+
def read_file(path)
|
170
|
+
raise_if_forbidden_path_for_create_operation(path)
|
171
|
+
|
172
|
+
file_path = expand_path(path).first
|
173
|
+
return ::File.read(file_path)
|
174
|
+
end
|
175
|
+
|
176
|
+
# Expand path based on temporary directory
|
177
|
+
#
|
178
|
+
# @param [String, Array, Multiple Values] paths
|
179
|
+
# the paths to be expanded
|
180
|
+
#
|
181
|
+
# @return [Array, String]
|
182
|
+
# the expanded arrays
|
183
|
+
def expand_path(*paths)
|
184
|
+
raise_if_forbidden_path_for_create_operation(paths)
|
185
|
+
|
186
|
+
paths.flatten.map do |p|
|
187
|
+
case p
|
188
|
+
when /^~/
|
189
|
+
::File.expand_path(p)
|
190
|
+
else
|
191
|
+
::File.join(working_directory, p )
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
# Check if path is forbidden for delete operation
|
197
|
+
#
|
198
|
+
# @param [String, Array] paths
|
199
|
+
# paths which should be checked
|
200
|
+
#
|
201
|
+
# @return [TrueClass, FalseClass]
|
202
|
+
# true if path is forbidden, false if path is not forbidden
|
203
|
+
def raise_if_forbidden_path_for_create_operation(*paths)
|
204
|
+
flattend_paths = paths.flatten
|
205
|
+
strings = []
|
206
|
+
regex = %r[\.\.]
|
207
|
+
|
208
|
+
raise FileSystem::Exceptions::InvalidPath , "Sorry, but you cannot use paths matching \"#{strings.join(', ')}\" or \"#{regex.to_s}\" here!" if path_matches?(strings, regex, flattend_paths)
|
209
|
+
end
|
210
|
+
|
211
|
+
# Check if path is forbidden for delete operation
|
212
|
+
#
|
213
|
+
# @param [String, Array] paths
|
214
|
+
# paths which should be checked
|
215
|
+
#
|
216
|
+
# @return [TrueClass, FalseClass]
|
217
|
+
# true if path is forbidden, false if path is not forbidden
|
218
|
+
def raise_if_forbidden_path_for_delete_operation(*paths)
|
219
|
+
flattend_paths = paths.flatten
|
220
|
+
strings = %w[ / ]
|
221
|
+
regex = %r[\.\.]
|
222
|
+
|
223
|
+
raise FileSystem::Exceptions::InvalidPath , "Sorry, but you cannot use paths matching \"#{strings.join(', ')}\" or \"#{regex.to_s}\" here!" if path_matches?(strings, regex, flattend_paths)
|
224
|
+
end
|
225
|
+
|
226
|
+
# Check if path matches
|
227
|
+
#
|
228
|
+
# @param [Array, String] strings
|
229
|
+
# strings which are checked against paths
|
230
|
+
#
|
231
|
+
# @param [Array, String] regex
|
232
|
+
# regex which is checked against path
|
233
|
+
#
|
234
|
+
# @param [Array, String] paths
|
235
|
+
# the paths to be checked
|
236
|
+
#
|
237
|
+
# @result [TrueClass, FalseClass]
|
238
|
+
# true if path is valid, false if invalid
|
239
|
+
def path_matches?(strings, regex, *paths)
|
240
|
+
flattend_paths = paths.flatten
|
241
|
+
flattend_strings = strings.flatten
|
242
|
+
|
243
|
+
flattend_paths.any? { |f| f =~ regex or flattend_strings.include?(f) }
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module FeduxOrg
|
2
|
+
module Stdlib
|
3
|
+
module Logging
|
4
|
+
class Logger
|
5
|
+
|
6
|
+
extend ::Forwardable
|
7
|
+
def_delegators :@logger, :fatal, :warn, :debug, :info, :error, :unknown
|
8
|
+
|
9
|
+
attr_reader :mode
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@logger = ::Logger.new($stderr)
|
13
|
+
self.mode = :info
|
14
|
+
end
|
15
|
+
|
16
|
+
def mode=(m)
|
17
|
+
@mode = m
|
18
|
+
|
19
|
+
case m
|
20
|
+
when :debug
|
21
|
+
@logger.level = ::Logger::DEBUG
|
22
|
+
format_debug
|
23
|
+
when :silent
|
24
|
+
@logger.level = ::Logger::SILENT
|
25
|
+
when :info
|
26
|
+
@logger.level = ::Logger::INFO
|
27
|
+
format_standard
|
28
|
+
else
|
29
|
+
@logger.level = ::Logger::INFO
|
30
|
+
format_standard
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def format_debug
|
37
|
+
@logger.formatter = proc { |severity, datetime, progname , msg|
|
38
|
+
debug_msg("%s %s %s: %s\n" % [ datetime, severity, progname, msg ])
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def format_standard
|
43
|
+
@logger.formatter = proc { |severity, datetime, _, msg|
|
44
|
+
info_msg( "%s %s: %s\n" % [ datetime, severity, msg ] )
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def error_msg(msg)
|
49
|
+
ANSI.red(msg)
|
50
|
+
end
|
51
|
+
|
52
|
+
def info_msg(msg)
|
53
|
+
msg
|
54
|
+
end
|
55
|
+
|
56
|
+
def debug_msg(msg)
|
57
|
+
msg
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class ::Logger
|
65
|
+
SILENT = 9999
|
66
|
+
end
|
@@ -94,20 +94,20 @@ module FeduxOrg
|
|
94
94
|
|
95
95
|
#finds all instances
|
96
96
|
def find_all( criteria={} )
|
97
|
-
|
97
|
+
FeduxOrg::Stdlib.logger.debug(self) { "Criteria for search: #{ criteria }" }
|
98
98
|
criteria = { name: criteria.to_sym } if criteria.kind_of? Symbol or criteria.kind_of? String
|
99
99
|
|
100
|
-
|
100
|
+
FeduxOrg::Stdlib.logger.debug(self) { "Instances to be searched for: #{ @instances.map { |i| "#{i.name} (#{i.class})" }.join(", ") }" }
|
101
101
|
@instances.find_all do |i|
|
102
102
|
criteria.all? do |c,v|
|
103
103
|
|
104
|
-
|
104
|
+
FeduxOrg::Stdlib.logger.debug(self) { "Check method for search: #{ c }" }
|
105
105
|
i.send( "#{c}?".to_sym , v )
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
109
|
rescue NameError => e
|
110
|
-
raise Exceptions::InvalidSearchCriteria, e.message
|
110
|
+
raise FeduxOrg::Stdlib::Models::Exceptions::InvalidSearchCriteria, e.message
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
@@ -11,13 +11,13 @@ module FeduxOrg
|
|
11
11
|
module ClassMethods
|
12
12
|
|
13
13
|
def require_path(name)
|
14
|
-
File.join(
|
14
|
+
File.join( module_name.underscore , model_name.pluralize.underscore , name.to_s )
|
15
15
|
end
|
16
16
|
|
17
17
|
def exception_for_model
|
18
|
-
"
|
18
|
+
"#{library_name}::Exceptions::Invalid#{model_name.singularize}".constantize
|
19
19
|
rescue
|
20
|
-
raise Exceptions::ExceptionNeedsToBeImplemented, "Exception \"Exceptions::Invalid#{model_name}\" does not exist."
|
20
|
+
raise FeduxOrg::Stdlib::Models::Exceptions::ExceptionNeedsToBeImplemented, "Exception \"#{library_name}::Exceptions::Invalid#{model_name}\" does not exist."
|
21
21
|
end
|
22
22
|
|
23
23
|
def check_klass( klass , method)
|
@@ -25,13 +25,13 @@ module FeduxOrg
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def build_class_constant(name)
|
28
|
-
"
|
28
|
+
"#{library_name}::#{model_name.pluralize}::#{name.to_s.camelcase}".constantize
|
29
29
|
rescue
|
30
30
|
raise exception_for_model , "The filename needs to be snakecase and needs to be convertible to the action class name: filename in camelcase."
|
31
31
|
end
|
32
32
|
|
33
33
|
def check_method
|
34
|
-
raise Exceptions::MethodNeedsToBeImplemented, "Method \"check_method\" does not exist."
|
34
|
+
raise FeduxOrg::Stdlib::Models::Exceptions::MethodNeedsToBeImplemented, "Method \"check_method\" does not exist."
|
35
35
|
end
|
36
36
|
|
37
37
|
def suffix
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module PuppetGenerator
|
2
|
+
module Exceptions
|
3
|
+
|
4
|
+
#raised if one tries to delete an instance which
|
5
|
+
#does not exist
|
6
|
+
class InstanceNotFound < InternalError; end
|
7
|
+
|
8
|
+
#raised if one tries to use a keyword whose use
|
9
|
+
#is restricted
|
10
|
+
class UnauthorizedUseOfKeyword < InternalError; end
|
11
|
+
|
12
|
+
#raised if one uses invalid search criteria
|
13
|
+
class InvalidSearchCriteria < InternalError; end
|
14
|
+
|
15
|
+
#raised if the code which defines an import filter
|
16
|
+
#is malformed
|
17
|
+
class MethodNeedsToBeImplemented < InternalError; end
|
18
|
+
|
19
|
+
#raised if one tries to use an unimplemented exception
|
20
|
+
class ExceptionNeedsToBeImplemented < InternalError; end
|
21
|
+
|
22
|
+
#raised if an file system error occured
|
23
|
+
class FilesystemError < Exception ; end
|
24
|
+
|
25
|
+
#raise if a directory does not exist in filesystem
|
26
|
+
class DirectoryDoesNotExist < FilesystemError; end
|
27
|
+
|
28
|
+
#raise if a file does not exist in filesystem
|
29
|
+
class FileDoesNotExist < FilesystemError; end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -32,8 +32,12 @@ module FeduxOrg
|
|
32
32
|
fqcn.last
|
33
33
|
end
|
34
34
|
|
35
|
+
def library_name
|
36
|
+
fqcn.first
|
37
|
+
end
|
38
|
+
|
35
39
|
def suffix
|
36
|
-
raise Exceptions::MethodNeedsToBeImplemented
|
40
|
+
raise FeduxOrg::Stdlib::Models::Exceptions::MethodNeedsToBeImplemented
|
37
41
|
end
|
38
42
|
|
39
43
|
def path_to_instances
|
@@ -44,13 +48,13 @@ module FeduxOrg
|
|
44
48
|
|
45
49
|
def name(path)
|
46
50
|
name = File.basename(path, suffix ).to_sym
|
47
|
-
raise Exceptions::UnauthorizedUseOfKeyword if forbidden_keywords.include? name
|
51
|
+
raise FeduxOrg::Stdlib::Models::Exceptions::UnauthorizedUseOfKeyword if forbidden_keywords.include? name
|
48
52
|
|
49
53
|
name
|
50
54
|
end
|
51
55
|
|
52
56
|
def load_from_filesystem
|
53
|
-
raise Exceptions::MethodNeedsToBeImplemented
|
57
|
+
raise FeduxOrg::Stdlib::Models::Exceptions::MethodNeedsToBeImplemented
|
54
58
|
end
|
55
59
|
|
56
60
|
def forbidden_keywords
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
$LOAD_PATH << File.expand_path( '../../lib', __FILE__ )
|
3
|
+
|
4
|
+
unless ENV['TRAVIS_CI'] == 'true'
|
5
|
+
require 'pry'
|
6
|
+
require 'debugger'
|
7
|
+
require 'ap'
|
8
|
+
require 'benchmark'
|
9
|
+
end
|
10
|
+
|
11
|
+
unless ENV['TRAVIS_CI'] == 'true'
|
12
|
+
require 'simplecov'
|
13
|
+
SimpleCov.start
|
14
|
+
SimpleCov.command_name 'rspec'
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'puppet_generator'
|
18
|
+
include PuppetGenerator
|
19
|
+
|
20
|
+
RSpec.configure do |c|
|
21
|
+
c.treat_symbols_as_metadata_keys_with_true_values = true
|
22
|
+
c.filter_run :focus => true
|
23
|
+
c.run_all_when_everything_filtered = true
|
24
|
+
end
|
25
|
+
|
26
|
+
def examples_dir
|
27
|
+
File.expand_path( '../examples', __FILE__ )
|
28
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fedux_org-stdlib
|
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:
|
@@ -57,10 +57,20 @@ files:
|
|
57
57
|
- Rakefile
|
58
58
|
- fedux_org-stdlib.gemspec
|
59
59
|
- lib/fedux_org/stdlib.rb
|
60
|
-
- lib/fedux_org/stdlib/
|
60
|
+
- lib/fedux_org/stdlib/command.rb
|
61
|
+
- lib/fedux_org/stdlib/command/command_result.rb
|
62
|
+
- lib/fedux_org/stdlib/environment.rb
|
63
|
+
- lib/fedux_org/stdlib/filesystem.rb
|
64
|
+
- lib/fedux_org/stdlib/filesystem/exceptions.rb
|
65
|
+
- lib/fedux_org/stdlib/logger.rb
|
66
|
+
- lib/fedux_org/stdlib/logging/logger.rb
|
67
|
+
- lib/fedux_org/stdlib/models.rb
|
68
|
+
- lib/fedux_org/stdlib/models/base_model.rb
|
61
69
|
- lib/fedux_org/stdlib/models/class_based_model.rb
|
70
|
+
- lib/fedux_org/stdlib/models/exceptions.rb
|
62
71
|
- lib/fedux_org/stdlib/models/filesystem_based_model.rb
|
63
72
|
- lib/fedux_org/stdlib/version.rb
|
73
|
+
- spec/spec_helper.rb
|
64
74
|
homepage: ''
|
65
75
|
licenses:
|
66
76
|
- MIT
|
@@ -86,5 +96,6 @@ rubygems_version: 1.8.23
|
|
86
96
|
signing_key:
|
87
97
|
specification_version: 3
|
88
98
|
summary: collection of use full libraries
|
89
|
-
test_files:
|
99
|
+
test_files:
|
100
|
+
- spec/spec_helper.rb
|
90
101
|
has_rdoc:
|