pax_global_header00006660000000000000000000000064120505462250014513gustar00rootroot0000000000000052 comment=cae61bc39b430efcac274ca2c4c1f41a10342fe4 ruby-tins-0.6.0/000077500000000000000000000000001205054622500134525ustar00rootroot00000000000000ruby-tins-0.6.0/.gitignore000066400000000000000000000000761205054622500154450ustar00rootroot00000000000000.*.sw[pon] .AppleDouble .rbx .rvmrc Gemfile.lock coverage pkg ruby-tins-0.6.0/.travis.yml000066400000000000000000000003321205054622500155610ustar00rootroot00000000000000rvm: - 1.8.6 - 1.8.7 - 1.9.2 - 1.9.3 - ruby-head - ree - rbx-18mode - rbx-19mode - jruby-18mode - jruby-19mode matrix: allow_failures: - rvm: 1.8.6 - rvm: rbx-18mode - rvm: rbx-19mode ruby-tins-0.6.0/Gemfile000066400000000000000000000002541205054622500147460ustar00rootroot00000000000000# vim: set filetype=ruby et sw=2 ts=2: source :rubygems gemspec group :development do gem 'simplecov', :platform => :mri_19 gem 'debugger', :platform => :mri_19 end ruby-tins-0.6.0/LICENSE000066400000000000000000000020211205054622500144520ustar00rootroot00000000000000Copyright (c) 2010 Florian Frank Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ruby-tins-0.6.0/README.rdoc000066400000000000000000000004761205054622500152670ustar00rootroot00000000000000= Tins - Useful tools library in Ruby == Description Non yet. == Download The homepage of this library is located at * http://flori.github.com/tins == Author Florian Frank mailto:flori@ping.de == License This software is licensed under the X11 (or MIT) license: http://www.xfree86.org/3.3.6/COPYRIGHT2.html#3 ruby-tins-0.6.0/Rakefile000066400000000000000000000015741205054622500151260ustar00rootroot00000000000000# vim: set filetype=ruby et sw=2 ts=2: require 'gem_hadar' GemHadar do name 'tins' author 'Florian Frank' email 'flori@ping.de' homepage "http://flori.github.com/#{name}" summary 'Useful stuff.' description 'All the stuff that isn\'t good/big enough for a real library.' test_dir 'tests' test_files.concat Dir["#{test_dir}/*_test.rb"] ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc', 'coverage', '.rbx', '.AppleDouble' readme 'README.rdoc' development_dependency 'test-unit', '~>2.5' development_dependency 'utils' install_library do libdir = CONFIG["sitelibdir"] cd 'lib' do for file in Dir['**/*.rb'] dst = File.join(libdir, file) mkdir_p File.dirname(dst) install file, dst end end install 'bin/enum', File.join(CONFIG['bindir'], 'enum') end end ruby-tins-0.6.0/TODO000066400000000000000000000000001205054622500141300ustar00rootroot00000000000000ruby-tins-0.6.0/VERSION000066400000000000000000000000061205054622500145160ustar00rootroot000000000000000.6.0 ruby-tins-0.6.0/lib/000077500000000000000000000000001205054622500142205ustar00rootroot00000000000000ruby-tins-0.6.0/lib/spruz.rb000066400000000000000000000000441205054622500157260ustar00rootroot00000000000000require 'tins' require 'tins/alias' ruby-tins-0.6.0/lib/tins.rb000066400000000000000000000022071205054622500155230ustar00rootroot00000000000000module Tins require 'tins/attempt' require 'tins/bijection' require 'tins/count_by' require 'tins/deep_dup' require 'tins/file_binary' require 'tins/find' require 'tins/generator' require 'tins/go' require 'tins/hash_symbolize_keys_recursive' require 'tins/hash_union' require 'tins/limited' require 'tins/lines_file' require 'tins/memoize' require 'tins/minimize' require 'tins/module_group' require 'tins/null' require 'tins/once' require 'tins/p' require 'tins/partial_application' require 'tins/range_plus' require 'tins/require_maybe' require 'tins/round' require 'tins/secure_write' require 'tins/shuffle' require 'tins/string_camelize' require 'tins/string_underscore' require 'tins/string_version' require 'tins/subhash' require 'tins/time_dummy' require 'tins/date_dummy' require 'tins/date_time_dummy' require 'tins/to_proc' require 'tins/uniq_by' require 'tins/version' require 'tins/write' require 'tins/extract_last_argument_options' require 'tins/deep_const_get' require 'tins/responding' require 'tins/proc_compose' require 'tins/concern' end require 'tins/alias' ruby-tins-0.6.0/lib/tins/000077500000000000000000000000001205054622500151755ustar00rootroot00000000000000ruby-tins-0.6.0/lib/tins/alias.rb000066400000000000000000000000151205054622500166070ustar00rootroot00000000000000Spruz = Tins ruby-tins-0.6.0/lib/tins/ask_and_send.rb000066400000000000000000000005261205054622500201360ustar00rootroot00000000000000module Tins module AskAndSend def ask_and_send(method_name, *args, &block) if respond_to?(method_name) __send__(method_name, *args, &block) end end def ask_and_send!(method_name, *args, &block) if respond_to?(method_name, true) __send__(method_name, *args, &block) end end end end ruby-tins-0.6.0/lib/tins/attempt.rb000066400000000000000000000022521205054622500172010ustar00rootroot00000000000000module Tins module Attempt def attempt(opts = {}, &block) sleep = nil exception_class = StandardError if Numeric === opts attempts = opts else attempts = opts[:attempts] || 1 exception_class = opts[:exception_class] if opts.key?(:exception_class) sleep = opts[:sleep] reraise = opts[:reraise] end return if attempts <= 0 count = 0 if exception_class.nil? begin count += 1 if block.call(count) return true elsif count < attempts sleep_duration(sleep, count) end end until count == attempts false else begin count += 1 block.call(count) true rescue exception_class if count < attempts sleep_duration(sleep, count) retry end reraise ? raise : false end end end private def sleep_duration(duration, count) case duration when Numeric sleep duration when Proc sleep duration.call(count) end end end end ruby-tins-0.6.0/lib/tins/bijection.rb000066400000000000000000000017431205054622500174750ustar00rootroot00000000000000module Tins class Bijection < Hash def self.[](*pairs) pairs.size % 2 == 0 or raise ArgumentError, "odd number of arguments for #{self}" new.fill do |obj| (pairs.size / 2).times do |i| j = 2 * i key = pairs[j] value = pairs[j + 1] obj.key?(key) and raise ArgumentError, "duplicate key #{key.inspect} for #{self}" obj.inverted.key?(value) and raise ArgumentError, "duplicate value #{value.inspect} for #{self}" obj[pairs[j]] = pairs[j + 1] end end end def initialize(inverted = Bijection.new(self)) @inverted = inverted end def fill if empty? yield self freeze end self end def freeze r = super unless @inverted.frozen? @inverted.freeze end r end def []=(key, value) key?(key) and return super @inverted[value] = key end attr_reader :inverted end end ruby-tins-0.6.0/lib/tins/concern.rb000066400000000000000000000013571205054622500171570ustar00rootroot00000000000000module Tins module Concern def self.extended(base) base.instance_variable_set("@_dependencies", []) end def append_features(base) if base.instance_variable_defined?("@_dependencies") base.instance_variable_get("@_dependencies") << self return false else return false if base < self @_dependencies.each { |dep| base.send(:include, dep) } super base.extend const_get("ClassMethods") if const_defined?("ClassMethods") base.class_eval(&@_included_block) if instance_variable_defined?("@_included_block") end end def included(base = nil, &block) if base.nil? @_included_block = block else super end end end end ruby-tins-0.6.0/lib/tins/count_by.rb000066400000000000000000000002211205054622500173370ustar00rootroot00000000000000module Tins module CountBy def count_by(&b) b ||= lambda { |x| true } inject(0) { |s, e| s += 1 if b[e]; s } end end end ruby-tins-0.6.0/lib/tins/date_dummy.rb000066400000000000000000000012431205054622500176520ustar00rootroot00000000000000require 'date' module Tins module DateDummy def self.included(modul) class << modul alias really_today today remove_method :today rescue nil attr_writer :dummy def dummy(value = nil) if value.nil? @dummy else begin old_dummy = @dummy @dummy = value yield ensure @dummy = old_dummy end end end def today if dummy dummy.dup else really_today end end end super end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/date_time_dummy.rb000066400000000000000000000012311205054622500206650ustar00rootroot00000000000000require 'date' module Tins module DateTimeDummy def self.included(modul) class << modul alias really_now now remove_method :now rescue nil attr_writer :dummy def dummy(value = nil) if value.nil? @dummy else begin old_dummy = @dummy @dummy = value yield ensure @dummy = old_dummy end end end def now if dummy dummy.dup else really_now end end end super end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/deep_const_get.rb000066400000000000000000000020111205054622500204760ustar00rootroot00000000000000module Tins module DeepConstGet if ::Object.method(:const_defined?).arity == 1 # :nocov: # We do not create coverage on 1.8 def self.const_defined_in?(modul, constant) modul.const_defined?(constant) end # :nocov: else def self.const_defined_in?(modul, constant) modul.const_defined?(constant, false) end end def deep_const_get(path, start_module = Object) path.to_s.split('::').inject(start_module) do |p, c| case when c.empty? if start_module == Object Object else raise ArgumentError, "top level constants cannot be reached from"\ " start module #{start_module.inspect}" end when ::Tins::DeepConstGet.const_defined_in?(p, c) then p.const_get(c) else begin p.const_missing(c) rescue NameError => e raise ArgumentError, "can't get const #{path}: #{e}" end end end end end end ruby-tins-0.6.0/lib/tins/deep_dup.rb000066400000000000000000000002441205054622500173070ustar00rootroot00000000000000module Tins module DeepDup def deep_dup Marshal.load(Marshal.dump(self)) rescue TypeError return self end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/extract_last_argument_options.rb000066400000000000000000000004731205054622500237000ustar00rootroot00000000000000module Tins module ExtractLastArgumentOptions def extract_last_argument_options last_argument = last if last_argument.respond_to?(:to_hash) and options = last_argument.to_hash.dup then return self[0..-2], options else return dup, {} end end end end ruby-tins-0.6.0/lib/tins/file_binary.rb000066400000000000000000000051651205054622500200140ustar00rootroot00000000000000require 'tins/xt/hash_union' module Tins module FileBinary module Constants SEEK_SET = ::File::SEEK_SET ZERO = "\x00" BINARY = "\x01-\x1f\x7f-\xff" if defined?(::Encoding) ZERO.force_encoding(Encoding::ASCII_8BIT) BINARY.force_encoding(Encoding::ASCII_8BIT) end end class << self # Default options can be queried/set via this hash. attr_accessor :default_options end self.default_options = { :offset => 0, :buffer_size => 2 ** 13, :percentage_binary => 30.0, :percentage_zeros => 0.0, } # Returns true if this file is considered to be binary, false if it is not # considered to be binary, and nil if it was empty. # # A file is considered to be binary if the percentage of zeros exceeds # options[:percentage_zeros] or the percentage of binary bytes # (8-th bit is 1) exceeds options[:percentage_binary] in the # buffer of size options[:buffer_size] that is checked (beginning # from offset options[:offset]). If an option isn't given the one # from FileBinary.default_options is used instead. def binary?(options = {}) options |= FileBinary.default_options old_pos = tell seek options[:offset], Constants::SEEK_SET data = read options[:buffer_size] !data or data.empty? and return nil data_size = data.size data.count(Constants::ZERO).to_f / data_size > options[:percentage_zeros] / 100.0 and return true data.count(Constants::BINARY).to_f / data_size > options[:percentage_binary] / 100.0 ensure old_pos and seek old_pos, Constants::SEEK_SET end # Returns true if FileBinary#binary? returns false, false if # FileBinary#binary? returns true, and nil otherwise. For an explanation of # +options+, see FileBinary#binary?. def ascii?(options = {}) case binary?(options) when true then false when false then true end end def self.included(modul) modul.instance_eval do extend ClassMethods end super end module ClassMethods # Returns true if the file with name +name+ is considered to be binary # using the FileBinary#binary? method. def binary?(name, options = {}) open(name, 'rb') { |f| f.binary?(options) } end # Returns true if the file with name +name+ is considered to be ascii # using the FileBinary#ascii? method. def ascii?(name, options = {}) open(name, 'rb') { |f| f.ascii?(options) } end end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/find.rb000066400000000000000000000067471205054622500164600ustar00rootroot00000000000000require 'enumerator' require 'pathname' require 'tins/module_group' module Tins module Find EXPECTED_STANDARD_ERRORS = ModuleGroup[ Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG ] class Finder module PathExtension attr_accessor :finder def finder_stat finder.protect_from_errors do finder.follow_symlinks ? File.stat(self) : File.lstat(self) end end def file finder.protect_from_errors do File.new(self) if file? end end def file? finder.protect_from_errors { s = finder_stat and s.file? } end def directory? finder.protect_from_errors { s = finder_stat and s.directory? } end def exist? finder.protect_from_errors { File.exist?(self) } end def stat finder.protect_from_errors { File.stat(self) } end def lstat finder.protect_from_errors { File.lstat(self) } end def pathname Pathname.new(self) end def suffix pathname.extname[1..-1] || '' end end def initialize(opts = {}) @show_hidden = opts.fetch(:show_hidden) { true } @raise_errors = opts.fetch(:raise_errors) { false } @follow_symlinks = opts.fetch(:follow_symlinks) { true } opts[:suffix].full? { |s| @suffix = [*s] } end attr_accessor :show_hidden attr_accessor :raise_errors attr_accessor :follow_symlinks attr_accessor :suffix def visit_path?(path) @suffix.nil? || @suffix.include?(path.suffix) end def find(*paths) block_given? or return enum_for(__method__, *paths) paths.collect! { |d| d.dup } while path = paths.shift path = prepare_path(path) catch(:prune) do stat = path.finder_stat or next visit_path?(path) and yield path if stat.directory? ps = protect_from_errors { Dir.entries(path) } or next ps.sort! ps.reverse_each do |p| next if p == "." or p == ".." next if !@show_hidden && p.start_with?('.') p = File.join(path, p) paths.unshift p.untaint end end end end end def prepare_path(path) path = path.dup.taint path.extend PathExtension path.finder = self path end def protect_from_errors(errors = Find::EXPECTED_STANDARD_ERRORS) yield rescue errors raise_errors and raise return end end # # Calls the associated block with the name of every path and directory # listed as arguments, then recursively on their subdirectories, and so on. # # See the +Find+ module documentation for an example. # def find(*paths, &block) # :yield: path opts = Hash === paths.last ? paths.pop : {} Finder.new(opts).find(*paths, &block) end # # Skips the current path or directory, restarting the loop with the next # entry. If the current path is a directory, that directory will not be # recursively entered. Meaningful only within the block associated with # Find::find. # # See the +Find+ module documentation for an example. # def prune throw :prune end module_function :find, :prune end end ruby-tins-0.6.0/lib/tins/generator.rb000066400000000000000000000037541205054622500175210ustar00rootroot00000000000000module Tins # This class can create generator objects, that can produce all tuples, that # would be created by as many for-loops as dimensions were given. # # The generator # g = Tins::Generator[1..2, %w[a b c]] # produces # g.to_a # => [[1, "a"], [1, "b"], [1, "c"], [2, "a"], [2, "b"], [2, "c"]] # # The 'each' method can be used to iterate over the tuples # g.each { |a, b| puts "#{a} #{b}" } # and Tins::Generator includes the Enumerable module, so # Enumerable.instance_methods can be used as well: # g.select { |a, b| %w[a c].include? b } # => [[1, "a"], [1, "c"], [2, "a"], [2, "c"]] # class Generator include Enumerable # Create a new Generator object from the enumberables _enums_. def self.[](*enums) new(enums) end # Create a new Generator instance. Use the objects in the Array _enums_ # as dimensions. The should all respond to the :each method (see module # Enumerable in the core ruby library). def initialize(enums) @enums, @iterators, @n = [], [], 0 enums.each { |e| add_dimension(e) } end # Iterate over all tuples produced by this generator and yield to them. def each(&block) # :yield: tuple recurse(&block) self end def recurse(tuple = [ nil ] * @n, i = 0, &block) if i < @n - 1 then @enums[i].__send__(@iterators[i]) do |x| tuple[i] = x recurse(tuple, i + 1, &block) end else @enums[i].__send__(@iterators[i]) do |x| tuple[i] = x yield tuple.dup end end end private :recurse # Add another dimension to this generator. _enum_ is an object, that ought # to respond to the _iterator_ method (defaults to :each). def add_dimension(enum, iterator = :each) @enums << enum @iterators << iterator @n += 1 end # Return the size of this generator, that is the number of its dimensions. def size @enums.size end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/go.rb000066400000000000000000000031731205054622500161330ustar00rootroot00000000000000module Tins module GO module EnumerableExtension def push(argument) @arguments ||= [] @arguments.push argument self end def each(&block) @arguments.each(&block) self end include Enumerable end module_function # Parses the argument array _args_, according to the pattern _s_, to # retrieve the single character command line options from it. If _s_ is # 'xy:' an option '-x' without an option argument is searched, and an # option '-y foo' with an option argument ('foo'). # # An option hash is returned with all found options set to true or the # found option argument. def go(s, args = ARGV) b, v = s.scan(/(.)(:?)/).inject([ {}, {} ]) { |t, (o, a)| a = a == ':' t[a ? 1 : 0][o] = a ? nil : false t } while a = args.shift a !~ /\A-(.+)/ and args.unshift a and break p = $1 until p == '' o = p.slice!(0, 1) if v.key?(o) if p == '' then a = args.shift or break 1 else a = p end if v[o].nil? a = a.dup a.extend EnumerableExtension a.push a v[o] = a else v[o].push a end break elsif b.key?(o) if b[o] == false b[o]= 1 else b[o] += 1 end else args.unshift a break 1 end end and break end b.merge(v) end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/hash_symbolize_keys_recursive.rb000066400000000000000000000011441205054622500236640ustar00rootroot00000000000000module Tins module HashSymbolizeKeysRecursive def symbolize_keys_recursive inject(self.class.new) do |h,(k, v)| k = k.to_s k.empty? and next case v when Hash h[k.to_sym] = v.symbolize_keys_recursive when Array h[k.to_sym] = a = v.dup v.each_with_index do |x, i| Hash === x and a[i] = x.symbolize_keys_recursive end else h[k.to_sym] = v end h end end def symbolize_keys_recursive! replace symbolize_keys_recursive end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/hash_union.rb000066400000000000000000000004111205054622500176510ustar00rootroot00000000000000module Tins module HashUnion def |(other) case when other.respond_to?(:to_hash) other = other.to_hash when other.respond_to?(:to_h) other = other.to_h end other.merge(self) end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/if_predicate.rb000066400000000000000000000001271205054622500201400ustar00rootroot00000000000000module Tins module IfPredicate def if? self ? self : nil end end end ruby-tins-0.6.0/lib/tins/limited.rb000066400000000000000000000015261205054622500171550ustar00rootroot00000000000000require 'thread' module Tins class Limited # Create a Limited instance, that runs _maximum_ threads at most. def initialize(maximum) @mutex = Mutex.new @continue = ConditionVariable.new @maximum = Integer(maximum) raise ArgumentError, "maximum < 1" if @maximum < 1 @count = 0 end # The maximum number of worker threads. attr_reader :maximum # Execute _maximum_ number of threads in parallel. def execute @mutex.synchronize do loop do if @count < @maximum @count += 1 Thread.new do yield @mutex.synchronize { @count -= 1 } @continue.signal end return else @continue.wait(@mutex) end end end end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/lines_file.rb000066400000000000000000000047361205054622500176450ustar00rootroot00000000000000module Tins class LinesFile module LineExtension attr_reader :line_number def filename lines_file.filename.dup end end def self.for_filename(filename, line_number = nil) obj = new(File.readlines(filename), line_number) obj.filename = filename obj end def self.for_file(file, line_number = nil) obj = new(file.readlines, line_number) obj.filename = file.path obj end def self.for_lines(lines, line_number = nil) new(lines, line_number) end def initialize(lines, line_number = nil) @lines = lines @lines.each_with_index do |line, i| line.extend LineExtension line.instance_variable_set :@line_number, i + 1 line.instance_variable_set :@lines_file, self end instance_variable_set :@line_number, line_number || (@lines.empty? ? 0 : 1) end attr_accessor :filename attr_reader :line_number def rewind self.line_number = 1 self end def next! old = line_number self.line_number += 1 line_number > old ? self : nil end def previous! old = line_number self.line_number -= 1 line_number < old ? self : nil end def line_number=(number) number = number.to_i if number > 0 && number <= last_line_number @line_number = number end end def last_line_number @lines.size end def empty? @lines.empty? end def each(&block) empty? and return self old_line_number = line_number 1.upto(last_line_number) do |number| self.line_number = number block.call(line) end self ensure self.line_number = old_line_number end include Enumerable def line index = line_number - 1 @lines[index] if index >= 0 end def file_linenumber "#{filename}:#{line_number}" end def match_backward(regexp, previous_after_match = false) begin if line =~ regexp previous_after_match and previous! return $~.captures end end while previous! end def match_forward(regexp, next_after_match = false) begin if line =~ regexp next_after_match and next! return $~.captures end end while next! end def to_s "#{line_number} #{line.chomp}" end def inspect "#<#{self.class}: #{to_s.inspect}>" end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/memoize.rb000066400000000000000000000040771205054622500171770ustar00rootroot00000000000000module Tins module Memoize module CacheMethods # Return the cache object. def __memoize_cache__ @__memoize_cache__ ||= {} end # Clear cached values for all methods/functions. def memoize_cache_clear __memoize_cache__.clear self end end class ::Module # Automatically memoize calls of the the methods +method_ids+. The # memoized results do NOT ONLY depend on the arguments, but ALSO on the # object the method is called on. def memoize_method(*method_ids) include CacheMethods method_ids.each do |method_id| method_id = method_id.to_s.to_sym orig_method = instance_method(method_id) __send__(:define_method, method_id) do |*args| mc = __memoize_cache__ if mc.key?(method_id) and result = mc[method_id][args] result else (mc[method_id] ||= {})[args] = result = orig_method.bind(self).call(*args) $DEBUG and warn "#{self.class} cached method #{method_id}(#{args.inspect unless args.empty?}) = #{result.inspect} [#{__id__}]" end result end end end include CacheMethods # Automatically memoize calls of the functions +function_ids+. The # memoized result does ONLY depend on the arguments given to the # function. def memoize_function(*function_ids) mc = __memoize_cache__ function_ids.each do |method_id| method_id = method_id.to_s.to_sym orig_method = instance_method(method_id) __send__(:define_method, method_id) do |*args| if mc.key?(method_id) and result = mc[method_id][args] result else (mc[method_id] ||= {})[args] = result = orig_method.bind(self).call(*args) $DEBUG and warn "#{self.class} cached function #{method_id}(#{args.inspect unless args.empty?}) = #{result.inspect}" end result end end end end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/minimize.rb000066400000000000000000000033621205054622500173470ustar00rootroot00000000000000module Tins # This module can be mixed into all classes, whose instances respond to the # [] and size-methods, like for example Array. The returned elements from [] # should respond to the succ method. module Minimize # Returns a minimized version of this object, that is successive elements # are substituted with ranges a..b. In the situation ..., x, y,... and y != # x.succ a range x..x is created, to make it easier to iterate over all the # ranges in one run. A small example: # [ 'A', 'B', 'C', 'G', 'K', 'L', 'M' ].minimize # => [ 'A'..'C', 'G'..'G', 'K'..'M' ] # # If the order of the original elements doesn't matter, it's a good idea to # first sort them and then minimize: # [ 5, 1, 4, 2 ].sort.minimize # => [ 1..2, 4..5 ] def minimize result = [] last_index = size - 1 size.times do |i| result << [ self[0] ] if i == 0 if self[i].succ != self[i + 1] or i == last_index result[-1] << self[i] result << [ self[i + 1] ] unless i == last_index end end result.map! { |a, b| a..b } end # First minimizes this object, then calls the replace method with the # result. def minimize! replace minimize end # Invert a minimized version of an object. Some small examples: # [ 'A'..'C', 'G'..'G', 'K'..'M' ].unminimize # => [ 'A', 'B', 'C', 'G', 'K', 'L', 'M' ] # and # [ 1..2, 4..5 ].unminimize # => [ 1, 2, 4, 5 ] def unminimize result = [] for range in self for e in range result << e end end result end # Invert a minimized version of this object in place. def unminimize! replace unminimize end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/module_group.rb000066400000000000000000000003241205054622500202220ustar00rootroot00000000000000module Tins module ModuleGroup def self.[](*modules) modul = Module.new modules.each do |m| m.module_eval { include modul } end modul end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/null.rb000066400000000000000000000013301205054622500164710ustar00rootroot00000000000000module Tins # Implementation of the null object pattern in Ruby. module Null def method_missing(*) self end def const_missing(*) self end def to_s '' end def to_str nil end def to_f 0.0 end def to_i 0 end def to_int nil end def to_a [] end def to_ary nil end def inspect 'NULL' end def nil? true end def blank? true end module Kernel def Null(value = nil) value.nil? ? Tins::NULL : value end end end class NullClass < Module include Tins::Null end NULL = NullClass.new.freeze end require 'tins/alias' ruby-tins-0.6.0/lib/tins/once.rb000066400000000000000000000010571205054622500164510ustar00rootroot00000000000000module Tins module Once include File::Constants module_function def only_once(lock_filename = nil, locking_constant = nil) lock_filename ||= $0 locking_constant ||= LOCK_EX f = File.new(lock_filename, RDONLY) f.flock(locking_constant) and yield ensure if f f.flock LOCK_UN f.close end end def try_only_once(lock_filename = nil, locking_constant = nil, &block) only_once(lock_filename, locking_constant || LOCK_EX | LOCK_NB, &block) end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/p.rb000066400000000000000000000011631205054622500157620ustar00rootroot00000000000000require 'pp' module Tins module P private # Raise a runtime error with the inspected objects +objs+ (obtained by # calling the #inspect method) as their message text. This is useful for # quick debugging. def p!(*objs) raise((objs.size < 2 ? objs.first : objs).inspect) end # Raise a runtime error with the inspected objects +objs+ (obtained by # calling the #pretty_inspect method) as their message text. This is useful # for quick debugging. def pp!(*objs) raise("\n" + (objs.size < 2 ? objs.first : objs).pretty_inspect.chomp) end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/partial_application.rb000066400000000000000000000015211205054622500215400ustar00rootroot00000000000000module Tins module PartialApplication # If this module is included into a Proc (or similar object), it tampers # with its Proc#arity method. def self.included(modul) modul.module_eval do old_arity = instance_method(:arity) define_method(:arity) do @__arity__ or old_arity.bind(self).call end end super end # Create a partial application of this Proc (or similar object) using # _args_ as the already applied arguments. def partial(*args) if args.empty? dup elsif args.size > arity raise ArgumentError, "wrong number of arguments (#{args.size} for #{arity})" else f = lambda { |*b| call(*(args + b)) } f.instance_variable_set :@__arity__, arity - args.size f end end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/proc_compose.rb000066400000000000000000000002311205054622500202060ustar00rootroot00000000000000module Tins module ProcCompose def compose(other) self.class.new { |*args| call(*other.call(*args)) } end alias * compose end end ruby-tins-0.6.0/lib/tins/range_plus.rb000066400000000000000000000001601205054622500176560ustar00rootroot00000000000000module Tins module RangePlus def +(other) to_a + other.to_a end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/require_maybe.rb000066400000000000000000000002421205054622500203510ustar00rootroot00000000000000module Tins module RequireMaybe def require_maybe(library) require library rescue LoadError => e block_given? and yield e end end end ruby-tins-0.6.0/lib/tins/responding.rb000066400000000000000000000006131205054622500176720ustar00rootroot00000000000000module Tins module Responding def responding?(*method_names) Class.new do define_method(:to_s) do "Responding to #{method_names * ', '}" end alias inspect to_s define_method(:===) do |object| method_names.all? do |method_name| object.respond_to?(method_name) end end end.new end end end ruby-tins-0.6.0/lib/tins/round.rb000066400000000000000000000023331205054622500166520ustar00rootroot00000000000000module Tins # A bit more versatile rounding for Ruby module Round def self.included(klass) if klass.instance_method(:round) klass.class_eval do begin alias_method :__old_round__, :round remove_method :round rescue NameError end end super else raise NoMethodError, 'no round method found' end end def round(places = nil) if places == nil || places == 0 return __old_round__ elsif places.respond_to?(:to_int) places = places.to_int else raise TypeError, "argument places has to be like an Integer" end if places < 0 max_places = -Math.log(self.abs + 1) / Math.log(10) raise ArgumentError, "places has to be >= #{max_places.ceil}" if max_places > places end t = self f = 10.0 ** places t *= f if t.infinite? result = self else if t >= 0.0 t = (t + 0.5).floor elsif t < 0.0 t = (t - 0.5).ceil end t /= f result = t.nan? ? self : t end max_places and result = result.to_i # if places < 0 result end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/secure_write.rb000066400000000000000000000012441205054622500202230ustar00rootroot00000000000000module Tins module SecureWrite # Write to a file atomically def secure_write(filename, content = nil, mode = 'w') temp = File.new(filename + ".tmp.#$$.#{Time.now.to_f}", mode) if content.nil? and block_given? yield temp elsif !content.nil? temp.write content else raise ArgumentError, "either content or block argument required" end temp.fsync size = temp.stat.size temp.close File.rename temp.path, filename size ensure if temp !temp.closed? and temp.close File.file?(temp.path) and File.unlink temp.path end end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/shuffle.rb000066400000000000000000000004141205054622500171550ustar00rootroot00000000000000module Tins module Shuffle # :nocov: def shuffle! (size - 1) .downto(1) do |i| j = rand(i + 1) self[i], self[j] = self[j], self[i] end self end def shuffle dup.shuffle! end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/string_camelize.rb000066400000000000000000000005411205054622500207010ustar00rootroot00000000000000module Tins module StringCamelize def camelize(first_letter = :upper) case first_letter when :upper, true gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } when :lower, false self[0].chr.downcase + camelize[1..-1] end end alias camelcase camelize end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/string_underscore.rb000066400000000000000000000004451205054622500212640ustar00rootroot00000000000000module Tins module StringUnderscore def underscore word = dup word.gsub!(/::/, '/') word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2') word.gsub!(/([a-z\d])([A-Z])/,'\1_\2') word.tr!("-", "_") word.downcase! word end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/string_version.rb000066400000000000000000000034121205054622500205750ustar00rootroot00000000000000require 'tins/xt/symbol_to_proc' module Tins module StringVersion class Version include Comparable def initialize(string) string =~ /\A[\.\d]+\z/ or raise ArgumentError, "#{string.inspect} isn't a version number" @version = string.frozen? ? string.dup : string end def major self[0] end def major=(number) self[0] = number end def minor self[1] end def minor=(number) self[1] = number end def build self[2] end def build=(number) self[2] = number end def revision self[3] end def revision=(number) self[3] = number end def [](index) array[index] end def []=(index, value) value = value.to_i value >= 0 or raise ArgumentError, "version numbers can't contain negative numbers like #{value}" a = array @array = nil a[index] = value a.map! { |x| x.nil? ? 0 : x } @version.replace a * '.' end def succ! self[-1] += 1 end def pred! self[-1] -= 1 end def <=>(other) pairs = array.zip(other.array) pairs.map! { |a, b| [ a.nil? ? 0 : a, b.nil? ? 0 : b ] } a, b = pairs.transpose a <=> b end def ==(other) (self <=> other).zero? end def array @version.split('.').map(&:to_i) end alias to_a array def to_s @version end alias inspect to_s def version self end end def version if frozen? Version.new(self) else @version ||= Version.new(self) end end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/subhash.rb000066400000000000000000000024131205054622500171570ustar00rootroot00000000000000module Tins module Subhash # Create a subhash from this hash, that only contains key-value pairs # matching +patterns+ and return it. +patterns+ can be for example /^foo/ # to put 'foobar' and 'foobaz' or 'foo'/:foo to put 'foo' into the subhash. # # If a block is given this method yields to it after the first pattern # matched with a 3-tuple of +(key, value, match_data)+ using the return # value of the block as the value of the result hash. +match_data+ is a # MatchData instance if the matching pattern was a regular rexpression # otherwise it is nil. def subhash(*patterns) patterns.map! do |pat| pat = pat.to_sym.to_s if pat.respond_to?(:to_sym) pat.respond_to?(:match) ? pat : pat.to_s end result = if default_proc self.class.new(&default_proc) else self.class.new(default) end if block_given? each do |k, v| patterns.each { |pat| if pat === k.to_s result[k] = yield(k, v, $~) break end } end else each do |k, v| result[k] = v if patterns.any? { |pat| pat === k.to_s } end end result end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/time_dummy.rb000066400000000000000000000014701205054622500176750ustar00rootroot00000000000000module Tins module TimeDummy def self.included(modul) class << modul alias really_new new alias really_now now remove_method :now rescue nil remove_method :new rescue nil attr_writer :dummy def dummy(value = nil) if value.nil? @dummy else begin old_dummy = @dummy @dummy = value yield ensure @dummy = old_dummy end end end def new(*a) if dummy dummy.dup elsif caller.first =~ /now/ really_now else really_new(*a) end end def now new end end super end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/to_proc.rb000066400000000000000000000002621205054622500171670ustar00rootroot00000000000000module Tins module ToProc # :nocov: def to_proc lambda do |obj, *args| obj.__send__(self, *args[0..-1]) end end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/uniq_by.rb000066400000000000000000000002511205054622500171660ustar00rootroot00000000000000module Tins module UniqBy def uniq_by(&b) b ||= lambda { |x| x } inject({}) { |h, e| h[b[e]] ||= e; h }.values end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/version.rb000066400000000000000000000004171205054622500172110ustar00rootroot00000000000000module Tins # Tins version VERSION = '0.6.0' VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc: VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc: VERSION_MINOR = VERSION_ARRAY[1] # :nodoc: VERSION_BUILD = VERSION_ARRAY[2] # :nodoc: end ruby-tins-0.6.0/lib/tins/write.rb000066400000000000000000000007141205054622500166560ustar00rootroot00000000000000require 'tins/secure_write' module Tins module Write def self.extended(modul) modul.extend SecureWrite if modul.respond_to?(:write) $DEBUG and warn "Skipping inclusion of Tins::Write#write method, include Tins::Write::SecureWrite#secure_write instead" else class << modul; self; end.instance_eval do alias_method :write, :secure_write end end super end end end require 'tins/alias' ruby-tins-0.6.0/lib/tins/xt.rb000066400000000000000000000017501205054622500161600ustar00rootroot00000000000000require 'tins' module Tins require 'tins/xt/attempt' require 'tins/xt/blank' require 'tins/xt/count_by' require 'tins/xt/deep_dup' require 'tins/xt/file_binary' require 'tins/xt/full' require 'tins/xt/hash_symbolize_keys_recursive' require 'tins/xt/hash_union' require 'tins/xt/irb' require 'tins/xt/named' require 'tins/xt/null' require 'tins/xt/p' require 'tins/xt/partial_application' require 'tins/xt/range_plus' require 'tins/xt/require_maybe' require 'tins/xt/round' require 'tins/xt/secure_write' require 'tins/xt/string' require 'tins/xt/subhash' require 'tins/xt/symbol_to_proc' require 'tins/xt/time_dummy' require 'tins/xt/date_dummy' require 'tins/xt/date_time_dummy' require 'tins/xt/uniq_by' require 'tins/xt/write' require 'tins/xt/if_predicate' require 'tins/xt/ask_and_send' require 'tins/xt/extract_last_argument_options' require 'tins/xt/deep_const_get' require 'tins/xt/responding' require 'tins/xt/proc_compose' end ruby-tins-0.6.0/lib/tins/xt/000077500000000000000000000000001205054622500156305ustar00rootroot00000000000000ruby-tins-0.6.0/lib/tins/xt/ask_and_send.rb000066400000000000000000000001411205054622500205620ustar00rootroot00000000000000require 'tins/ask_and_send' module Tins class ::Object include Tins::AskAndSend end end ruby-tins-0.6.0/lib/tins/xt/attempt.rb000066400000000000000000000001311205054622500176260ustar00rootroot00000000000000require 'tins/attempt' module Tins class ::Object include Tins::Attempt end end ruby-tins-0.6.0/lib/tins/xt/blank.rb000066400000000000000000000017461205054622500172540ustar00rootroot00000000000000module Tins module Blank module Object def blank? respond_to?(:empty?) ? empty? : !self end def present? !blank? end end module NilClass def blank? true end end module FalseClass def blank? true end end module TrueClass def blank? false end end module Array def self.included(modul) modul.module_eval do alias_method :blank?, :empty? end end end module Hash def self.included(modul) modul.module_eval do alias_method :blank?, :empty? end end end module String def blank? self !~ /\S/ end end module Numeric def blank? false end end end unless Object.respond_to?(:blank?) for k in Blank.constants Object.const_get(k).class_eval do include Blank.const_get(k) end end end end ruby-tins-0.6.0/lib/tins/xt/count_by.rb000066400000000000000000000002041205054622500177730ustar00rootroot00000000000000require 'tins/count_by' module Tins module ::Enumerable include CountBy end class ::Array include CountBy end end ruby-tins-0.6.0/lib/tins/xt/date_dummy.rb000066400000000000000000000001261205054622500203040ustar00rootroot00000000000000require 'tins/date_dummy' module Tins class ::Date include DateDummy end end ruby-tins-0.6.0/lib/tins/xt/date_time_dummy.rb000066400000000000000000000001431205054622500213210ustar00rootroot00000000000000require 'tins/date_time_dummy' module Tins class ::DateTime include DateTimeDummy end end ruby-tins-0.6.0/lib/tins/xt/deep_const_get.rb000066400000000000000000000001371205054622500211400ustar00rootroot00000000000000require 'tins/deep_const_get' module Tins class ::Object include DeepConstGet end end ruby-tins-0.6.0/lib/tins/xt/deep_dup.rb000066400000000000000000000001321205054622500177360ustar00rootroot00000000000000require 'tins/deep_dup' module Tins class ::Object include Tins::DeepDup end end ruby-tins-0.6.0/lib/tins/xt/extract_last_argument_options.rb000066400000000000000000000001731205054622500243300ustar00rootroot00000000000000require 'tins/extract_last_argument_options' module Tins class ::Array include ExtractLastArgumentOptions end end ruby-tins-0.6.0/lib/tins/xt/file_binary.rb000066400000000000000000000001301205054622500204320ustar00rootroot00000000000000require 'tins/file_binary' module Tins class ::File include FileBinary end end ruby-tins-0.6.0/lib/tins/xt/full.rb000066400000000000000000000017741205054622500171300ustar00rootroot00000000000000require 'tins/xt/blank' module Tins module Full # Returns the object if it isn't blank (as in Object#blank?), otherwise it # returns nil. If a block was given as an argument and the object isn't # blank, the block is executed with the object as its first argument. If an # argument +dispatch+ was given and the object wasn't blank the method # given by dispatch is called on the object. This is the same as # foo.full?(&:bar) in the previous block form. def full?(dispatch = nil, *args) if blank? obj = nil #elsif Module === dispatch # TODO # dispatch.found?(self) elsif dispatch obj = __send__(dispatch, *args) obj = nil if obj.blank? else obj = self end if block_given? and obj yield obj else obj end end def all_full? if respond_to?(:all?) && all?(&:full?) block_given? ? yield(self) : self end end end class ::Object include Full end end ruby-tins-0.6.0/lib/tins/xt/hash_symbolize_keys_recursive.rb000066400000000000000000000001721205054622500243170ustar00rootroot00000000000000require 'tins/hash_symbolize_keys_recursive' module Tins class ::Hash include HashSymbolizeKeysRecursive end end ruby-tins-0.6.0/lib/tins/xt/hash_union.rb000066400000000000000000000003261205054622500203110ustar00rootroot00000000000000require 'tins/hash_union' module Tins class ::Hash if method_defined?(:|) warn "#{self}#| already defined, didn't include at #{__FILE__}:#{__LINE__}" else include HashUnion end end end ruby-tins-0.6.0/lib/tins/xt/if_predicate.rb000066400000000000000000000001421205054622500205700ustar00rootroot00000000000000require 'tins/if_predicate' module Tins class ::Object include Tins::IfPredicate end end ruby-tins-0.6.0/lib/tins/xt/irb.rb000066400000000000000000000006541205054622500167360ustar00rootroot00000000000000require 'irb' module Tins IRB = ::IRB module ::IRB def self.examine(binding = TOPLEVEL_BINDING) setup nil workspace = WorkSpace.new binding irb = Irb.new workspace @CONF[:MAIN_CONTEXT] = irb.context catch(:IRB_EXIT) { irb.eval_input } rescue Interrupt exit end end class ::Object def examine(binding = TOPLEVEL_BINDING) IRB.examine(binding) end end end ruby-tins-0.6.0/lib/tins/xt/named.rb000066400000000000000000000017231205054622500172440ustar00rootroot00000000000000require 'tins/xt/string_version' class Object if RUBY_VERSION.version >= '1.9'.version def named(name, method, *args, &named_block) extend Module.new { define_method(name) do |*rest, &block| block = named_block if named_block __send__(method, *(args + rest), &block) end } end else def named(name, method, *args, &block) extend Module.new { define_method(name) { |*rest| __send__(method, *(args + rest), &block) } } end end end class Module if RUBY_VERSION.version >= '1.9'.version def named(name, method, *args, &named_block) include Module.new { define_method(name) do |*rest, &block| block = named_block if named_block __send__(method, *(args + rest), &block) end } end else def named(name, method, *args, &block) include Module.new { define_method(name) { |*rest| __send__(method, *(args + rest), &block) } } end end end ruby-tins-0.6.0/lib/tins/xt/null.rb000066400000000000000000000001621205054622500171260ustar00rootroot00000000000000require 'tins/null' module Tins ::NULL = Tins::NULL class ::Object include Tins::Null::Kernel end end ruby-tins-0.6.0/lib/tins/xt/p.rb000066400000000000000000000001151205054622500164110ustar00rootroot00000000000000require 'tins/p' module Tins class ::Object include Tins::P end end ruby-tins-0.6.0/lib/tins/xt/partial_application.rb000066400000000000000000000002371205054622500221760ustar00rootroot00000000000000require 'tins/partial_application' module Tins class ::Proc include PartialApplication end class ::Method include PartialApplication end end ruby-tins-0.6.0/lib/tins/xt/proc_compose.rb000066400000000000000000000001401205054622500206400ustar00rootroot00000000000000require 'tins/proc_compose' module Tins class ::Proc include Tins::ProcCompose end end ruby-tins-0.6.0/lib/tins/xt/range_plus.rb000066400000000000000000000003301205054622500203100ustar00rootroot00000000000000require 'tins/range_plus' module Tins class ::Range if method_defined?(:+) warn "#{self}#+ already defined, didn't include at #{__FILE__}:#{__LINE__}" else include RangePlus end end end ruby-tins-0.6.0/lib/tins/xt/require_maybe.rb000066400000000000000000000001441205054622500210050ustar00rootroot00000000000000require 'tins/require_maybe' module Tins class ::Object include Tins::RequireMaybe end end ruby-tins-0.6.0/lib/tins/xt/responding.rb000066400000000000000000000001371205054622500203260ustar00rootroot00000000000000require 'tins/responding' module Tins class ::Object include Tins::Responding end end ruby-tins-0.6.0/lib/tins/xt/round.rb000066400000000000000000000002321205054622500173010ustar00rootroot00000000000000require 'tins/round' module Tins module Round class ::Float include Round end class ::Integer include Round end end end ruby-tins-0.6.0/lib/tins/xt/secure_write.rb000066400000000000000000000002261205054622500206550ustar00rootroot00000000000000require 'tins/secure_write' module Tins #class ::Object # include Tins::SecureWrite #end class ::IO extend Tins::SecureWrite end end ruby-tins-0.6.0/lib/tins/xt/shuffle.rb000066400000000000000000000003361205054622500176130ustar00rootroot00000000000000require 'tins/shuffle' module Tins class ::Array if method_defined?(:shuffle) warn "#{self}#shuffle already defined, didn't include at #{__FILE__}:#{__LINE__}" else include Shuffle end end end ruby-tins-0.6.0/lib/tins/xt/string.rb000066400000000000000000000001751205054622500174660ustar00rootroot00000000000000module Tins require 'tins/xt/string_camelize' require 'tins/xt/string_underscore' require 'tins/xt/string_version' end ruby-tins-0.6.0/lib/tins/xt/string_camelize.rb000066400000000000000000000001431205054622500213320ustar00rootroot00000000000000module Tins require 'tins/string_camelize' class ::String include StringCamelize end end ruby-tins-0.6.0/lib/tins/xt/string_underscore.rb000066400000000000000000000001471205054622500217160ustar00rootroot00000000000000module Tins require 'tins/string_underscore' class ::String include StringUnderscore end end ruby-tins-0.6.0/lib/tins/xt/string_version.rb000066400000000000000000000001421205054622500212250ustar00rootroot00000000000000module Tins require 'tins/string_version' class ::String include StringVersion end end ruby-tins-0.6.0/lib/tins/xt/subhash.rb000066400000000000000000000002351205054622500176120ustar00rootroot00000000000000require 'tins/subhash' module Tins class ::Hash include Tins::Subhash def subhash!(*patterns) replace subhash(*patterns) end end end ruby-tins-0.6.0/lib/tins/xt/symbol_to_proc.rb000066400000000000000000000002001205054622500211770ustar00rootroot00000000000000module Tins unless ::Symbol.method_defined?(:to_proc) # :nocov: class ::Symbol include ToProc end end end ruby-tins-0.6.0/lib/tins/xt/time_dummy.rb000066400000000000000000000001261205054622500203250ustar00rootroot00000000000000require 'tins/time_dummy' module Tins class ::Time include TimeDummy end end ruby-tins-0.6.0/lib/tins/xt/uniq_by.rb000066400000000000000000000002711205054622500176230ustar00rootroot00000000000000require 'tins/uniq_by' module Tins module ::Enumerable include UniqBy end class ::Array include UniqBy def uniq_by!(&b) replace uniq_by(&b) end end end ruby-tins-0.6.0/lib/tins/xt/write.rb000066400000000000000000000002031205054622500173020ustar00rootroot00000000000000require 'tins/write' module Tins #class ::Object # include Tins::Write #end class ::IO extend Tins::Write end end ruby-tins-0.6.0/metadata.yml000066400000000000000000000211771205054622500157650ustar00rootroot00000000000000--- !ruby/object:Gem::Specification name: tins version: !ruby/object:Gem::Version version: 0.6.0 prerelease: platform: ruby authors: - Florian Frank autorequire: bindir: bin cert_chain: [] date: 2012-10-02 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: gem_hadar requirement: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: 0.1.8 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: 0.1.8 - !ruby/object:Gem::Dependency name: test-unit requirement: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '2.5' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '2.5' - !ruby/object:Gem::Dependency name: utils requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' description: All the stuff that isn't good/big enough for a real library. email: flori@ping.de executables: [] extensions: [] extra_rdoc_files: - README.rdoc - lib/spruz.rb - lib/tins/alias.rb - lib/tins/ask_and_send.rb - lib/tins/attempt.rb - lib/tins/bijection.rb - lib/tins/concern.rb - lib/tins/count_by.rb - lib/tins/date_dummy.rb - lib/tins/date_time_dummy.rb - lib/tins/deep_const_get.rb - lib/tins/deep_dup.rb - lib/tins/extract_last_argument_options.rb - lib/tins/file_binary.rb - lib/tins/find.rb - lib/tins/generator.rb - lib/tins/go.rb - lib/tins/hash_symbolize_keys_recursive.rb - lib/tins/hash_union.rb - lib/tins/if_predicate.rb - lib/tins/limited.rb - lib/tins/lines_file.rb - lib/tins/memoize.rb - lib/tins/minimize.rb - lib/tins/module_group.rb - lib/tins/null.rb - lib/tins/once.rb - lib/tins/p.rb - lib/tins/partial_application.rb - lib/tins/proc_compose.rb - lib/tins/range_plus.rb - lib/tins/require_maybe.rb - lib/tins/responding.rb - lib/tins/round.rb - lib/tins/secure_write.rb - lib/tins/shuffle.rb - lib/tins/string_camelize.rb - lib/tins/string_underscore.rb - lib/tins/string_version.rb - lib/tins/subhash.rb - lib/tins/time_dummy.rb - lib/tins/to_proc.rb - lib/tins/uniq_by.rb - lib/tins/version.rb - lib/tins/write.rb - lib/tins/xt/ask_and_send.rb - lib/tins/xt/attempt.rb - lib/tins/xt/blank.rb - lib/tins/xt/count_by.rb - lib/tins/xt/date_dummy.rb - lib/tins/xt/date_time_dummy.rb - lib/tins/xt/deep_const_get.rb - lib/tins/xt/deep_dup.rb - lib/tins/xt/extract_last_argument_options.rb - lib/tins/xt/file_binary.rb - lib/tins/xt/full.rb - lib/tins/xt/hash_symbolize_keys_recursive.rb - lib/tins/xt/hash_union.rb - lib/tins/xt/if_predicate.rb - lib/tins/xt/irb.rb - lib/tins/xt/named.rb - lib/tins/xt/null.rb - lib/tins/xt/p.rb - lib/tins/xt/partial_application.rb - lib/tins/xt/proc_compose.rb - lib/tins/xt/range_plus.rb - lib/tins/xt/require_maybe.rb - lib/tins/xt/responding.rb - lib/tins/xt/round.rb - lib/tins/xt/secure_write.rb - lib/tins/xt/shuffle.rb - lib/tins/xt/string.rb - lib/tins/xt/string_camelize.rb - lib/tins/xt/string_underscore.rb - lib/tins/xt/string_version.rb - lib/tins/xt/subhash.rb - lib/tins/xt/symbol_to_proc.rb - lib/tins/xt/time_dummy.rb - lib/tins/xt/uniq_by.rb - lib/tins/xt/write.rb - lib/tins/xt.rb - lib/tins.rb files: - .gitignore - .travis.yml - Gemfile - LICENSE - README.rdoc - Rakefile - TODO - VERSION - lib/spruz.rb - lib/tins.rb - lib/tins/alias.rb - lib/tins/ask_and_send.rb - lib/tins/attempt.rb - lib/tins/bijection.rb - lib/tins/concern.rb - lib/tins/count_by.rb - lib/tins/date_dummy.rb - lib/tins/date_time_dummy.rb - lib/tins/deep_const_get.rb - lib/tins/deep_dup.rb - lib/tins/extract_last_argument_options.rb - lib/tins/file_binary.rb - lib/tins/find.rb - lib/tins/generator.rb - lib/tins/go.rb - lib/tins/hash_symbolize_keys_recursive.rb - lib/tins/hash_union.rb - lib/tins/if_predicate.rb - lib/tins/limited.rb - lib/tins/lines_file.rb - lib/tins/memoize.rb - lib/tins/minimize.rb - lib/tins/module_group.rb - lib/tins/null.rb - lib/tins/once.rb - lib/tins/p.rb - lib/tins/partial_application.rb - lib/tins/proc_compose.rb - lib/tins/range_plus.rb - lib/tins/require_maybe.rb - lib/tins/responding.rb - lib/tins/round.rb - lib/tins/secure_write.rb - lib/tins/shuffle.rb - lib/tins/string_camelize.rb - lib/tins/string_underscore.rb - lib/tins/string_version.rb - lib/tins/subhash.rb - lib/tins/time_dummy.rb - lib/tins/to_proc.rb - lib/tins/uniq_by.rb - lib/tins/version.rb - lib/tins/write.rb - lib/tins/xt.rb - lib/tins/xt/ask_and_send.rb - lib/tins/xt/attempt.rb - lib/tins/xt/blank.rb - lib/tins/xt/count_by.rb - lib/tins/xt/date_dummy.rb - lib/tins/xt/date_time_dummy.rb - lib/tins/xt/deep_const_get.rb - lib/tins/xt/deep_dup.rb - lib/tins/xt/extract_last_argument_options.rb - lib/tins/xt/file_binary.rb - lib/tins/xt/full.rb - lib/tins/xt/hash_symbolize_keys_recursive.rb - lib/tins/xt/hash_union.rb - lib/tins/xt/if_predicate.rb - lib/tins/xt/irb.rb - lib/tins/xt/named.rb - lib/tins/xt/null.rb - lib/tins/xt/p.rb - lib/tins/xt/partial_application.rb - lib/tins/xt/proc_compose.rb - lib/tins/xt/range_plus.rb - lib/tins/xt/require_maybe.rb - lib/tins/xt/responding.rb - lib/tins/xt/round.rb - lib/tins/xt/secure_write.rb - lib/tins/xt/shuffle.rb - lib/tins/xt/string.rb - lib/tins/xt/string_camelize.rb - lib/tins/xt/string_underscore.rb - lib/tins/xt/string_version.rb - lib/tins/xt/subhash.rb - lib/tins/xt/symbol_to_proc.rb - lib/tins/xt/time_dummy.rb - lib/tins/xt/uniq_by.rb - lib/tins/xt/write.rb - tests/ask_and_send_test.rb - tests/bijection_test.rb - tests/blank_full_test.rb - tests/concern_test.rb - tests/count_by_test.rb - tests/date_dummy_test.rb - tests/date_time_dummy_test.rb - tests/deep_const_get_test.rb - tests/deep_dup_test.rb - tests/extract_last_argument_options_test.rb - tests/file_binary_test.rb - tests/find_test.rb - tests/generator_test.rb - tests/go_test.rb - tests/hash_symbolize_keys_recursive_test.rb - tests/hash_union_test.rb - tests/if_predicate_test.rb - tests/limited_test.rb - tests/lines_file_test.rb - tests/memoize_test.rb - tests/minimize_test.rb - tests/module_group_test.rb - tests/named_test.rb - tests/null_test.rb - tests/p_test.rb - tests/partial_application_test.rb - tests/proc_compose_test.rb - tests/range_plus_test.rb - tests/require_maybe_test.rb - tests/responding_test.rb - tests/round_test.rb - tests/secure_write_test.rb - tests/shuffle_test.rb - tests/string_camelize_test.rb - tests/string_underscore_test.rb - tests/string_version_test.rb - tests/subhash_test.rb - tests/test_helper.rb - tests/time_dummy_test.rb - tests/try_test.rb - tests/uniq_by_test.rb - tins.gemspec homepage: http://flori.github.com/tins licenses: [] post_install_message: rdoc_options: - --title - Tins - Useful stuff. - --main - README.rdoc require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' segments: - 0 hash: 4391703042856250428 required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 1.8.24 signing_key: specification_version: 3 summary: Useful stuff. test_files: - tests/ask_and_send_test.rb - tests/bijection_test.rb - tests/blank_full_test.rb - tests/concern_test.rb - tests/count_by_test.rb - tests/date_dummy_test.rb - tests/date_time_dummy_test.rb - tests/deep_const_get_test.rb - tests/deep_dup_test.rb - tests/extract_last_argument_options_test.rb - tests/file_binary_test.rb - tests/find_test.rb - tests/generator_test.rb - tests/go_test.rb - tests/hash_symbolize_keys_recursive_test.rb - tests/hash_union_test.rb - tests/if_predicate_test.rb - tests/limited_test.rb - tests/lines_file_test.rb - tests/memoize_test.rb - tests/minimize_test.rb - tests/module_group_test.rb - tests/named_test.rb - tests/null_test.rb - tests/p_test.rb - tests/partial_application_test.rb - tests/proc_compose_test.rb - tests/range_plus_test.rb - tests/require_maybe_test.rb - tests/responding_test.rb - tests/round_test.rb - tests/secure_write_test.rb - tests/shuffle_test.rb - tests/string_camelize_test.rb - tests/string_underscore_test.rb - tests/string_version_test.rb - tests/subhash_test.rb - tests/test_helper.rb - tests/time_dummy_test.rb - tests/try_test.rb - tests/uniq_by_test.rb ruby-tins-0.6.0/tests/000077500000000000000000000000001205054622500146145ustar00rootroot00000000000000ruby-tins-0.6.0/tests/ask_and_send_test.rb000066400000000000000000000011141205054622500206060ustar00rootroot00000000000000require 'test_helper' require 'tins/xt' module Tins class AskAndSendTest < Test::Unit::TestCase class A public def foo :foo end private def bar :bar end end def test_asking_publicly assert_equal :foo, A.new.ask_and_send(:foo) assert_nil A.new.ask_and_send(:bar) assert_nil A.new.ask_and_send(:baz) end def test_asking_privately assert_equal :foo, A.new.ask_and_send!(:foo) assert_equal :bar, A.new.ask_and_send!(:bar) assert_nil A.new.ask_and_send(:baz) end end end ruby-tins-0.6.0/tests/bijection_test.rb000066400000000000000000000007111205054622500201450ustar00rootroot00000000000000require 'test_helper' require 'tins' module Tins class BijectionTest < Test::Unit::TestCase def test_bijection assert_equal [ [ 1, 2 ], [ 3, 4 ] ], Tins::Bijection[ 1, 2, 3, 4 ].to_a.sort assert_raise(ArgumentError) do Tins::Bijection[1,2,3] end assert_raise(ArgumentError) do Tins::Bijection[1,2,3,2] end assert_raise(ArgumentError) do Tins::Bijection[1,2,1,3] end end end end ruby-tins-0.6.0/tests/blank_full_test.rb000066400000000000000000000036171205054622500203200ustar00rootroot00000000000000require 'test_helper' require 'tins/xt' require 'set' module Tins class BlankFullTest < Test::Unit::TestCase def test_blank assert !true.blank? assert false.blank? assert nil.blank? assert [].blank? assert ![23].blank? assert Set[].blank? assert !Set[23].blank? assert({}.blank?) assert !{ :foo => 23 }.blank? assert "".blank? assert " ".blank? assert !"foo".blank? end def test_present assert true.present? assert !false.present? assert !nil.present? assert ![].present? assert [23].present? assert !Set[].present? assert Set[23].present? assert !{}.present? assert({ :foo => 23 }.present?) assert !"".present? assert !" ".present? assert "foo".present? end def test_full assert_equal true, true.full? assert_nil false.full? assert_nil nil.full? assert_nil [].full? assert_equal [ 23 ], [ 23 ].full? assert_nil Set[].full? assert_equal Set[23], Set[23].full? assert_nil({}.full?) assert_equal({ :foo => 23 }, { :foo => 23 }.full?) assert_nil "".full? assert_nil " ".full? assert_equal "foo", "foo".full? assert_nil " ".full?(&:size) assert_equal 3, "foo".full?(&:size) assert_nil " ".full?(&:size) assert_equal 3, "foo".full?(&:size) assert_nil " ".full?(:size) assert_equal 3, "foo".full?(:size) assert_nil " ".full?(:size) assert_equal 3, "foo".full?(:size) end def test_all_full assert_equal [1, 2], [1, 2].all_full? assert_nil [nil, 2].all_full? assert_nil [1, ''].all_full? end def test_all_full_with_block [1, 2].all_full? do |x, y| assert_equal 1, x assert_equal 2, y end ['', 2].all_full? do |x, y| assert false end end end end ruby-tins-0.6.0/tests/concern_test.rb000066400000000000000000000011271205054622500176300ustar00rootroot00000000000000require 'test_helper' require 'tins/concern' module Tins class ConcernTest < Test::Unit::TestCase module ConcernTroll extend ::Tins::Concern included do @included = :included end module ClassMethods def class_foo :class_foo end end def foo :foo end end class Troll include ConcernTroll end def test_concern assert_equal :class_foo, Troll.class_foo assert_equal :foo, Troll.new.foo assert_equal :included, Troll.instance_variable_get(:@included) end end end ruby-tins-0.6.0/tests/count_by_test.rb000066400000000000000000000010541205054622500200220ustar00rootroot00000000000000require 'test_helper' require 'tins/xt' module Tins class CountByTest < Test::Unit::TestCase def test_count_by assert_equal 0, [].count_by { |x| x % 2 == 0 } assert_equal 0, [ 1 ].count_by { |x| x % 2 == 0 } assert_equal 1, [ 1 ].count_by { |x| x % 2 == 1 } assert_equal 1, [ 1, 2 ].count_by { |x| x % 2 == 0 } assert_equal 1, [ 1, 2 ].count_by { |x| x % 2 == 1 } assert_equal 2, [ 1, 2, 3, 4, 5 ].count_by { |x| x % 2 == 0 } assert_equal 3, [ 1, 2, 3, 4, 5 ].count_by { |x| x % 2 == 1 } end end end ruby-tins-0.6.0/tests/date_dummy_test.rb000066400000000000000000000013521205054622500203310ustar00rootroot00000000000000require 'test_helper' require 'tins' module Tins class DateDummyTest < Test::Unit::TestCase require 'tins/xt/date_dummy' require 'date' def test_date_dummy date = Date.parse('2009-09-09') assert_not_equal date, Date.today Date.dummy = date assert_equal date, Date.today Date.dummy = nil assert_not_equal date, Date.today end def test_date_dummy_block date = Date.parse('2009-09-09') assert_not_equal date, Date.today Date.dummy date do assert_equal date, Date.today Date.dummy date + 1 do assert_equal date + 1, Date.today end assert_equal date, Date.today end assert_not_equal date, Date.today end end end ruby-tins-0.6.0/tests/date_time_dummy_test.rb000066400000000000000000000015561205054622500213550ustar00rootroot00000000000000require 'test_helper' require 'tins' module Tins class DateTimeDummyTest < Test::Unit::TestCase require 'tins/xt/date_time_dummy' require 'date' def test_time_dummy date_time = DateTime.parse('2009-09-09 21:09:09') assert_not_equal date_time, DateTime.now DateTime.dummy = date_time assert_equal date_time, DateTime.now DateTime.dummy = nil assert_not_equal date_time, DateTime.now end def test_time_dummy_block date_time = DateTime.parse('2009-09-09 21:09:09') assert_not_equal date_time, DateTime.now DateTime.dummy date_time do assert_equal date_time, DateTime.now DateTime.dummy date_time + 1 do assert_equal date_time + 1, DateTime.now end assert_equal date_time, DateTime.now end assert_not_equal date_time, DateTime.now end end end ruby-tins-0.6.0/tests/deep_const_get_test.rb000066400000000000000000000020201205054622500211540ustar00rootroot00000000000000require 'test_helper' require 'tins/xt/deep_const_get' module Tins class DeepConstGetTest < Test::Unit::TestCase module A module B end end module C module NotB end def self.const_missing(c) NotB end end def test_deep_const_get_with_start_module assert_raise(ArgumentError) { deep_const_get '::B', A } assert_equal A::B, deep_const_get('B', A) end def test_deep_const_get_without_start_module assert_equal Tins::DeepConstGetTest::A::B, deep_const_get('::Tins::DeepConstGetTest::A::B') assert_equal Tins::DeepConstGetTest::A::B, deep_const_get('Tins::DeepConstGetTest::A::B') assert_equal Array, deep_const_get('::Array') assert_equal Array, deep_const_get('Array') end def test_deep_const_get_with_const_missing assert_raise(ArgumentError) { deep_const_get '::Tins::DeepConstGetTest::A::D' } assert_equal Tins::DeepConstGetTest::C::NotB, deep_const_get('::Tins::DeepConstGetTest::C::B') end end end ruby-tins-0.6.0/tests/deep_dup_test.rb000066400000000000000000000006101205054622500177620ustar00rootroot00000000000000require 'test_helper' require 'tins/xt' module Tins class DeepDupTest < Test::Unit::TestCase def test_deep_dup a = [1,2,3] assert_equal a, a.deep_dup assert_not_same a, a.deep_dup end def test_deep_dup_proc f = lambda { |x| 2 * x } g = f.deep_dup assert_equal f[3], g[3] assert_equal f, g assert_same f, g end end end ruby-tins-0.6.0/tests/extract_last_argument_options_test.rb000066400000000000000000000016261205054622500243570ustar00rootroot00000000000000require 'test_helper' require 'tins' module Tins class ExtractLastArgumentOptionsTest < Test::Unit::TestCase require 'tins/xt/extract_last_argument_options' def test_empty_argument_array arguments = [] result = arguments.extract_last_argument_options assert_equal [ [], {} ], result assert_not_same arguments, result.first end def test_argument_array_without_options arguments = [ 1, 2, 3 ] result = arguments.extract_last_argument_options assert_equal [ [ 1, 2, 3 ], {} ], result assert_not_same arguments, result.first end def test_argument_array_witt_options arguments = [ 1, 2, 3, { :foo => :bar } ] result = arguments.extract_last_argument_options assert_equal [ [ 1, 2, 3 ], { :foo => :bar } ], result assert_not_same arguments, result.first assert_not_same arguments.last, result.last end end end ruby-tins-0.6.0/tests/file_binary_test.rb000066400000000000000000000035211205054622500204640ustar00rootroot00000000000000require 'test_helper' require 'tempfile' require 'tins/xt' module Tins class TinsFileBinaryTest < Test::Unit::TestCase def test_ascii_buffer_size write_file do |file| file.write "A" * 10 + "\x00" assert_equal true, file.ascii?(:buffer_size => 10) assert_equal true, File.ascii?(file.path, :buffer_size => 10) assert_equal false, file.binary?(:buffer_size => 10) assert_equal false, File.binary?(file.path, :buffer_size => 10) end end def test_binary write_file do |file| file.write "A" * 69 + "\x01" * 31 assert_equal true, file.binary? assert_equal true, File.binary?(file.path) assert_equal false, file.ascii? assert_equal false, File.ascii?(file.path) end end def test_ascii_offset write_file do |file| file.write "\x01" * 31 + "A" * 70 assert_equal false, file.binary?(:offset => 1) assert_equal false, File.binary?(file.path, :offset => 1) assert_equal true, file.ascii?(:offset => 1) assert_equal true, File.ascii?(file.path, :offset => 1) end end def test_binary_zero write_file do |file| file.write "A" * 50 + "\0" + "A" * 49 assert_equal true, file.binary? assert_equal true, File.binary?(file.path) assert_equal false, file.ascii? assert_equal false, File.ascii?(file.path) end end def test_ascii write_file do |file| file.write "A" * 100 assert_equal false, file.binary? assert_equal false, File.binary?(file.path) assert_equal true, file.ascii? assert_equal true, File.ascii?(file.path) end end private def write_file File.open(File.join(Dir.tmpdir, "temp.#$$"), 'wb+') do |file| yield file end end end end ruby-tins-0.6.0/tests/find_test.rb000066400000000000000000000077251205054622500171330ustar00rootroot00000000000000require 'test_helper' require 'tins/find' require 'fileutils' require 'tempfile' module Tins class FindTest < Test::Unit::TestCase include Tins::Find include FileUtils def setup mkdir_p @work_dir = File.join(Dir.tmpdir, "test.#$$") end def teardown rm_rf @work_dir end def test_raising_errors assert_equal [], find(File.join(@work_dir, 'nix'), :raise_errors => false).to_a assert_equal [], find(File.join(@work_dir, 'nix')).to_a assert_raise(Errno::ENOENT) do find(File.join(@work_dir, 'nix'), :raise_errors => true).to_a end end def test_showing_hidden touch file = File.join(@work_dir, '.foo') assert_equal [ @work_dir ], find(@work_dir, :show_hidden => false).to_a assert_equal [ @work_dir, file ], find(@work_dir).to_a assert_equal [ @work_dir, file ], find(@work_dir, :show_hidden => true).to_a end def test_check_directory_without_access # do not run this test on JRuby omit_if(RUBY_PLATFORM =~ /java/, "Can't run the test on JRuby") # do not run this test if we're root, as it will fail. omit_if(Process::UID.eid == 0, "Can't run the test as root") begin mkdir_p directory1 = File.join(@work_dir, 'foo') mkdir_p directory2 = File.join(directory1, 'bar') touch file = File.join(directory2, 'file') chmod 0, directory2 assert_equal [ @work_dir, directory1, directory2 ], find(@work_dir, :raise_errors => false).to_a assert_equal [ @work_dir, directory1, directory2 ], find(@work_dir).to_a assert_raise(Errno::EACCES) do find(@work_dir, :raise_errors => true).to_a end ensure File.exist?(directory2) and chmod 0777, directory2 end end def test_follow_symlinks mkdir_p directory1 = File.join(@work_dir, 'foo1') mkdir_p directory2 = File.join(@work_dir, 'foo2') mkdir_p directory3 = File.join(directory1, 'bar') touch file = File.join(directory3, 'foo') ln_s directory3, link = File.join(directory2, 'baz') assert_equal [ directory2, link ], find(directory2, :follow_symlinks => false).to_a assert_equal [ directory2, link, linked = File.join(link, 'foo') ], find(directory2).to_a assert_equal [ directory2, link, linked ], find(directory2, :follow_symlinks => true).to_a end def test_path_file File.open(File.join(@work_dir, 'foo'), 'w') do |f| f.print "hello" f.fsync assert_equal "hello", find(@work_dir).select { |f| f.stat.file? }.first.file.read end end def test_path_extension finder = Tins::Find::Finder.new f = File.open(path = File.join(@work_dir, 'foo.bar'), 'w') ln_s path, path2 = File.join(@work_dir, 'foo2.bar') path2 = finder.prepare_path path2 path = finder.prepare_path path assert_true path.exist? assert_true path.file? assert_false path.directory? assert_true finder.prepare_path(Dir.pwd).directory? assert_equal Pathname.new(path), path.pathname assert_equal 'bar', path.suffix assert_true path2.lstat.symlink? ensure f and rm_f f.path end def test_suffix finder = Tins::Find::Finder.new(:suffix => 'bar') f = File.open(fpath = File.join(@work_dir, 'foo.bar'), 'w') g = File.open(gpath = File.join(@work_dir, 'foo.baz'), 'w') fpath = finder.prepare_path fpath gpath = finder.prepare_path gpath assert_true finder.visit_path?(fpath) assert_false finder.visit_path?(gpath) finder.suffix = nil assert_true finder.visit_path?(fpath) assert_true finder.visit_path?(gpath) ensure f and rm_f f.path g and rm_f g.path end def test_prune mkdir_p directory1 = File.join(@work_dir, 'foo1') mkdir_p directory2 = File.join(@work_dir, 'foo2') result = [] find(@work_dir) { |f| f =~ /foo2\z/ and prune; result << f } assert_equal [ @work_dir, directory1 ], result end end end ruby-tins-0.6.0/tests/generator_test.rb000066400000000000000000000017561205054622500201770ustar00rootroot00000000000000require 'test_helper' require 'tins' module Tins class GeneratorTest < Test::Unit::TestCase def setup @numeric = [ 1, 2, 3 ] @string = %w[a b c] @chars = 'abc' end def test_generator g = Tins::Generator[@numeric, @string] assert_equal 2, g.size g.add_dimension(@chars, :each_byte) assert_equal 3, g.size assert_equal\ [[1, "a", 97], [1, "a", 98], [1, "a", 99], [1, "b", 97], [1, "b", 98], [1, "b", 99], [1, "c", 97], [1, "c", 98], [1, "c", 99], [2, "a", 97], [2, "a", 98], [2, "a", 99], [2, "b", 97], [2, "b", 98], [2, "b", 99], [2, "c", 97], [2, "c", 98], [2, "c", 99], [3, "a", 97], [3, "a", 98], [3, "a", 99], [3, "b", 97], [3, "b", 98], [3, "b", 99], [3, "c", 97], [3, "c", 98], [3, "c", 99]], g.to_a end end end ruby-tins-0.6.0/tests/go_test.rb000066400000000000000000000024251205054622500166100ustar00rootroot00000000000000require 'test_helper' require 'tins/go' module Tins class GoTest < Test::Unit::TestCase include Tins::GO def test_empty_string r = go '', args = %w[a b c] assert_equal({}, r) assert_equal %w[a b c], args end def test_empty_args r = go 'ab:', args = [] assert_equal({ 'a' => false, 'b' => nil }, r) assert_equal [], args end def test_simple r = go 'ab:', args = %w[-b hello -a -c rest] assert_equal({ 'a' => 1, 'b' => 'hello' }, r) assert_equal %w[-c rest], args end def test_complex r = go 'ab:', args = %w[-a -b hello -a -bworld -c rest] assert_equal({ 'a' => 2, 'b' => 'hello' }, r) assert_equal %w[hello world], r['b'].to_a assert_equal %w[-c rest], args end def test_complex2 r = go 'ab:', args = %w[-b hello -aa -b world -c rest] assert_equal({ 'a' => 2, 'b' => 'hello' }, r) assert_equal %w[hello world], r['b'].to_a assert_equal %w[-c rest], args end def test_complex_frozen args = %w[-b hello -aa -b world -c rest] args = args.map(&:freeze) r = go 'ab:', args assert_equal({ 'a' => 2, 'b' => 'hello' }, r) assert_equal %w[hello world], r['b'].to_a assert_equal %w[-c rest], args end end end ruby-tins-0.6.0/tests/hash_symbolize_keys_recursive_test.rb000066400000000000000000000007741205054622500243520ustar00rootroot00000000000000require 'test_helper' require 'tins' module Tins class HashSymbolizeKeysRecursiveTest < Test::Unit::TestCase require 'tins/xt/hash_symbolize_keys_recursive' def test_symbolize hash = { 'key' => [ { 'key' => { 'key' => true } } ], } hash2 = hash.symbolize_keys_recursive assert hash2[:key][0][:key][:key] hash.symbolize_keys_recursive! assert hash[:key][0][:key][:key] end end end ruby-tins-0.6.0/tests/hash_union_test.rb000066400000000000000000000017351205054622500203410ustar00rootroot00000000000000require 'test_helper' require 'tins/xt' module Tins class HashUnionTest < Test::Unit::TestCase class HashLike1 def to_hash { 'foo' => true } end end class HashLike2 def to_h { 'foo' => true } end end def test_union defaults = { 'foo' => true, 'bar' => false, 'quux' => nil } hash = { 'foo' => false } assert_equal [ ['bar', false], ['foo', false], ['quux', nil] ], (hash | defaults).sort hash |= defaults assert_equal [ ['bar', false], ['foo', false], ['quux', nil] ], hash.sort hash = { 'foo' => false } hash |= { 'quux' => true, 'baz' => 23, } | defaults assert_equal [ ['bar', false], [ 'baz', 23 ], ['foo', false], ['quux', true] ], hash.sort end def test_hash_conversion assert_equal({ 'foo' => true }, { } | HashLike1.new) assert_equal({ 'foo' => true }, { } | HashLike2.new) end end end ruby-tins-0.6.0/tests/if_predicate_test.rb000066400000000000000000000003471205054622500206220ustar00rootroot00000000000000require 'test_helper' require 'tins/xt' module Tins class IfPredicateTest def test_if_predicate assert_equal :foo, true.if? && :foo assert_nil false.if? && :foo assert_nil nil.if? && :foo end end end ruby-tins-0.6.0/tests/limited_test.rb000066400000000000000000000007151205054622500176320ustar00rootroot00000000000000require 'test_helper' require 'tins' module Tins class LimitedTest < Test::Unit::TestCase class ::Array include Tins::Shuffle end def test_limited count = {} limited = Tins::Limited.new(5) 5.times do limited.execute do count[Thread.current] = true sleep end end until count.size >= 5 sleep 0.1 end assert_equal 5, count.keys.uniq.size end end end ruby-tins-0.6.0/tests/lines_file_test.rb000066400000000000000000000051331205054622500203130ustar00rootroot00000000000000require 'test_helper' require 'tempfile' require 'tins/lines_file' module Tins class TinsLinesFileTest < Test::Unit::TestCase FILE = <= '1.9' def foo(x, y, &block) block.call x * y end def test_more_complex Object.named(:foo_with_block, :foo) do |z| z ** 2 end assert_equal foo(2, 3) { |z| z ** 2 }, foo_with_block(2, 3) Object.named(:foo_23, :foo, 2, 3) assert_equal foo(2, 3) { |z| z ** 2 }, foo_23 { |z| z ** 2 } Object.named(:foo_2, :foo, 2) assert_equal foo(2, 3) { |z| z ** 2 }, foo_2(3) { |z| z ** 2 } end end end end ruby-tins-0.6.0/tests/null_test.rb000066400000000000000000000010431205054622500171500ustar00rootroot00000000000000require 'test_helper' require 'tins' module Tins class NullTest < Test::Unit::TestCase require 'tins/xt/null' def test_null assert_equal NULL, NULL.foo assert_equal NULL, NULL.foo.bar assert_equal 'NULL', NULL.inspect assert_equal '', NULL.to_s assert_equal 0, NULL.to_i assert_equal 0.0, NULL.to_f assert_equal [], NULL.to_a assert_equal 1, Null(1) assert_equal NULL, Null(nil) assert_equal NULL, NULL::NULL assert NULL.nil? assert NULL.blank? end end end ruby-tins-0.6.0/tests/p_test.rb000066400000000000000000000003751205054622500164440ustar00rootroot00000000000000require 'test_helper' require 'tins/xt/p' module Tins class PTest < Test::Unit::TestCase def test_p_bang assert_raise(RuntimeError) { p! "foo" } end def test_pp_bang assert_raise(RuntimeError) { pp! "foo" } end end end ruby-tins-0.6.0/tests/partial_application_test.rb000066400000000000000000000013141205054622500222160ustar00rootroot00000000000000require 'test_helper' require 'tins/xt' module Tins class PartialApplicationTest < Test::Unit::TestCase def mul(x, y) x * y end define_method(:dup) { |y| method(:mul).partial(2)[y] } define_method(:trip) { |y| method(:mul).partial(3)[y] } def test_proc mul = lambda { |x, y| x * y } klon = mul.partial dup = mul.partial(2) trip = mul.partial(3) assert_equal [ 6, 9, 12 ], [ dup[3], trip[3], mul[4, 3] ] assert_equal [ 6, 9, 12 ], [ dup[3], trip[3], klon[4, 3] ] assert_raises(ArgumentError) do mul.partial(1, 2, 3) end end def test_method assert_equal [ 6, 9, 12 ], [ dup(3), trip(3), mul(4, 3) ] end end end ruby-tins-0.6.0/tests/proc_compose_test.rb000066400000000000000000000011501205054622500206650ustar00rootroot00000000000000require 'test_helper' require 'tins/xt' module Tins class ProcComposeTest < Test::Unit::TestCase def test_proc_compose_simple f = lambda { |x| 2 * x } g = lambda { |x| x + 1 } assert_equal 6, (f * g).call(2) end def test_proc_compose_more_complex f = lambda { |x, y| 2 * x + y * 3 } g = lambda { |x| x + 1 } if RUBY_VERSION >= "1.9" assert_raise(ArgumentError) { (f * g).call(2, 3) } else assert_raise(TypeError) { (f * g).call(2, 3) } end d = lambda { |x| [ x, x ] } assert_equal 15, (f * d * g).call(2) end end end ruby-tins-0.6.0/tests/range_plus_test.rb000066400000000000000000000005011205054622500203330ustar00rootroot00000000000000require 'test_helper' require 'tins/xt' module Tins class RangePlustTest < Test::Unit::TestCase def test_range_plus assert_equal [], (0...0) + (0...0) assert_equal [ 0 ], (0..0) + (0...0) assert_equal [ 0, 0 ], (0..0) + (0..0) assert_equal((1..5).to_a, (1...3) + (3..5)) end end end ruby-tins-0.6.0/tests/require_maybe_test.rb000066400000000000000000000010541205054622500210310ustar00rootroot00000000000000require 'test_helper' require 'tins' module Tins require 'tins/xt/require_maybe' class RequireMaybeTest < Test::Unit::TestCase def test_require_maybe_failed executed = false require_maybe 'nix' do executed = true end assert executed, 'require did not fail' end def test_require_maybe_succeeded not_executed = true result = require_maybe 'tins' do not_executed = false end assert [ false, true ].include?(result) assert not_executed, 'require failed' end end end ruby-tins-0.6.0/tests/responding_test.rb000066400000000000000000000011631205054622500203510ustar00rootroot00000000000000require 'test_helper' require 'tins/xt' module Tins class RespondingTest < Test::Unit::TestCase class A def foo() end def bar() end end def test_responding assert_equal true, responding?(:foo) === A.new assert_equal false, responding?(:jflafjdklfjaslkdfj) === A.new assert_equal false, responding?(:jflafjdklfjaslkdfj, :foo) === A.new assert_equal true, responding?(:foo, :bar) === A.new end def test_responding_to_s assert_equal 'Responding to foo', responding?(:foo).to_s assert_equal 'Responding to foo', responding?(:foo).inspect end end end ruby-tins-0.6.0/tests/round_test.rb000066400000000000000000000016741205054622500173370ustar00rootroot00000000000000require 'test_helper' require 'tins/xt' module Tins class RoundTest < Test::Unit::TestCase def test_standard assert_equal(1, 1.round) assert_equal(-1, -1.round) assert_equal(2, 1.5.round) assert_kind_of Integer, 1.5.round assert_equal(-1, -1.4.round) assert_equal(-2, -1.5.round) end def test_inclusion assert_equal(10, 12.round(-1)) assert_kind_of Integer, 12.round(-1) assert_equal(-10, -12.round(-1)) assert_raises(ArgumentError) { 12.round(-2) } assert_raises(ArgumentError) { -12.round(-2) } assert_in_delta(1.6, 1.55.round(1), 1E-1) assert_kind_of Float, 1.55.round(1) assert_equal(2, 1.55.round(0)) assert_in_delta(-1.5, -1.45.round(1), 1E-1) assert_equal(-1, -1.45.round(0)) assert_in_delta(-1.6, -1.55.round(1), 1E-1) assert_equal(-2, -1.55.round(0)) assert_in_delta(-1.55, -1.55.round(999), 1E-2) end end end ruby-tins-0.6.0/tests/secure_write_test.rb000066400000000000000000000021311205054622500206750ustar00rootroot00000000000000require 'test_helper' require 'tempfile' require 'tins' module Tins class TinsSecureWriteTest < Test::Unit::TestCase module A extend SecureWrite end def test_secure_write assert_equal 4, A.secure_write(fn = File.join(Dir.tmpdir, "A_file.#$$"), 'test') assert_equal 4, A.secure_write(fn = File.join(Dir.tmpdir, "A_file.#$$")) { |f| f.write('test') } assert_equal 'test', File.read(fn) assert_raise(ArgumentError) { A.secure_write } end module B extend Write end module C def self.write(*args) args end extend Write end class ::IO extend Write end def test_write assert_equal 4, B.write(fn = File.join(Dir.tmpdir, "B_file.#$$"), 'test') assert_equal 4, B.write(fn = File.join(Dir.tmpdir, "B_file.#$$")) { |f| f.write('test') } assert_equal 4, IO.write(fn = File.join(Dir.tmpdir, "IO_file.#$$"), 'test') assert_equal 'test', File.read(fn) result = C.write(fn = File.join(Dir.tmpdir, "C_file.#$$"), 'test') assert_equal [ fn, 'test' ], result end end end ruby-tins-0.6.0/tests/shuffle_test.rb000066400000000000000000000012201205054622500176270ustar00rootroot00000000000000require 'test_helper' require 'tins/xt' module Tins if Tins::Shuffle === Array class ShuffleTest < Test::Unit::TestCase def setup @a = [ 1, 2, 3 ] srand 666 end def test_shuffle assert_equal(a = [2, 3, 1], a = @a.shuffle) assert_not_same @a, a assert_equal(b = [3, 1, 2], b = @a.shuffle) assert_not_same a, b assert_not_same @a, b end def test_shuffle_bang assert_equal([2, 3, 1], a = @a.shuffle!) assert_same @a, a assert_equal([1, 2, 3], b = @a.shuffle!) assert_same a, b assert_same @a, b end end end end ruby-tins-0.6.0/tests/string_camelize_test.rb000066400000000000000000000014271205054622500213630ustar00rootroot00000000000000require 'test_helper' require 'tins/xt' module Tins class StringCamelizeTest < Test::Unit::TestCase def test_camelize assert_equal 'FooBar', 'foo_bar'.camelize assert_equal 'FooBar', 'foo_bar'.camelize(:upper) assert_equal 'FooBar', 'foo_bar'.camelize(true) assert_equal 'fooBar', 'foo_bar'.camelize(:lower) assert_equal 'fooBar', 'foo_bar'.camelize(false) assert_equal 'FooBar', 'foo_bar'.camelcase assert_equal 'Foo::Bar', 'foo/bar'.camelize assert_equal 'Foo::Bar', 'foo/bar'.camelize(:upper) assert_equal 'Foo::Bar', 'foo/bar'.camelize(true) assert_equal 'foo::Bar', 'foo/bar'.camelize(:lower) assert_equal 'foo::Bar', 'foo/bar'.camelize(false) assert_equal 'Foo::Bar', 'foo/bar'.camelcase end end end ruby-tins-0.6.0/tests/string_underscore_test.rb000066400000000000000000000003711205054622500217400ustar00rootroot00000000000000require 'test_helper' require 'tins/xt' module Tins class StringUnderscoreTest < Test::Unit::TestCase def test_underscore assert_equal 'foo_bar', 'FooBar'.underscore assert_equal 'foo/bar', 'Foo::Bar'.underscore end end end ruby-tins-0.6.0/tests/string_version_test.rb000066400000000000000000000015461205054622500212610ustar00rootroot00000000000000require 'test_helper' require 'tins' module Tins class StringVersionTest < Test::Unit::TestCase def test_comparison assert_operator '1.2'.version, :<, '1.3'.version assert_operator '1.3'.version, :>, '1.2'.version assert_operator '1.2'.version, :<=, '1.2'.version assert_operator '1.2'.version, :>=, '1.2'.version assert_operator '1.2'.version, :==, '1.2'.version end def test_change s = '1.2' s.version.revision = 1 assert_equal '1.2.0.1', s s.version.revision += 1 assert_equal '1.2.0.2', s s.version.succ! assert_equal '1.2.0.3', s s.version.pred! assert_equal '1.2.0.2', s assert_raise(ArgumentError) { s.version.build -= 1 } s.version.major = 2 assert_equal '2.2.0.2', s s.version.minor = 1 assert_equal '2.1.0.2', s end end end ruby-tins-0.6.0/tests/subhash_test.rb000066400000000000000000000015721205054622500176420ustar00rootroot00000000000000require 'test_helper' require 'tins' module Tins class SubhashTest < Test::Unit::TestCase require 'tins/xt/subhash' def test_subhash h = { 'foo1' => 1, 'foo2' => 2, 'bar666' => 666 } assert_equal [ [ 'bar666', 666 ] ], h.subhash(/\Abar/).to_a assert h.subhash(/\Abaz/).empty? assert_equal [ [ 'foo1', 1 ], [ 'foo2', 2 ] ], h.subhash(/\Afoo\d/).sort assert_equal [ [ 'foo2', 2 ] ], h.subhash('foo2').to_a end def test_subhash_bang h = { 'foo1' => 1, 'foo2' => 2, 'bar666' => 666 } h.subhash!('foo2') assert_equal [ [ 'foo2', 2 ] ], h.to_a end def test_subhash_with_block h = { 'foo1' => 1, 'foo2' => 2, 'bar666' => 666 } assert h.subhash(/\Abaz/) { :foo }.empty? assert_equal [ [ 'foo1', 1 ], [ 'foo2', 2 ] ], h.subhash(/\Afoo(\d)/) { |_,_,m| Integer(m[1]) }.to_a.sort end end end ruby-tins-0.6.0/tests/test_helper.rb000066400000000000000000000003021205054622500174520ustar00rootroot00000000000000if ENV['START_SIMPLECOV'].to_i == 1 require 'simplecov' SimpleCov.start do add_filter "#{File.basename(File.dirname(__FILE__))}/" end end gem 'test-unit', '~> 2.5' require 'test/unit' ruby-tins-0.6.0/tests/time_dummy_test.rb000066400000000000000000000013541205054622500203540ustar00rootroot00000000000000require 'test_helper' require 'tins' module Tins class TimeDummyTest < Test::Unit::TestCase require 'tins/xt/time_dummy' require 'time' def test_time_dummy time = Time.parse('2009-09-09 21:09:09') assert_not_equal time, Time.now Time.dummy = time assert_equal time, Time.now Time.dummy = nil assert_not_equal time, Time.now end def test_time_dummy_block time = Time.parse('2009-09-09 21:09:09') assert_not_equal time, Time.now Time.dummy time do assert_equal time, Time.now Time.dummy time + 1 do assert_equal time + 1, Time.now end assert_equal time, Time.now end assert_not_equal time, Time.now end end end ruby-tins-0.6.0/tests/try_test.rb000066400000000000000000000033371205054622500170240ustar00rootroot00000000000000require 'test_helper' require 'tins/xt' module Tins class TryTest < Test::Unit::TestCase def test_attempt_block_condition assert attempt(:attempts => 1, :exception_class => nil) { |c| c == 1 } assert attempt(:attempts => 3, :exception_class => nil) { |c| c == 1 } assert_equal false, attempt(:attempts => 3, :exception_class => nil) { |c| c == 4 } assert_nil attempt(:attempts => 0, :exception_class => nil) { |c| c == 4 } assert_raise(Exception) { attempt(:attempts => 3, :exception_class => nil) { raise Exception } } end class MyError < StandardError; end class MyException < Exception; end def test_attempt_default_exception assert attempt(1) { |c| c != 1 and raise MyError } assert attempt(3) { |c| c != 1 and raise MyError } assert_equal false, attempt(3) { |c| c != 4 and raise MyError } assert_nil attempt(0) { |c| c != 4 and raise MyError } assert_raise(Exception) { attempt(3) { raise Exception } } end def test_attempt_exception assert attempt(:attempts => 1, :exception_class => MyException) { |c| c != 1 and raise MyException } assert attempt(:attempts => 3, :exception_class => MyException) { |c| c != 1 and raise MyException } assert_nil attempt(:attempts => 0, :exception_class => MyException) { |c| c != 4 and raise MyException } assert_raise(Exception) { attempt(:attempts => 3, :exception_class => MyException) { raise Exception } } end def test_reraise_exception tries = 0 assert_raise(MyException) do attempt(:attempts => 3, :exception_class => MyException, :reraise => true) do |c| tries = c; raise MyException end end assert_equal 3, tries end end end ruby-tins-0.6.0/tests/uniq_by_test.rb000066400000000000000000000014271205054622500176520ustar00rootroot00000000000000require 'test_helper' require 'tins/xt' module Tins class UniqByTest < Test::Unit::TestCase unless defined?(Point) class Point < Struct.new :x, :y end end def test_uniq_by assert_equal [ 1, 2, 3 ], [ 1, 2, 2, 3 ].uniq_by.sort a = [ 1, 2, 2, 3 ]; a.uniq_by! assert_equal [ 1, 2, 3 ], a.sort p1 = Point.new 1, 2 p2 = Point.new 2, 2 p3 = Point.new 2, 2 p4 = Point.new 3, 3 a = [ p1, p2, p3, p4 ] a_uniq = a.uniq_by { |p| p.y } assert_equal 2, a_uniq.size assert a_uniq.include?(p4) assert [ p1, p2, p3 ].any? { |p| a_uniq.include? p } a.uniq_by! { |p| p.y } assert_equal 2, a.size assert a.include?(p4) assert [ p1, p2, p3 ].any? { |p| a.include? p } end end end ruby-tins-0.6.0/tins.gemspec000066400000000000000000000221141205054622500157740ustar00rootroot00000000000000# -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = "tins" s.version = "0.6.0" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Florian Frank"] s.date = "2012-10-02" s.description = "All the stuff that isn't good/big enough for a real library." s.email = "flori@ping.de" s.extra_rdoc_files = ["README.rdoc", "lib/spruz.rb", "lib/tins/alias.rb", "lib/tins/ask_and_send.rb", "lib/tins/attempt.rb", "lib/tins/bijection.rb", "lib/tins/concern.rb", "lib/tins/count_by.rb", "lib/tins/date_dummy.rb", "lib/tins/date_time_dummy.rb", "lib/tins/deep_const_get.rb", "lib/tins/deep_dup.rb", "lib/tins/extract_last_argument_options.rb", "lib/tins/file_binary.rb", "lib/tins/find.rb", "lib/tins/generator.rb", "lib/tins/go.rb", "lib/tins/hash_symbolize_keys_recursive.rb", "lib/tins/hash_union.rb", "lib/tins/if_predicate.rb", "lib/tins/limited.rb", "lib/tins/lines_file.rb", "lib/tins/memoize.rb", "lib/tins/minimize.rb", "lib/tins/module_group.rb", "lib/tins/null.rb", "lib/tins/once.rb", "lib/tins/p.rb", "lib/tins/partial_application.rb", "lib/tins/proc_compose.rb", "lib/tins/range_plus.rb", "lib/tins/require_maybe.rb", "lib/tins/responding.rb", "lib/tins/round.rb", "lib/tins/secure_write.rb", "lib/tins/shuffle.rb", "lib/tins/string_camelize.rb", "lib/tins/string_underscore.rb", "lib/tins/string_version.rb", "lib/tins/subhash.rb", "lib/tins/time_dummy.rb", "lib/tins/to_proc.rb", "lib/tins/uniq_by.rb", "lib/tins/version.rb", "lib/tins/write.rb", "lib/tins/xt/ask_and_send.rb", "lib/tins/xt/attempt.rb", "lib/tins/xt/blank.rb", "lib/tins/xt/count_by.rb", "lib/tins/xt/date_dummy.rb", "lib/tins/xt/date_time_dummy.rb", "lib/tins/xt/deep_const_get.rb", "lib/tins/xt/deep_dup.rb", "lib/tins/xt/extract_last_argument_options.rb", "lib/tins/xt/file_binary.rb", "lib/tins/xt/full.rb", "lib/tins/xt/hash_symbolize_keys_recursive.rb", "lib/tins/xt/hash_union.rb", "lib/tins/xt/if_predicate.rb", "lib/tins/xt/irb.rb", "lib/tins/xt/named.rb", "lib/tins/xt/null.rb", "lib/tins/xt/p.rb", "lib/tins/xt/partial_application.rb", "lib/tins/xt/proc_compose.rb", "lib/tins/xt/range_plus.rb", "lib/tins/xt/require_maybe.rb", "lib/tins/xt/responding.rb", "lib/tins/xt/round.rb", "lib/tins/xt/secure_write.rb", "lib/tins/xt/shuffle.rb", "lib/tins/xt/string.rb", "lib/tins/xt/string_camelize.rb", "lib/tins/xt/string_underscore.rb", "lib/tins/xt/string_version.rb", "lib/tins/xt/subhash.rb", "lib/tins/xt/symbol_to_proc.rb", "lib/tins/xt/time_dummy.rb", "lib/tins/xt/uniq_by.rb", "lib/tins/xt/write.rb", "lib/tins/xt.rb", "lib/tins.rb"] s.files = [".gitignore", ".travis.yml", "Gemfile", "LICENSE", "README.rdoc", "Rakefile", "TODO", "VERSION", "lib/spruz", "lib/spruz.rb", "lib/tins.rb", "lib/tins/alias.rb", "lib/tins/ask_and_send.rb", "lib/tins/attempt.rb", "lib/tins/bijection.rb", "lib/tins/concern.rb", "lib/tins/count_by.rb", "lib/tins/date_dummy.rb", "lib/tins/date_time_dummy.rb", "lib/tins/deep_const_get.rb", "lib/tins/deep_dup.rb", "lib/tins/extract_last_argument_options.rb", "lib/tins/file_binary.rb", "lib/tins/find.rb", "lib/tins/generator.rb", "lib/tins/go.rb", "lib/tins/hash_symbolize_keys_recursive.rb", "lib/tins/hash_union.rb", "lib/tins/if_predicate.rb", "lib/tins/limited.rb", "lib/tins/lines_file.rb", "lib/tins/memoize.rb", "lib/tins/minimize.rb", "lib/tins/module_group.rb", "lib/tins/null.rb", "lib/tins/once.rb", "lib/tins/p.rb", "lib/tins/partial_application.rb", "lib/tins/proc_compose.rb", "lib/tins/range_plus.rb", "lib/tins/require_maybe.rb", "lib/tins/responding.rb", "lib/tins/round.rb", "lib/tins/secure_write.rb", "lib/tins/shuffle.rb", "lib/tins/string_camelize.rb", "lib/tins/string_underscore.rb", "lib/tins/string_version.rb", "lib/tins/subhash.rb", "lib/tins/time_dummy.rb", "lib/tins/to_proc.rb", "lib/tins/uniq_by.rb", "lib/tins/version.rb", "lib/tins/write.rb", "lib/tins/xt.rb", "lib/tins/xt/ask_and_send.rb", "lib/tins/xt/attempt.rb", "lib/tins/xt/blank.rb", "lib/tins/xt/count_by.rb", "lib/tins/xt/date_dummy.rb", "lib/tins/xt/date_time_dummy.rb", "lib/tins/xt/deep_const_get.rb", "lib/tins/xt/deep_dup.rb", "lib/tins/xt/extract_last_argument_options.rb", "lib/tins/xt/file_binary.rb", "lib/tins/xt/full.rb", "lib/tins/xt/hash_symbolize_keys_recursive.rb", "lib/tins/xt/hash_union.rb", "lib/tins/xt/if_predicate.rb", "lib/tins/xt/irb.rb", "lib/tins/xt/named.rb", "lib/tins/xt/null.rb", "lib/tins/xt/p.rb", "lib/tins/xt/partial_application.rb", "lib/tins/xt/proc_compose.rb", "lib/tins/xt/range_plus.rb", "lib/tins/xt/require_maybe.rb", "lib/tins/xt/responding.rb", "lib/tins/xt/round.rb", "lib/tins/xt/secure_write.rb", "lib/tins/xt/shuffle.rb", "lib/tins/xt/string.rb", "lib/tins/xt/string_camelize.rb", "lib/tins/xt/string_underscore.rb", "lib/tins/xt/string_version.rb", "lib/tins/xt/subhash.rb", "lib/tins/xt/symbol_to_proc.rb", "lib/tins/xt/time_dummy.rb", "lib/tins/xt/uniq_by.rb", "lib/tins/xt/write.rb", "tests/ask_and_send_test.rb", "tests/bijection_test.rb", "tests/blank_full_test.rb", "tests/concern_test.rb", "tests/count_by_test.rb", "tests/date_dummy_test.rb", "tests/date_time_dummy_test.rb", "tests/deep_const_get_test.rb", "tests/deep_dup_test.rb", "tests/extract_last_argument_options_test.rb", "tests/file_binary_test.rb", "tests/find_test.rb", "tests/generator_test.rb", "tests/go_test.rb", "tests/hash_symbolize_keys_recursive_test.rb", "tests/hash_union_test.rb", "tests/if_predicate_test.rb", "tests/limited_test.rb", "tests/lines_file_test.rb", "tests/memoize_test.rb", "tests/minimize_test.rb", "tests/module_group_test.rb", "tests/named_test.rb", "tests/null_test.rb", "tests/p_test.rb", "tests/partial_application_test.rb", "tests/proc_compose_test.rb", "tests/range_plus_test.rb", "tests/require_maybe_test.rb", "tests/responding_test.rb", "tests/round_test.rb", "tests/secure_write_test.rb", "tests/shuffle_test.rb", "tests/string_camelize_test.rb", "tests/string_underscore_test.rb", "tests/string_version_test.rb", "tests/subhash_test.rb", "tests/test_helper.rb", "tests/time_dummy_test.rb", "tests/try_test.rb", "tests/uniq_by_test.rb", "tins.gemspec"] s.homepage = "http://flori.github.com/tins" s.rdoc_options = ["--title", "Tins - Useful stuff.", "--main", "README.rdoc"] s.require_paths = ["lib"] s.rubygems_version = "1.8.24" s.summary = "Useful stuff." s.test_files = ["tests/ask_and_send_test.rb", "tests/bijection_test.rb", "tests/blank_full_test.rb", "tests/concern_test.rb", "tests/count_by_test.rb", "tests/date_dummy_test.rb", "tests/date_time_dummy_test.rb", "tests/deep_const_get_test.rb", "tests/deep_dup_test.rb", "tests/extract_last_argument_options_test.rb", "tests/file_binary_test.rb", "tests/find_test.rb", "tests/generator_test.rb", "tests/go_test.rb", "tests/hash_symbolize_keys_recursive_test.rb", "tests/hash_union_test.rb", "tests/if_predicate_test.rb", "tests/limited_test.rb", "tests/lines_file_test.rb", "tests/memoize_test.rb", "tests/minimize_test.rb", "tests/module_group_test.rb", "tests/named_test.rb", "tests/null_test.rb", "tests/p_test.rb", "tests/partial_application_test.rb", "tests/proc_compose_test.rb", "tests/range_plus_test.rb", "tests/require_maybe_test.rb", "tests/responding_test.rb", "tests/round_test.rb", "tests/secure_write_test.rb", "tests/shuffle_test.rb", "tests/string_camelize_test.rb", "tests/string_underscore_test.rb", "tests/string_version_test.rb", "tests/subhash_test.rb", "tests/test_helper.rb", "tests/time_dummy_test.rb", "tests/try_test.rb", "tests/uniq_by_test.rb", "tests/ask_and_send_test.rb", "tests/bijection_test.rb", "tests/blank_full_test.rb", "tests/concern_test.rb", "tests/count_by_test.rb", "tests/date_dummy_test.rb", "tests/date_time_dummy_test.rb", "tests/deep_const_get_test.rb", "tests/deep_dup_test.rb", "tests/extract_last_argument_options_test.rb", "tests/file_binary_test.rb", "tests/find_test.rb", "tests/generator_test.rb", "tests/go_test.rb", "tests/hash_symbolize_keys_recursive_test.rb", "tests/hash_union_test.rb", "tests/if_predicate_test.rb", "tests/limited_test.rb", "tests/lines_file_test.rb", "tests/memoize_test.rb", "tests/minimize_test.rb", "tests/module_group_test.rb", "tests/named_test.rb", "tests/null_test.rb", "tests/p_test.rb", "tests/partial_application_test.rb", "tests/proc_compose_test.rb", "tests/range_plus_test.rb", "tests/require_maybe_test.rb", "tests/responding_test.rb", "tests/round_test.rb", "tests/secure_write_test.rb", "tests/shuffle_test.rb", "tests/string_camelize_test.rb", "tests/string_underscore_test.rb", "tests/string_version_test.rb", "tests/subhash_test.rb", "tests/time_dummy_test.rb", "tests/try_test.rb", "tests/uniq_by_test.rb"] if s.respond_to? :specification_version then s.specification_version = 3 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_development_dependency(%q, ["~> 0.1.8"]) s.add_development_dependency(%q, ["~> 2.5"]) s.add_development_dependency(%q, [">= 0"]) else s.add_dependency(%q, ["~> 0.1.8"]) s.add_dependency(%q, ["~> 2.5"]) s.add_dependency(%q, [">= 0"]) end else s.add_dependency(%q, ["~> 0.1.8"]) s.add_dependency(%q, ["~> 2.5"]) s.add_dependency(%q, [">= 0"]) end end