garcun 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.
Files changed (139) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +17 -0
  3. data/.gitignore +197 -0
  4. data/.rspec +2 -0
  5. data/Gemfile +22 -0
  6. data/LICENSE +201 -0
  7. data/README.md +521 -0
  8. data/Rakefile +47 -0
  9. data/garcun.gemspec +83 -0
  10. data/lib/garcon.rb +290 -0
  11. data/lib/garcon/chef/chef_helpers.rb +343 -0
  12. data/lib/garcon/chef/coerce/coercer.rb +134 -0
  13. data/lib/garcon/chef/coerce/coercions/boolean_definitions.rb +34 -0
  14. data/lib/garcon/chef/coerce/coercions/date_definitions.rb +32 -0
  15. data/lib/garcon/chef/coerce/coercions/date_time_definitions.rb +32 -0
  16. data/lib/garcon/chef/coerce/coercions/fixnum_definitions.rb +34 -0
  17. data/lib/garcon/chef/coerce/coercions/float_definitions.rb +32 -0
  18. data/lib/garcon/chef/coerce/coercions/hash_definitions.rb +29 -0
  19. data/lib/garcon/chef/coerce/coercions/integer_definitions.rb +31 -0
  20. data/lib/garcon/chef/coerce/coercions/string_definitions.rb +45 -0
  21. data/lib/garcon/chef/coerce/coercions/time_definitions.rb +32 -0
  22. data/lib/garcon/chef/handler/devreporter.rb +127 -0
  23. data/lib/garcon/chef/log.rb +64 -0
  24. data/lib/garcon/chef/node.rb +100 -0
  25. data/lib/garcon/chef/provider/civilize.rb +209 -0
  26. data/lib/garcon/chef/provider/development.rb +159 -0
  27. data/lib/garcon/chef/provider/download.rb +420 -0
  28. data/lib/garcon/chef/provider/house_keeping.rb +265 -0
  29. data/lib/garcon/chef/provider/node_cache.rb +31 -0
  30. data/lib/garcon/chef/provider/partial.rb +183 -0
  31. data/lib/garcon/chef/provider/recovery.rb +80 -0
  32. data/lib/garcon/chef/provider/zip_file.rb +271 -0
  33. data/lib/garcon/chef/resource/attribute.rb +52 -0
  34. data/lib/garcon/chef/resource/base_dsl.rb +174 -0
  35. data/lib/garcon/chef/resource/blender.rb +140 -0
  36. data/lib/garcon/chef/resource/lazy_eval.rb +66 -0
  37. data/lib/garcon/chef/resource/resource_name.rb +109 -0
  38. data/lib/garcon/chef/secret_bag.rb +204 -0
  39. data/lib/garcon/chef/validations.rb +76 -0
  40. data/lib/garcon/chef_inclusions.rb +151 -0
  41. data/lib/garcon/configuration.rb +138 -0
  42. data/lib/garcon/core_ext.rb +39 -0
  43. data/lib/garcon/core_ext/array.rb +27 -0
  44. data/lib/garcon/core_ext/binding.rb +64 -0
  45. data/lib/garcon/core_ext/boolean.rb +66 -0
  46. data/lib/garcon/core_ext/duration.rb +271 -0
  47. data/lib/garcon/core_ext/enumerable.rb +34 -0
  48. data/lib/garcon/core_ext/file.rb +127 -0
  49. data/lib/garcon/core_ext/filetest.rb +62 -0
  50. data/lib/garcon/core_ext/hash.rb +279 -0
  51. data/lib/garcon/core_ext/kernel.rb +159 -0
  52. data/lib/garcon/core_ext/lazy.rb +222 -0
  53. data/lib/garcon/core_ext/method_access.rb +243 -0
  54. data/lib/garcon/core_ext/module.rb +92 -0
  55. data/lib/garcon/core_ext/nil.rb +53 -0
  56. data/lib/garcon/core_ext/numeric.rb +44 -0
  57. data/lib/garcon/core_ext/object.rb +342 -0
  58. data/lib/garcon/core_ext/pathname.rb +152 -0
  59. data/lib/garcon/core_ext/process.rb +41 -0
  60. data/lib/garcon/core_ext/random.rb +497 -0
  61. data/lib/garcon/core_ext/string.rb +312 -0
  62. data/lib/garcon/core_ext/struct.rb +49 -0
  63. data/lib/garcon/core_ext/symbol.rb +170 -0
  64. data/lib/garcon/core_ext/time.rb +234 -0
  65. data/lib/garcon/exceptions.rb +101 -0
  66. data/lib/garcon/inflections.rb +237 -0
  67. data/lib/garcon/inflections/defaults.rb +79 -0
  68. data/lib/garcon/inflections/inflections.rb +182 -0
  69. data/lib/garcon/inflections/rules_collection.rb +37 -0
  70. data/lib/garcon/secret.rb +271 -0
  71. data/lib/garcon/stash/format.rb +114 -0
  72. data/lib/garcon/stash/journal.rb +226 -0
  73. data/lib/garcon/stash/queue.rb +83 -0
  74. data/lib/garcon/stash/serializer.rb +86 -0
  75. data/lib/garcon/stash/store.rb +435 -0
  76. data/lib/garcon/task.rb +31 -0
  77. data/lib/garcon/task/atomic.rb +151 -0
  78. data/lib/garcon/task/atomic_boolean.rb +127 -0
  79. data/lib/garcon/task/condition.rb +99 -0
  80. data/lib/garcon/task/copy_on_notify_observer_set.rb +154 -0
  81. data/lib/garcon/task/copy_on_write_observer_set.rb +153 -0
  82. data/lib/garcon/task/count_down_latch.rb +92 -0
  83. data/lib/garcon/task/delay.rb +196 -0
  84. data/lib/garcon/task/dereferenceable.rb +144 -0
  85. data/lib/garcon/task/event.rb +119 -0
  86. data/lib/garcon/task/executor.rb +275 -0
  87. data/lib/garcon/task/executor_options.rb +59 -0
  88. data/lib/garcon/task/future.rb +107 -0
  89. data/lib/garcon/task/immediate_executor.rb +84 -0
  90. data/lib/garcon/task/ivar.rb +171 -0
  91. data/lib/garcon/task/lazy_reference.rb +74 -0
  92. data/lib/garcon/task/monotonic_time.rb +69 -0
  93. data/lib/garcon/task/obligation.rb +256 -0
  94. data/lib/garcon/task/observable.rb +101 -0
  95. data/lib/garcon/task/priority_queue.rb +234 -0
  96. data/lib/garcon/task/processor_count.rb +128 -0
  97. data/lib/garcon/task/read_write_lock.rb +304 -0
  98. data/lib/garcon/task/safe_task_executor.rb +58 -0
  99. data/lib/garcon/task/single_thread_executor.rb +97 -0
  100. data/lib/garcon/task/thread_pool/cached.rb +71 -0
  101. data/lib/garcon/task/thread_pool/executor.rb +294 -0
  102. data/lib/garcon/task/thread_pool/fixed.rb +61 -0
  103. data/lib/garcon/task/thread_pool/worker.rb +90 -0
  104. data/lib/garcon/task/timer.rb +44 -0
  105. data/lib/garcon/task/timer_set.rb +194 -0
  106. data/lib/garcon/task/timer_task.rb +377 -0
  107. data/lib/garcon/task/waitable_list.rb +58 -0
  108. data/lib/garcon/utility/ansi.rb +199 -0
  109. data/lib/garcon/utility/at_random.rb +77 -0
  110. data/lib/garcon/utility/crypto.rb +292 -0
  111. data/lib/garcon/utility/equalizer.rb +146 -0
  112. data/lib/garcon/utility/faker/extensions/array.rb +22 -0
  113. data/lib/garcon/utility/faker/extensions/symbol.rb +9 -0
  114. data/lib/garcon/utility/faker/faker.rb +164 -0
  115. data/lib/garcon/utility/faker/faker/company.rb +17 -0
  116. data/lib/garcon/utility/faker/faker/hacker.rb +30 -0
  117. data/lib/garcon/utility/faker/faker/version.rb +3 -0
  118. data/lib/garcon/utility/faker/locales/en-US.yml +83 -0
  119. data/lib/garcon/utility/faker/locales/en.yml +21 -0
  120. data/lib/garcon/utility/file_helper.rb +170 -0
  121. data/lib/garcon/utility/hookers.rb +178 -0
  122. data/lib/garcon/utility/interpolation.rb +90 -0
  123. data/lib/garcon/utility/memstash.rb +364 -0
  124. data/lib/garcon/utility/misc.rb +54 -0
  125. data/lib/garcon/utility/msg_from_god.rb +62 -0
  126. data/lib/garcon/utility/retry.rb +238 -0
  127. data/lib/garcon/utility/timeout.rb +58 -0
  128. data/lib/garcon/utility/uber/builder.rb +91 -0
  129. data/lib/garcon/utility/uber/callable.rb +7 -0
  130. data/lib/garcon/utility/uber/delegates.rb +13 -0
  131. data/lib/garcon/utility/uber/inheritable_attr.rb +37 -0
  132. data/lib/garcon/utility/uber/options.rb +101 -0
  133. data/lib/garcon/utility/uber/uber_version.rb +3 -0
  134. data/lib/garcon/utility/uber/version.rb +33 -0
  135. data/lib/garcon/utility/url_helper.rb +100 -0
  136. data/lib/garcon/utils.rb +29 -0
  137. data/lib/garcon/version.rb +62 -0
  138. data/lib/garcun.rb +24 -0
  139. metadata +680 -0
@@ -0,0 +1,76 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Author: Stefano Harding <riddopic@gmail.com>
4
+ # License: Apache License, Version 2.0
5
+ # Copyright: (C) 2014-2015 Stefano Harding
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require 'uri'
21
+
22
+ # Resource validations.
23
+ #
24
+ module Garcon
25
+ module Resource
26
+ module Validations
27
+ module ClassMethods
28
+ # Callback for source URL validation.
29
+ #
30
+ # @return [Proc]
31
+ #
32
+ def source_callbacks
33
+ { 'Source must be an absolute URI' => ->(src) { valid_source?(src) }}
34
+ end
35
+
36
+ # Validate that the source attribute is an absolute URI or file and not
37
+ # an not empty string.
38
+ #
39
+ # @param [String]
40
+ #
41
+ # @return [Boolean]
42
+ #
43
+ def valid_source?(source)
44
+ absolute_uri?(source) ? true : ::File.exist?(source)
45
+ end
46
+
47
+ # Boolean, true if source is an absolute URI, false otherwise.
48
+ #
49
+ # @param [String] source
50
+ #
51
+ # @return [Boolean]
52
+ #
53
+ def absolute_uri?(source)
54
+ source =~ URI::ABS_URI && URI.parse(source).absolute?
55
+ rescue URI::InvalidURIError
56
+ false
57
+ end
58
+
59
+ # Hook called when module is included, extends a descendant with class
60
+ # and instance methods.
61
+ #
62
+ # @param [Module] descendant
63
+ # The module or class including Garcon::Resource::Validations
64
+ #
65
+ # @return [self]
66
+ #
67
+ def included(descendant)
68
+ super
69
+ descendant.extend ClassMethods
70
+ end
71
+ end
72
+
73
+ extend ClassMethods
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,151 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Author: Stefano Harding <riddopic@gmail.com>
4
+ # License: Apache License, Version 2.0
5
+ # Copyright: (C) 2014-2015 Stefano Harding
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require_relative 'chef/chef_helpers'
21
+ require_relative 'chef/log'
22
+ require_relative 'chef/node'
23
+ require_relative 'chef/secret_bag'
24
+ require_relative 'chef/validations'
25
+
26
+ require_relative 'chef/resource/attribute'
27
+ require_relative 'chef/resource/base_dsl'
28
+ require_relative 'chef/resource/blender'
29
+ require_relative 'chef/resource/lazy_eval'
30
+ require_relative 'chef/resource/resource_name'
31
+
32
+ module Garcon
33
+ # Extend Resource with class and instance methods.
34
+ #
35
+ module Resource
36
+ include BaseDSL
37
+ include LazyEval
38
+ include Validations
39
+ include ResourceName
40
+ include Garcon::UrlHelper
41
+ include Garcon::FileHelper
42
+
43
+ module ClassMethods
44
+ # Interpolate node attributes automatically.
45
+ #
46
+ def interpolate(namespace = nil)
47
+ node.set[namespace] = interpolate(Garcon.config.stash[namespace])
48
+ end
49
+
50
+ # Combine a resource and provider class for quick and easy oven baked
51
+ # goodness. Never has cooking been this fun since the invention of the
52
+ # grocery store!
53
+ #
54
+ def blender
55
+ include Garcon::Resource::Blender
56
+ end
57
+
58
+ # Hook called when module is included, extends a descendant with class
59
+ # and instance methods.
60
+ #
61
+ # @param [Module] descendant
62
+ # the module or class including Garcon
63
+ #
64
+ # @return [self]
65
+ #
66
+ # @api private
67
+ def included(descendant)
68
+ super
69
+ descendant.extend ClassMethods
70
+ end
71
+ end
72
+
73
+ extend ClassMethods
74
+ end
75
+
76
+ # Extend Provider with class and instance methods.
77
+ #
78
+ module Provider
79
+ include BaseDSL
80
+ include Garcon::Retry
81
+ include Garcon::Timeout
82
+ include Garcon::UrlHelper
83
+ include Garcon::FileHelper
84
+ include Garcon::ChefHelpers
85
+ end
86
+
87
+ # Hook called when module is included, extends a descendant with class
88
+ # and instance methods.
89
+ #
90
+ # @param [Module] descendant
91
+ # the module or class including Garcon
92
+ #
93
+ # @return [self]
94
+ #
95
+ # @api private
96
+ def self.included(descendant)
97
+ super
98
+ if descendant < Chef::Resource
99
+ descendant.class_exec { include Garcon::Resource }
100
+ elsif descendant < Chef::Provider
101
+ descendant.class_exec { include Garcon::Provider }
102
+ end
103
+ end
104
+ end
105
+
106
+ def Garcon(opts = {})
107
+ if opts.is_a?(Class)
108
+ opts = { parent: opts }
109
+ end
110
+
111
+ mod = Module.new
112
+
113
+ def mod.name
114
+ super || 'Garcon'
115
+ end
116
+
117
+ mod.define_singleton_method(:included) do |base|
118
+ super(base)
119
+ base.class_exec { include Garcon }
120
+ if base < Chef::Resource
121
+ base.interpolate(opts[:node], opts[:namespace]) if opts[:interpolate]
122
+ base.blender if opts[:blender]
123
+ end
124
+ end
125
+
126
+ mod
127
+ end
128
+
129
+ unless Chef::Recipe.ancestors.include?(Garcon::ChefHelpers)
130
+ Chef::Recipe.send(:include, Garcon::ChefHelpers)
131
+ Chef::Resource.send(:include, Garcon::ChefHelpers)
132
+ Chef::Provider.send(:include, Garcon::ChefHelpers)
133
+ end
134
+
135
+ unless Chef::Recipe.ancestors.include?(Garcon::Interpolation)
136
+ Chef::Recipe.send(:include, Garcon::Interpolation)
137
+ Chef::Resource.send(:include, Garcon::Interpolation)
138
+ Chef::Provider.send(:include, Garcon::Interpolation)
139
+ end
140
+
141
+ unless Chef::Resource.method_defined?(:run_now)
142
+ Chef::Resource.send(:include, Garcon::RunNow::Mixin)
143
+ end
144
+
145
+ require_relative 'chef/provider/civilize'
146
+ require_relative 'chef/provider/download'
147
+ require_relative 'chef/provider/house_keeping'
148
+ require_relative 'chef/provider/node_cache'
149
+ require_relative 'chef/provider/partial'
150
+ require_relative 'chef/provider/recovery'
151
+ require_relative 'chef/provider/zip_file'
@@ -0,0 +1,138 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Author: Stefano Harding <riddopic@gmail.com>
4
+ # License: Apache License, Version 2.0
5
+ # Copyright: (C) 2014-2015 Stefano Harding
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ module Garcon
21
+ # Configuration instance
22
+ #
23
+ class Configuration
24
+
25
+ # Access the minimum number of threads setting for this instance.
26
+ attr_accessor :min_threads
27
+
28
+ # Access the maximum number of threads setting for this instance.
29
+ attr_accessor :max_threads
30
+
31
+ # @!attribute [rw] auto_terminate_global_executors
32
+ # @return [Boolean] Defines if global executors should be auto-terminated
33
+ # with an `at_exit` callback. When set to `false` it will be the
34
+ # application programmer's responsibility to ensure that the global
35
+ # thread pools are shutdown properly prior to application exit.
36
+ attr_accessor :auto_terminate_global_executors
37
+
38
+ # @!attribute [rw] auto_terminate_all_executors
39
+ # @return [Boolean] Defines if global executors should be auto-terminated
40
+ # with an `at_exit` callback. When set to `false` it will be the
41
+ # application programmer's responsibility to ensure that the global
42
+ # thread pools are shutdown properly prior to application exit.
43
+ attr_accessor :auto_terminate_all_executors
44
+
45
+ # Global thread pool optimized for short, fast *operations*.
46
+ #
47
+ # @!attribute [ro] global_fast_executor
48
+ # @return [ThreadPoolExecutor] the thread pool
49
+ attr_reader :global_fast_executor
50
+
51
+ # Global thread pool optimized for long, blocking (IO) *tasks*.
52
+ #
53
+ # @!attribute [ro] global_io_executor
54
+ # @return [ThreadPoolExecutor] the thread pool
55
+ attr_reader :global_io_executor
56
+
57
+ # Global thread pool user for global *timers*.
58
+ #
59
+ # @!attribute [ro] global_timer_set
60
+ # @return [Garcon::TimerSet] the thread pool
61
+ attr_reader :global_timer_set
62
+
63
+ # Initialized a configuration instance.
64
+ #
65
+ # @return [undefined]
66
+ #
67
+ # @api private
68
+ def initialize(opts = {})
69
+ @min_threads = opts.fetch(:min_threads, [2, Garcon.processor_count].max)
70
+ @max_threads = opts.fetch(:max_threads, Garcon.processor_count * 100)
71
+
72
+ @crypto = Crypto::Configuration.new
73
+ @secret = Secret::Configuration.new
74
+
75
+ @auto_terminate_global_executors = AtomicBoolean.new(true)
76
+ @auto_terminate_all_executors = AtomicBoolean.new(true)
77
+
78
+ @global_fast_executor = Delay.new do
79
+ Garcon.new_fast_executor(
80
+ stop_on_exit: @auto_terminate_global_executors.value)
81
+ end
82
+
83
+ @global_io_executor = Delay.new do
84
+ Garcon.new_io_executor(
85
+ stop_on_exit: @auto_terminate_global_executors.value)
86
+ end
87
+
88
+ @global_timer_set = Delay.new do
89
+ TimerSet.new(stop_on_exit: @auto_terminate_global_executors.value)
90
+ end
91
+
92
+ yield self if block_given?
93
+ end
94
+
95
+ # Access the crypto for this instance and optional configure a
96
+ # new crypto with the passed block.
97
+ #
98
+ # @example
99
+ # Garcon.config do |c|
100
+ # c.crypto.password = "!mWh0!s@y!m"
101
+ # c.crypto.salt = "9e5f851900cad8892ac8b737b7370cbe"
102
+ # end
103
+ #
104
+ # @return [Crypto]
105
+ #
106
+ # @api private
107
+ def crypto(&block)
108
+ @crypto = Crypto::Configuration.new(&block) if block_given?
109
+ @crypto
110
+ end
111
+
112
+ # Access the secret stash hash cash store for this instance and optional
113
+ # configure a new secret with the passed block.
114
+ #
115
+ # @return [Secret]
116
+ #
117
+ # @api private
118
+ def secret(&block)
119
+ @secret = Secret::Configuration.new(&block) if block_given?
120
+ @secret
121
+ end
122
+
123
+ # @api private
124
+ def to_h
125
+ { crypto: crypto,
126
+ secret: secret,
127
+ blender: blender,
128
+ min_threads: min_threads,
129
+ max_threads: max_threads,
130
+ global_timer_set: global_timer_set,
131
+ global_io_executor: global_io_executor,
132
+ global_fast_executor: global_fast_executor,
133
+ auto_terminate_all_executors: auto_terminate_all_executors,
134
+ auto_terminate_global_executors: auto_terminate_global_executors
135
+ }.freeze
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,39 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Author: Stefano Harding <riddopic@gmail.com>
4
+ # License: Apache License, Version 2.0
5
+ # Copyright: (C) 2014-2015 Stefano Harding
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require_relative 'core_ext/array'
21
+ require_relative 'core_ext/binding'
22
+ require_relative 'core_ext/boolean'
23
+ require_relative 'core_ext/enumerable'
24
+ require_relative 'core_ext/file'
25
+ require_relative 'core_ext/filetest'
26
+ require_relative 'core_ext/hash'
27
+ require_relative 'core_ext/kernel'
28
+ require_relative 'core_ext/lazy'
29
+ require_relative 'core_ext/method_access'
30
+ require_relative 'core_ext/nil'
31
+ require_relative 'core_ext/numeric'
32
+ require_relative 'core_ext/object'
33
+ require_relative 'core_ext/pathname'
34
+ require_relative 'core_ext/process'
35
+ require_relative 'core_ext/random'
36
+ require_relative 'core_ext/string'
37
+ require_relative 'core_ext/struct'
38
+ require_relative 'core_ext/symbol'
39
+ require_relative 'core_ext/time'
@@ -0,0 +1,27 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Author: Stefano Harding <riddopic@gmail.com>
4
+ # License: Apache License, Version 2.0
5
+ # Copyright: (C) 2014-2015 Stefano Harding
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ class Array
21
+ # Get or set state of object. You can think of #object_state as an in-code
22
+ # form of marshalling.
23
+ #
24
+ def object_state(data=nil)
25
+ data ? replace(data) : dup
26
+ end
27
+ end
@@ -0,0 +1,64 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Author: Stefano Harding <riddopic@gmail.com>
4
+ # License: Apache License, Version 2.0
5
+ # Copyright: (C) 2014-2015 Stefano Harding
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ class Binding
21
+
22
+ # Returns the call stack, same format as Kernel#caller()
23
+ #
24
+ def caller( skip=0 )
25
+ eval("caller(#{skip})")
26
+ end
27
+
28
+ # Return the line number on which the binding was created.
29
+ #
30
+ def __LINE__
31
+ Kernel.eval("__LINE__", self)
32
+ end
33
+
34
+ # Returns file name in which the binding was created.
35
+ #
36
+ def __FILE__
37
+ Kernel.eval("__FILE__", self)
38
+ end
39
+
40
+ # Return the directory of the file in which the binding was created.
41
+ #
42
+ def __DIR__
43
+ File.dirname(self.__FILE__)
44
+ end
45
+
46
+ # Retreive the current running method.
47
+ #
48
+ def __method__
49
+ Kernel.eval("__method__", self)
50
+ end
51
+
52
+ # Retreive the current running method.
53
+ #
54
+ def __callee__
55
+ Kernel.eval("__callee__", self)
56
+ end
57
+
58
+ # Returns the call stack, in array format.
59
+ def callstack(level=1)
60
+ eval( "callstack( #{level} )" )
61
+ end
62
+ alias_method :call_stack, :callstack
63
+ end
64
+