lib/hack_tree.rb in hack_tree-0.1.0 vs lib/hack_tree.rb in hack_tree-0.1.1
- old
+ new
@@ -1,16 +1,16 @@
+
+# Load all stuff.
[
"hack_tree/**/*.rb",
].each do |fmask|
- Dir[File.join(File.dirname(__FILE__), fmask)].each do |fn|
+ Dir[File.expand_path("../#{fmask}", __FILE__)].each do |fn|
require fn
end
end
module HackTree
- VERSION = "0.1.0"
-
# Standard hacks bundled with the gem, their global names.
STD_HACKS = [
"hack_tree.reload",
"ls",
]
@@ -55,26 +55,24 @@
end
# Enable HackTree globally.
#
# >> HackTree.enable
- # Greetings.
+ # Console hacks are available. Use `c`, `c.hack?`, `c.hack [args]`
+ #
# >> c
# hello # Say hello
+ #
# >> c.hello
# Hello, world!
#
# Options:
#
- # :completion => T|F # Enable completion enhancement. Default is true.
+ # :completion => T|F # Enable completion enhancement. Default is `true`.
# :with_std => [...] # Load only these standard hacks.
# :without_std => [...] # Load all but these standard hacks.
- # :quiet => T|F # Be quiet. Default is false.
- #
- # Examples:
- #
- # TODO.
+ # :quiet => T|F # Be quiet. Default is `false`.
def self.enable(method_name = :c, options = {})
options = options.dup
o = {}
o[k = :completion] = (v = options.delete(k)).nil?? true : v
@@ -140,12 +138,12 @@
STD_HACKS
end
global_names.each do |global_name|
bn = global_name.gsub(".", "/") + ".rb"
- fn = File.join(File.dirname(__FILE__), "../hacks", bn)
- load fn
+ fn = File.expand_path("../hacks/#{bn}", __FILE__)
+ require fn
end
nil
end
@@ -154,80 +152,6 @@
end
def self.instance
@instance ||= Instance.new
end
-end
-
-#--------------------------------------- Junk
-
-if false
- # * Using array is a reliable way to ensure a newline after the banner.
- ::Kernel.puts [
- #"",
- "Console hacks are available. Use `%s`, `%s.hack?`, `%s.hack [args]`" % ([@enabled_as]*3),
- #"",
- ]
-end
-
-if false
- # Node (group/hack) regexp without delimiters.
- NAME_REGEXP = /[a-zA-Z_]\w*/
-
- # Node names which can't be used due to serious reasons.
- FORBIDDEN_NAMES = [
- :inspect,
- :method_missing,
- :to_s,
- ]
-end
-
-if false
- # Create the action object.
- #
- # module Kernel
- # # Access our hacks via <tt>c</tt>.
- # def c
- # ::HackTree.action
- # end
- # end
- #
- # >> c
- # hello # Say hello
- # >> c.hello
- # Hello, world!
- #
- # See also ::enable.
- def self.action
- ActionContext.new(@nodes)
- end
-
- # Clear self.
- def self.clear
- # Request re-initialization upon first use of any kind.
- @is_initialized = false
- end
-
- # Access nodes (groups/hacks) created via the DSL.
- def self.nodes
- @nodes
- end
-
- # See #nodes.
- def self.nodes=(ar)
- @nodes = ar
- end
-
- # NOTE: We need this wrapper to create private singletons.
- class << self
- private
-
- # On-the-fly initializer.
- def _otf_init
- return if @is_initialized
-
- @is_initialized = true
- @nodes = []
- @dsl_root = DslContext.new(@nodes)
- end
- end # class << self
end