Module: AeEasy::Core
- Defined in:
- lib/ae_easy/core.rb,
lib/ae_easy/core/mock.rb,
lib/ae_easy/core/config.rb,
lib/ae_easy/core/helper.rb,
lib/ae_easy/core/plugin.rb,
lib/ae_easy/core/version.rb,
lib/ae_easy/core/exception.rb,
lib/ae_easy/core/mock/fake_db.rb,
lib/ae_easy/core/helper/cookie.rb,
lib/ae_easy/core/plugin/parser.rb,
lib/ae_easy/core/plugin/seeder.rb,
lib/ae_easy/core/mock/fake_parser.rb,
lib/ae_easy/core/mock/fake_seeder.rb,
lib/ae_easy/core/smart_collection.rb,
lib/ae_easy/core/mock/fake_executor.rb,
lib/ae_easy/core/plugin/config_behavior.rb,
lib/ae_easy/core/plugin/initialize_hook.rb,
lib/ae_easy/core/plugin/parser_behavior.rb,
lib/ae_easy/core/plugin/seeder_behavior.rb,
lib/ae_easy/core/plugin/collection_vault.rb,
lib/ae_easy/core/exception/outdated_error.rb,
lib/ae_easy/core/plugin/context_integrator.rb
Defined Under Namespace
Modules: Exception, Helper, Mock, Plugin Classes: Config, SmartCollection
Constant Summary collapse
- VERSION =
Gem version
"0.0.2"
Class Method Summary collapse
-
.all_scripts(dir, opts = {}) {|path| ... } ⇒ Object
Execute an action for all scripts within a directory.
-
.analyze_compatibility(source, fragment) ⇒ Hash
Generate a compatibility report from a source and a fragment as a hash.
-
.deep_clone(hash, should_clone = false) ⇒ Hash
Deep clone a hash while keeping it's values object references.
-
.deep_stringify_keys(hash, should_clone = true) ⇒ Hash
Deep stringify keys from a hash.
-
.deep_stringify_keys!(hash) ⇒ Hash
Deep stringify all keys on hash object.
-
.expose_to(object, env) ⇒ Object
Expose an environment into an object instance as methods.
-
.gem_root ⇒ String
Get AeEasy-core gem root directory path.
-
.instance_methods_from(object) ⇒ Array
Retrieve instance methods from an object.
-
.mock_instance_methods(source, target) ⇒ Object
Mock instances methods from the source into target object.
-
.require_all(dir, opts = {}) ⇒ Object
Require all scripts within a directory.
-
.require_relative_all(dir, opts = {}) ⇒ Object
Require all relative scripts paths within a directory.
Class Method Details
.all_scripts(dir, opts = {}) {|path| ... } ⇒ Object
Execute an action for all scripts within a directory.
29 30 31 32 33 34 |
# File 'lib/ae_easy/core.rb', line 29 def all_scripts dir, opts = {}, &block excluded_files = (opts[:except] || []).map{|f|File. File.join(dir, f)} files = Dir[File.join(File.(dir), '*.rb')] - excluded_files block ||= proc{} files.sort.each &block end |
.analyze_compatibility(source, fragment) ⇒ Hash
Generate a compatibility report from a source and a fragment as a hash.
190 191 192 193 194 195 196 197 |
# File 'lib/ae_easy/core.rb', line 190 def analyze_compatibility source, fragment intersection = source & fragment { missing: fragment - intersection, new: source - intersection, is_compatible: (intersection.count == fragment.count) } end |
.deep_clone(hash, should_clone = false) ⇒ Hash
Deep clone a hash while keeping it's values object references.
231 232 233 234 235 236 237 238 |
# File 'lib/ae_easy/core.rb', line 231 def deep_clone hash, should_clone = false target = {} hash.each do |key, value| value = value.is_a?(Hash) ? deep_clone(value, should_clone) : (should_clone ? value.clone : value) target[key] = value end target end |
.deep_stringify_keys(hash, should_clone = true) ⇒ Hash
Deep stringify keys from a hash.
205 206 207 208 209 210 211 212 213 214 |
# File 'lib/ae_easy/core.rb', line 205 def deep_stringify_keys hash, should_clone = true pair_collection = hash.map{|k,v| [k.to_s,v]} target = should_clone ? {} : hash target.clear pair_collection.each do |pair| key, value = pair target[key] = value.is_a?(Hash) ? deep_stringify_keys(value, should_clone) : value end target end |
.deep_stringify_keys!(hash) ⇒ Hash
Deep stringify all keys on hash object.
221 222 223 |
# File 'lib/ae_easy/core.rb', line 221 def deep_stringify_keys! hash deep_stringify_keys hash, false end |
.expose_to(object, env) ⇒ Object
Expose an environment into an object instance as methods.
91 92 93 94 95 96 97 |
# File 'lib/ae_easy/core.rb', line 91 def expose_to object, env = class << object; self; end env.each do |key, block| .send(:define_method, key, block) end object end |
.gem_root ⇒ String
Get AeEasy-core gem root directory path.
18 19 20 |
# File 'lib/ae_easy/core.rb', line 18 def gem_root File. File.join(File.dirname(__FILE__), '../..') end |
.instance_methods_from(object) ⇒ Array
Retrieve instance methods from an object.
119 120 121 |
# File 'lib/ae_easy/core.rb', line 119 def instance_methods_from object object.methods(false) - Object.new.methods(false) end |
.mock_instance_methods(source, target) ⇒ Object
Mock instances methods from the source into target object.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/ae_easy/core.rb', line 158 def mock_instance_methods source, target # Get instance unique methods method_list = instance_methods_from source method_list.delete :context_binding if method_list.include? :context_binding # Build env reflecting source unique methods env = {} method_list.each do |method| env[method] = lambda{|*args|source.send(method, *args)} end # Mock source unique methods into target expose_to target, env end |
.require_all(dir, opts = {}) ⇒ Object
Require all scripts within a directory.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ae_easy/core.rb', line 41 def require_all dir, opts = {} real_dir = = nil real_except = [] $LOAD_PATH.each do |load_path| real_dir = File.join load_path, dir next unless File.directory? real_dir real_except = (opts[:except] || []).map{|f| "#{f}.rb"} = opts.merge except: real_except all_scripts(real_dir, ) {|file| require file} end end |
.require_relative_all(dir, opts = {}) ⇒ Object
Require all relative scripts paths within a directory.
58 59 60 61 62 |
# File 'lib/ae_easy/core.rb', line 58 def require_relative_all dir, opts = {} real_except = (opts[:except] || []).map{|f| "#{f}.rb"} = opts.merge except: real_except all_scripts(dir, ) {|file| require file} end |