Permalink
Browse files

Removed a ton of snippets.

Most of these snippets were either unused by Ramaze itself or were originally
added to provide compatibility between Ruby 1.8/1.9. There also werent any
tests for quite a few of these snippets.

Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>
  • Loading branch information...
YorickPeterse committed Dec 6, 2012
1 parent 86cc398 commit 7e966dcdec50d490eb828f7673f101b1a6b087b3
View
@@ -1,35 +1,15 @@
# Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the MIT license.
-require 'ramaze/snippets/array/put_within'
-require 'ramaze/snippets/binding/locals'
require 'ramaze/snippets/blankslate'
-require 'ramaze/snippets/fiber'
-require 'ramaze/snippets/kernel/pretty_inspect'
-require 'ramaze/snippets/metaid'
-require 'ramaze/snippets/numeric/filesize_format'
-require 'ramaze/snippets/numeric/time'
require 'ramaze/snippets/object/__dir__'
-require 'ramaze/snippets/object/instance_variable_defined'
-require 'ramaze/snippets/object/pretty'
-require 'ramaze/snippets/object/scope'
-require 'ramaze/snippets/ordered_set'
-require 'ramaze/snippets/proc/locals'
-require 'ramaze/snippets/ramaze/acquire'
require 'ramaze/snippets/ramaze/deprecated'
-require 'ramaze/snippets/ramaze/dictionary'
-require 'ramaze/snippets/ramaze/fiber'
require 'ramaze/snippets/ramaze/lru_hash'
-require 'ramaze/snippets/ramaze/struct'
require 'ramaze/snippets/string/camel_case'
require 'ramaze/snippets/string/color'
-require 'ramaze/snippets/string/end_with'
require 'ramaze/snippets/string/esc'
-require 'ramaze/snippets/string/ord'
require 'ramaze/snippets/string/snake_case'
-require 'ramaze/snippets/string/start_with'
require 'ramaze/snippets/string/unindent'
-require 'ramaze/snippets/thread/into'
Ramaze::CoreExtensions.constants.each do |const|
ext = Ramaze::CoreExtensions.const_get(const)
@@ -1,38 +0,0 @@
-# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
-# All files in this distribution are subject to the terms of the MIT license.
-
-module Ramaze
- module CoreExtensions
- # Extensions for Array
- module Array
- # a = [1, 2, 3]
- # a.put_within(4, :after => 2, :before => 3)
- # a # => [1, 2, 4, 3]
- def put_within(object, constrain)
- pre, post = constrain.values_at(:after, :before)
-
- return put_after(pre, object) if rindex(post) - index(pre) == 1
-
- raise ArgumentError, "Too many elements within constrain"
- end
-
- # a = [1, 2, 3]
- # a.put_after(2, 4)
- # a # => [1, 2, 4, 3]
- def put_after(element, object)
- return self[index(element) + 1, 0] = object if include?(element)
-
- raise ArgumentError, "The given element doesn't exist"
- end
-
- # a = [1, 2, 3]
- # a.put_before(2, 4)
- # a # => [1, 4, 2, 3]
- def put_before(element, object)
- return self[rindex(element), 0] = object if include?(element)
-
- raise ArgumentError, "The given element doesn't exist"
- end
- end # Array
- end # CoreExtensions
-end # Ramaze
@@ -1,20 +0,0 @@
-module Ramaze
- module CoreExtensions
- # Extensions for Binding
- module Binding
- # Returns a hash of localvar/localvar-values from binding, useful for
- # template engines that do not accept bindings and force passing locals
- # via hash
- #
- # @example
- # x = 42; p binding.locals #=> {'x'=> 42}
- def locals
- ::Kernel::eval '
- local_variables.inject({}){|h,v|
- k = v.to_s
- h.merge!(k => eval(k))
- }', self
- end
- end # Binding
- end # CoreExtensions
-end # Ramaze
@@ -1,41 +0,0 @@
-unless defined? Fiber
- require 'thread'
-
- class FiberError < StandardError; end
-
- class Fiber
- def initialize
- raise ArgumentError, 'new Fiber requires a block' unless block_given?
-
- @yield = Queue.new
- @resume = Queue.new
-
- @thread = Thread.new{ @yield.push [*yield(*wait)] }
- @thread.abort_on_exception = true
- @thread[:fiber] = self
- end
- attr_reader :yield, :thread
-
- def resume *args
- raise FiberError, 'dead fiber called' unless @thread.alive?
- @resume.push(args)
- result = @yield.pop
- result.size > 1 ? result : result.first
- end
-
- def wait
- @resume.pop
- end
-
- def self.yield *args
- raise FiberError, "can't yield from root fiber" unless fiber = Thread.current[:fiber]
- fiber.yield.push(args)
- result = fiber.wait
- result.size > 1 ? result : result.first
- end
-
- def inspect
- "#<#{self.class}:0x#{self.object_id.to_s(16)}>"
- end
- end
-end
@@ -1,18 +0,0 @@
-# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
-# All files in this distribution are subject to the terms of the MIT license.
-
-require 'pp'
-
-module Ramaze
- module CoreExtensions
- # Extensions for Kernel
- module Kernel
- unless defined?(pretty_inspect)
- # returns a pretty printed object as a string.
- def pretty_inspect
- PP.pp(self, '')
- end
- end
- end # Kernel
- end # CoreExtensions
-end # Ramaze
@@ -1,17 +0,0 @@
-# from http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html
-
-class Object
- # The hidden singleton lurks behind everyone
- def metaclass; class << self; self; end; end
- def meta_eval &blk; metaclass.instance_eval(&blk); end
-
- # Adds methods to a metaclass
- def meta_def name, &blk
- meta_eval { define_method name, &blk }
- end
-
- # Defines an instance method within a class
- def class_def name, &blk
- class_eval { define_method name, &blk }
- end
-end
@@ -1,30 +0,0 @@
-# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
-# All files in this distribution are subject to the terms of the MIT license.
-
-module Ramaze
- module CoreExtensions
- # Extensions for Numeric
- module Numeric
- FILESIZE_FORMAT = [
- ['%.1fT', 1 << 40],
- ['%.1fG', 1 << 30],
- ['%.1fM', 1 << 20],
- ['%.1fK', 1 << 10],
- ]
-
- # Output this number as easily readable filesize.
- # Usage:
- # 100_000.filesize_format # => "97.7K"
- # 100_000_000.filesize_format # => "95.4M"
- # 100_000_000_000.filesize_format # => "93.1G"
- # 100_000_000_000_000.filesize_format # => "90.9T"
- def filesize_format
- FILESIZE_FORMAT.each do |format, size|
- return format % (self.to_f / size) if self >= size
- end
-
- self.to_s
- end
- end # Numeric
- end # CoreExtensions
-end # Ramaze
@@ -1,59 +0,0 @@
-module Ramaze
- module CoreExtensions
- # Extensions for Numeric
- module Numeric
- def seconds
- self
- end
- alias second seconds
-
- # 60 seconds in a minute
- def minutes
- self * 60
- end
- alias minute minutes
-
- # 60 minutes in an hour
- def hours
- self * 3600
- end
- alias hour hours
-
- # 24 hours in a day
- def days
- self * 86400
- end
- alias day days
-
- # 7 days in a week
- def weeks
- self * 604800
- end
- alias week weeks
-
- # 30 days in a month
- def months
- self * 2592000
- end
- alias month months
-
- # 365.25 days in a year
- def years
- self * 31557600
- end
- alias year years
-
- # Time in the past, i.e. 3.days.ago
- def ago t = Time.now
- t - self
- end
- alias before ago
-
- # Time in the future, i.e. 3.days.from_now
- def from_now t = Time.now
- t + self
- end
- alias since from_now
- end # Numeric
- end # CoreExtensions
-end # Ramaze
@@ -1,16 +0,0 @@
-# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
-# All files in this distribution are subject to the terms of the MIT license.
-
-module Ramaze
- module CoreExtensions
- # Extensions for Object
- module Object
- # Available in 1.8.6 and later.
- unless ::Object.method_defined?(:instance_variable_defined?)
- def instance_variable_defined?(variable)
- instance_variables.include?(variable.to_s)
- end
- end
- end # Object
- end # CoreExtensions
-end # Ramaze
@@ -1,12 +0,0 @@
-module Ramaze
- module CoreExtensions
- # Extensions for Object
- module Object
- # Returns the string that #pretty_inspect would yield
- def pretty s = ''
- PP.pp(self, s)
- s
- end
- end # Object
- end # CoreExtensions
-end # Ramaze
@@ -1,16 +0,0 @@
-module Ramaze
- module CoreExtensions
- # Extensions for Object
- module Object
- # returns a new clean binding for this object
- #
- # Usage:
- #
- # eval 'self', object.scope #=> returns object
- #
- def scope
- lambda{}
- end
- end # Object
- end # CoreExtensions
-end # Ramaze
@@ -1,51 +0,0 @@
-# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
-# All files in this distribution are subject to the terms of the MIT license.
-
-require(File.join(File.dirname(__FILE__), 'blankslate'))
-
-# Basically an Set, but with Order, ain't that obivous?
-class OrderedSet < BlankSlate
- def self.[](*args)
- new(*args)
- end
-
- # Create new instances, optionally pass the first set
- def initialize(*args)
- if args.size == 1
- @set = args.shift
- else
- @set = *args
- end
-
- @set ||= []
- @set = [@set] unless ::Array === @set
- @set.uniq!
- end
-
- %w[ push unshift << ].each do |meth|
- class_eval %[
- def #{meth} *args
- @set.delete(*args)
- @set.#{meth}(*args)
- end
- ]
- end
-
- def []= *args
- @set.map! do |e|
- if ::Array === args.last
- args.last.include?(e) ? nil : e
- else
- args.last == e ? nil : e
- end
- end
- @set.__send__(:[]=, *args)
- @set.compact!
- end
-
- # Delegate everything, but controlled, keep elements unique.
- # Warning, this is not really atomic.
- def method_missing(meth, *args, &block)
- @set.__send__(meth, *args, &block)
- end
-end
@@ -1,19 +0,0 @@
-module Ramaze
- module CoreExtensions
- # Extensions for Proc
- module Proc
- ##
- # Returns a hash of localvar/localvar-values from proc, useful for
- # template engines that do not accept bindings/proc and force passing
- # locals via hash
- #
- # Usage:
- #
- # x = 42; p Proc.new.locals #=> {'x'=> 42}
- #
- def locals
- instance_eval('binding').locals
- end
- end # Proc
- end # CoreExtensions
-end # Ramaze
Oops, something went wrong.

0 comments on commit 7e966dc

Please sign in to comment.