pax_global_header00006660000000000000000000000064123162425520014514gustar00rootroot0000000000000052 comment=3b09e352a9ce12d3630b08d762cf026f325fd0e3 ruby-naught-1.0.0/000077500000000000000000000000001231624255200137575ustar00rootroot00000000000000ruby-naught-1.0.0/.gitignore000066400000000000000000000003171231624255200157500ustar00rootroot00000000000000*.gem *.rbc .bundle .config .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp /naught.org /naught.html /bin /TAGS /gems.tags /tags ruby-naught-1.0.0/.rspec000066400000000000000000000000271231624255200150730ustar00rootroot00000000000000--color --order random ruby-naught-1.0.0/.rubocop.yml000066400000000000000000000023701231624255200162330ustar00rootroot00000000000000AllCops: Includes: - 'Gemfile' - 'Rakefile' - 'naught.gemspec' # Avoid long parameter lists ParameterLists: Max: 4 CountKeywordArgs: true ClassLength: Max: 144 # TODO: Lower to 100 MethodLength: CountComments: false Max: 21 # TODO: Lower to 15 # Avoid more than `Max` levels of nesting. BlockNesting: Max: 2 # Align with the style guide. CollectionMethods: PreferredMethods: map: 'collect' reduce: 'inject' find: 'detect' find_all: 'select' # Limit line length LineLength: Enabled: false # Disable documentation checking until a class needs to be documented once Documentation: Enabled: false # Enforce Ruby 1.8-compatible hash syntax HashSyntax: EnforcedStyle: hash_rockets # No spaces inside hash literals SpaceInsideHashLiteralBraces: EnforcedStyle: no_space # Allow dots at the end of lines DotPosition: Enabled: false # Don't require magic comment at the top of every file Encoding: Enabled: false EmptyLinesAroundAccessModifier: Enabled: true # Align ends correctly EndAlignment: AlignWith: variable # Indentation of when/else CaseIndentation: IndentWhenRelativeTo: end IndentOneStep: false Lambda: Enabled: false MethodName: Enabled: false ClassVars: Enabled: false ruby-naught-1.0.0/.travis.yml000066400000000000000000000004631231624255200160730ustar00rootroot00000000000000before_install: - gem update --system 2.1.11 - gem --version bundler_args: --without development language: ruby rvm: - 1.8.7 - 1.9.2 - 1.9.3 - 2.0.0 - 2.1.0 - jruby - jruby-head - rbx - ruby-head matrix: allow_failures: - rvm: jruby-head - rvm: ruby-head fast_finish: true ruby-naught-1.0.0/Changelog.md000066400000000000000000000007101231624255200161660ustar00rootroot00000000000000## 1.0.0 - [Replace `::BasicObject` with `Naught::BasicObject`](https://github.com/avdi/naught/commit/8defad0bf9eb65e33054bf0a6e9c625c87c3e6df) - [Delegate explicit conversions to nil instead of defining them explicitly](https://github.com/avdi/naught/commit/85c195de80ed56993b88f47e09112c903a92a167) - Add support for (and run tests on) Ruby 1.8, 1.9, 2.0, 2.1, JRuby, and Rubinius ## 0.0.3 Features: - New "pebble" mode (Guilherme Carvalho) ruby-naught-1.0.0/Gemfile000066400000000000000000000012361231624255200152540ustar00rootroot00000000000000source 'https://rubygems.org' # Specify your gem's dependencies in naught.gemspec gemspec gem 'rake' group :development do platforms :ruby_19, :ruby_20, :ruby_21 do gem 'guard' gem 'guard-bundler' gem 'guard-rspec' end gem 'pry' gem 'pry-rescue' end group :test do gem 'coveralls', :require => false gem 'json', :platforms => [:jruby, :rbx, :ruby_18, :ruby_19] gem 'libnotify' gem 'mime-types', '~> 1.25', :platforms => [:jruby, :ruby_18] gem 'rspec', '>= 2.14' gem 'rubocop', '>= 0.16', :platforms => [:ruby_19, :ruby_20, :ruby_21] end platforms :rbx do gem 'racc' gem 'rubinius-coverage', '~> 2.0' gem 'rubysl', '~> 2.0' end ruby-naught-1.0.0/Guardfile000066400000000000000000000006251231624255200156070ustar00rootroot00000000000000guard 'bundler' do watch('Gemfile') watch(/^.+\.gemspec/) end guard :rspec, cli: '-fs --color --order rand' do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } watch('spec/spec_helper.rb') { "spec" } end guard 'ctags-bundler', emacs: true, src_path: ["lib", "spec/support"] do watch(/^(lib|spec\/support)\/.*\.rb$/) watch('Gemfile.lock') end ruby-naught-1.0.0/LICENSE.txt000066400000000000000000000020531231624255200156020ustar00rootroot00000000000000Copyright (c) 2013 Avdi Grimm MIT License 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 AUTHORS OR COPYRIGHT HOLDERS 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-naught-1.0.0/README.markdown000066400000000000000000000251261231624255200164660ustar00rootroot00000000000000[![Build Status](https://travis-ci.org/avdi/naught.png?branch=master)](https://travis-ci.org/avdi/naught) [![Code Climate](https://codeclimate.com/github/avdi/naught.png)](https://codeclimate.com/github/avdi/naught) [![Coverage Status](https://coveralls.io/repos/avdi/naught/badge.png?branch=master)](https://coveralls.io/r/avdi/naught?branch=master) [![Gem Version](https://badge.fury.io/rb/naught.png)](http://badge.fury.io/rb/naught) A quick intro to Naught ------------------------- #### What's all this now then? Naught is a toolkit for building [Null Objects](http://en.wikipedia.org/wiki/Null_Object_pattern) in Ruby. #### What's that supposed to mean? Null Objects can make your code more [confident](http://confidentruby.com). Here's a method that's not very sure of itself. ```ruby class Geordi def make_it_so(logger=nil) logger && logger.info("Reversing the flux phase capacitance!") logger && logger.info("Bounding a tachyon particle beam off of Data's cat!") logger && logger.warn("Warning, bogon levels are rising!") end end ``` Now, observe as we give it a dash of confidence with the Null Object pattern! ```ruby class NullLogger def debug(*); end def info(*); end def warn(*); end def error(*); end def fatal(*); end end class Geordi def make_it_so(logger=NullLogger.new) logger.info "Reversing the flux phase capacitance!" logger.info "Bounding a tachyon particle beam off of Data's cat!" logger.warn "Warning, bogon levels are rising!" end end ``` By providing a `NullLogger` which implements [some of] the `Logger` interface as no-op methods, we've gotten rid of those unsightly `&&` operators. #### That was simple enough. Why do I need a library for it? You don't! The Null Object pattern is a very simple one at its core. #### And yet here we are… Yes. While you don't *need* a Null Object library, this one offers some conveniences you probably won't find elsewhere. But there's an even more important reason I wrote this library. In the immortal last words of James T. Kirk: "It was… *fun!*" #### OK, so how do I use this thing? Well, what would you like to do? #### I dunno, gimme an object that responds to any message with nil Sure thing! ```ruby require 'naught' NullObject = Naught.build null = NullObject.new null.foo # => nil null.bar # => nil ``` #### That was… weird. What's with this "build" business? Naught is a *toolkit* for building null object classes. It is not a one-size-fits-all solution. What else can I make for you? #### How about a "black hole" null object that supports infinite chaining of methods? OK. ```ruby require 'naught' BlackHole = Naught.build do |config| config.black_hole end null = BlackHole.new null.foo # => null.foo.bar.baz # => null << "hello" << "world" # => ``` #### What's that "config" thing? That's what you use to customize the generated class to your liking. Internally, Naught uses the [Builder Pattern](http://en.wikipedia.org/wiki/Builder_pattern) to make this work.. #### Whatever. What if I want a null object that has conversions to Integer, String, etc. using sensible conversions to "zero values"? We can do that. ```ruby require 'naught' NullObject = Naught.build do |config| config.define_explicit_conversions end null = NullObject.new null.to_s # => "" null.to_i # => 0 null.to_f # => 0.0 null.to_a # => [] null.to_h # => {} null.to_c # => (0+0i) null.to_r # => (0/1) ``` #### Ah, but what about implicit conversions such as `#to_str`? Like what if I want a null object that implicitly splats the same way as an empty array? Gotcha covered. ```ruby require 'naught' NullObject = Naught.build do |config| config.define_implicit_conversions end null = NullObject.new null.to_str # => "" null.to_ary # => [] a, b, c = [] a # => nil b # => nil c # => nil x, y, z = null x # => nil y # => nil z # => nil ``` #### How about a null object that only stubs out the methods from a specific class? That's what `mimic` is for. ```ruby require 'naught' NullIO = Naught.build do |config| config.mimic IO end null_io = NullIO.new null_io << "foo" # => nil null_io.readline # => nil null_io.foobar # => # ~> -:11:in `
': undefined method `foobar' for # :NullIO (NoMethodError) ``` There is also `impersonate` which takes `mimic` one step further. The generated null class will be derived from the impersonated class. This is handy when refitting legacy code that contains type checks. ```ruby require 'naught' NullIO = Naught.build do |config| config.impersonate IO end null_io = NullIO.new IO === null_io # => true case null_io when IO puts "Yep, checks out!" null_io << "some output" else raise "Hey, I expected an IO!" end # >> Yep, checks out! ``` #### What about predicate methods? You know, the ones that end with question marks? Shouldn't they return `false` instead of `nil`? Sure, if you'd like. ```ruby require 'naught' NullObject = Naught.build do |config| config.predicates_return false end null = NullObject.new null.foo # => nil null.bar? # => false null.nil? # => false ``` #### Alright smartypants. What if I want to add my own methods? Not a problem, just define them in the `.build` block. ```ruby require 'naught' NullObject = Naught.build do |config| config.define_explicit_conversions config.predicates_return false def to_path "/dev/null" end # You can override methods generated by Naught def to_s "NOTHING TO SEE HERE MOVE ALONG" end def nil? true end end null = NullObject.new null.to_path # => "/dev/null" null.to_s # => "NOTHING TO SEE HERE MOVE ALONG" null.nil? # => true ``` #### Got anything else up your sleeve? Well, we can make the null class a singleton, since null objects generally have no state. ```ruby require 'naught' NullObject = Naught.build do |config| config.singleton end null = NullObject.instance null.__id__ # => 17844080 NullObject.instance.__id__ # => 17844080 NullObject.new # => # ~> -:11:in `
': private method `new' called for # NullObject:Class (NoMethodError) ``` Speaking of null objects with state, we can also enable tracing. This is handy for playing "where'd that null come from?!" Try doing *that* with `nil`! ```ruby require 'naught' NullObject = Naught.build do |config| config.traceable end null = NullObject.new # line 7 null.__file__ # => "example.rb" null.__line__ # => 7 ``` We can even conditionally enable either singleton mode (for production) or tracing (for development). Here's an example of using the `$DEBUG` global variable (set with the `-d` option to ruby) to choose which one. ```ruby require 'naught' NullObject = Naught.build do |config| if $DEBUG config.traceable else config.singleton end end ``` The only caveat is that when swapping between singleton and non-singleton implementations, you should be careful to always instantiate your null objects with `NullObject.get`, not `.new` or `.instance`. `.get` will work whether the class is implemented as a singleton or not. ```ruby NullObject.get # => ``` #### And if I want to know legacy code better? Naught can make a null object behave as a pebble object. ```ruby require 'naught' NullObject = Naught.build do |config| if $DEBUG config.pebble else config.black_hole end end ``` Now you can pass the pebble object to your code and see which messages are sent to the pebble. ```ruby null = NullObject.new class MyConsumer < Struct.new(:producer) def consume producer.produce end end MyConsumer.new(null).consume # >> produce() from consume # => ``` #### Are you done yet? Just one more thing. For maximum convenience, Naught-generated null classes also come with a full suite of conversion functions which can be included into your classes. ```ruby require 'naught' NullObject = Naught.build include NullObject::Conversions # Convert nil to null objects. Everything else passes through. Maybe(42) # => 42 Maybe(nil) # => Maybe(NullObject.get) # => Maybe{ 42 } # => 42 # Insist on a non-null (or nil) value Just(42) # => 42 Just(nil) rescue $! # => # Just(NullObject.get) rescue $! # => #> # nils and nulls become nulls. Everything else is rejected. Null() # => Null(42) rescue $! # => # Null(nil) # => Null(NullObject.get) # => # Convert nulls back to nils. Everything else passes through. Useful # for preventing null objects from "leaking" into public API return # values. Actual(42) # => 42 Actual(nil) # => nil Actual(NullObject.get) # => nil Actual { 42 } # => 42 ``` Installation -------------- ``` {.example} gem install naught ``` Requirements -------------- - Ruby 1.9 Contributing -------------- - Fork, branch, submit PR, blah blah blah. Don't forget tests. Who's responsible ------------------- Naught is by [Avdi Grimm](http://devblog.avdi.org/). Prior Art --------- This isn't the first Ruby Null Object library. Others to check out include: - [NullAndVoid](https://github.com/jfelchner/null_and_void) - [BlankSlate](https://github.com/saturnflyer/blank_slate) Further reading ----------------- - [Null Object: Something for Nothing](http://www.two-sdg.demon.co.uk/curbralan/papers/europlop/NullObject.pdf) (PDF) by Kevlin Henney - [The Null Object Pattern](http://www.cs.oberlin.edu/~jwalker/refs/woolf.ps) (PS) by Bobby Woolf - [NullObject](http://www.c2.com/cgi/wiki?NullObject) on WikiWiki - [Null Object pattern](http://en.wikipedia.org/wiki/Null_Object_pattern) on Wikipedia - [Null Objects and Falsiness](http://devblog.avdi.org/2011/05/30/null-objects-and-falsiness/), by Avdi Grimm ruby-naught-1.0.0/Rakefile000066400000000000000000000004231231624255200154230ustar00rootroot00000000000000require 'bundler/gem_tasks' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) begin require 'rubocop/rake_task' Rubocop::RakeTask.new rescue LoadError task :rubocop do $stderr.puts 'Rubocop is disabled' end end task :default => [:spec, :rubocop] ruby-naught-1.0.0/checksums.yaml.gz000066400000000000000000000004141231624255200172460ustar00rootroot00000000000000!Re;R0 D"%-Q08=%Rvr~#w>~0|VqJsTb*mdžOWݒ+ tnK<HX@; b࢓ޗ!mٚy$k,HSĨruby-naught-1.0.0/lib/000077500000000000000000000000001231624255200145255ustar00rootroot00000000000000ruby-naught-1.0.0/lib/naught.rb000066400000000000000000000004611231624255200163410ustar00rootroot00000000000000require 'naught/version' require 'naught/null_class_builder' require 'naught/null_class_builder/commands' module Naught def self.build(&customization_block) builder = NullClassBuilder.new builder.customize(&customization_block) builder.generate_class end module NullObjectTag end end ruby-naught-1.0.0/lib/naught/000077500000000000000000000000001231624255200160135ustar00rootroot00000000000000ruby-naught-1.0.0/lib/naught/basic_object.rb000066400000000000000000000007211231624255200207470ustar00rootroot00000000000000module Naught if defined? ::BasicObject class BasicObject < ::BasicObject end else class BasicObject #:nodoc: keep = %w[ ! != == __id__ __send__ equal? instance_eval instance_exec method_missing singleton_method_added singleton_method_removed singleton_method_undefined ] instance_methods.each do |method_name| undef_method(method_name) unless keep.include?(method_name) end end end end ruby-naught-1.0.0/lib/naught/conversions.rb000066400000000000000000000022521231624255200207110ustar00rootroot00000000000000module Naught module Conversions def self.included(null_class) unless class_variable_defined?(:@@included) && @@included @@null_class = null_class @@null_equivs = null_class::NULL_EQUIVS @@included = true end super end def Null(object = :nothing_passed) case object when NullObjectTag object when :nothing_passed, *@@null_equivs @@null_class.get(:caller => caller(1)) else fail ArgumentError, "#{object.inspect} is not null!" end end def Maybe(object = nil) object = yield if block_given? case object when NullObjectTag object when *@@null_equivs @@null_class.get(:caller => caller(1)) else object end end def Just(object = nil) object = yield if block_given? case object when NullObjectTag, *@@null_equivs fail ArgumentError, "Null value: #{object.inspect}" else object end end def Actual(object = nil) object = yield if block_given? case object when NullObjectTag nil else object end end end end ruby-naught-1.0.0/lib/naught/null_class_builder.rb000066400000000000000000000112671231624255200222140ustar00rootroot00000000000000require 'naught/basic_object' require 'naught/conversions' module Naught class NullClassBuilder # make sure this module exists module Commands end attr_accessor :base_class, :inspect_proc, :interface_defined def initialize @interface_defined = false @base_class = Naught::BasicObject @inspect_proc = lambda { '' } @stub_strategy = :stub_method_returning_nil define_basic_methods end def interface_defined? !!@interface_defined end def customize(&customization_block) return unless customization_block customization_module.module_exec(self, &customization_block) end def customization_module @customization_module ||= Module.new end def null_equivalents @null_equivalents ||= [nil] end def generate_class respond_to_any_message unless interface_defined? generation_mod = Module.new customization_mod = customization_module # get a local binding builder = self apply_operations(operations, generation_mod) null_class = Class.new(@base_class) do const_set :GeneratedMethods, generation_mod const_set :Customizations, customization_mod const_set :NULL_EQUIVS, builder.null_equivalents include Conversions remove_const :NULL_EQUIVS Conversions.instance_methods.each do |instance_method| undef_method(instance_method) end const_set :Conversions, Conversions include NullObjectTag include generation_mod include customization_mod end apply_operations(class_operations, null_class) null_class end def method_missing(method_name, *args, &block) command_name = command_name_for_method(method_name) if Commands.const_defined?(command_name) command_class = Commands.const_get(command_name) command_class.new(self, *args, &block).call else super end end if RUBY_VERSION >= '1.9' def respond_to_missing?(method_name, include_private = false) command_name = command_name_for_method(method_name) Commands.const_defined?(command_name) || super rescue NameError super end else def respond_to?(method_name, include_private = false) command_name = command_name_for_method(method_name) Commands.const_defined?(command_name) || super rescue NameError super end end ############################################################################ # Builder API # # See also the contents of lib/naught/null_class_builder/commands ############################################################################ def black_hole @stub_strategy = :stub_method_returning_self end def respond_to_any_message defer(:prepend => true) do |subject| subject.module_eval do def respond_to?(*) true end end stub_method(subject, :method_missing) end @interface_defined = true end def defer(options = {}, &deferred_operation) list = options[:class] ? class_operations : operations if options[:prepend] list.unshift(deferred_operation) else list << deferred_operation end end def stub_method(subject, name) send(@stub_strategy, subject, name) end private def define_basic_methods define_basic_instance_methods define_basic_class_methods end def apply_operations(operations, module_or_class) operations.each do |operation| operation.call(module_or_class) end end def define_basic_instance_methods defer do |subject| subject.module_exec(@inspect_proc) do |inspect_proc| define_method(:inspect, &inspect_proc) def initialize(*) end end end end def define_basic_class_methods defer(:class => true) do |subject| subject.module_eval do class << self alias_method :get, :new end klass = self define_method(:class) { klass } end end end def class_operations @class_operations ||= [] end def operations @operations ||= [] end def stub_method_returning_nil(subject, name) subject.module_eval do define_method(name) { |*| nil } end end def stub_method_returning_self(subject, name) subject.module_eval do define_method(name) { |*| self } end end def command_name_for_method(method_name) method_name.to_s.gsub(/(?:^|_)([a-z])/) { Regexp.last_match[1].upcase } end end end ruby-naught-1.0.0/lib/naught/null_class_builder/000077500000000000000000000000001231624255200216605ustar00rootroot00000000000000ruby-naught-1.0.0/lib/naught/null_class_builder/command.rb000066400000000000000000000006001231624255200236170ustar00rootroot00000000000000module Naught class NullClassBuilder class Command attr_reader :builder def initialize(builder) @builder = builder end def call fail NotImplementedError, 'Method #call should be overriden in child classes' end def defer(options = {}, &block) @builder.defer(options, &block) end end end end ruby-naught-1.0.0/lib/naught/null_class_builder/commands.rb000066400000000000000000000007371231624255200240150ustar00rootroot00000000000000require 'naught/null_class_builder/commands/define_explicit_conversions' require 'naught/null_class_builder/commands/define_implicit_conversions' require 'naught/null_class_builder/commands/pebble' require 'naught/null_class_builder/commands/predicates_return' require 'naught/null_class_builder/commands/singleton' require 'naught/null_class_builder/commands/traceable' require 'naught/null_class_builder/commands/mimic' require 'naught/null_class_builder/commands/impersonate' ruby-naught-1.0.0/lib/naught/null_class_builder/commands/000077500000000000000000000000001231624255200234615ustar00rootroot00000000000000ruby-naught-1.0.0/lib/naught/null_class_builder/commands/define_explicit_conversions.rb000066400000000000000000000006161231624255200315740ustar00rootroot00000000000000require 'forwardable' require 'naught/null_class_builder/command' module Naught::NullClassBuilder::Commands class DefineExplicitConversions < ::Naught::NullClassBuilder::Command def call defer do |subject| subject.module_eval do extend Forwardable def_delegators :nil, :to_a, :to_c, :to_f, :to_h, :to_i, :to_r, :to_s end end end end end ruby-naught-1.0.0/lib/naught/null_class_builder/commands/define_implicit_conversions.rb000066400000000000000000000005611231624255200315640ustar00rootroot00000000000000require 'naught/null_class_builder/command' module Naught::NullClassBuilder::Commands class DefineImplicitConversions < ::Naught::NullClassBuilder::Command def call defer do |subject| subject.module_eval do def to_ary [] end def to_str '' end end end end end end ruby-naught-1.0.0/lib/naught/null_class_builder/commands/impersonate.rb000066400000000000000000000003701231624255200263340ustar00rootroot00000000000000module Naught::NullClassBuilder::Commands class Impersonate < Naught::NullClassBuilder::Commands::Mimic def initialize(builder, class_to_impersonate, options = {}) super builder.base_class = class_to_impersonate end end end ruby-naught-1.0.0/lib/naught/null_class_builder/commands/mimic.rb000066400000000000000000000017251231624255200251110ustar00rootroot00000000000000require 'naught/basic_object' require 'naught/null_class_builder/command' module Naught::NullClassBuilder::Commands class Mimic < Naught::NullClassBuilder::Command attr_reader :class_to_mimic, :include_super def initialize(builder, class_to_mimic, options = {}) super(builder) @class_to_mimic = class_to_mimic @include_super = options.fetch(:include_super) { true } builder.base_class = root_class_of(class_to_mimic) builder.inspect_proc = lambda { "" } builder.interface_defined = true end def call defer do |subject| methods_to_stub.each do |method_name| builder.stub_method(subject, method_name) end end end private def root_class_of(klass) klass.ancestors.include?(Object) ? Object : Naught::BasicObject end def methods_to_stub class_to_mimic.instance_methods(include_super) - Object.instance_methods end end end ruby-naught-1.0.0/lib/naught/null_class_builder/commands/pebble.rb000066400000000000000000000017451231624255200252460ustar00rootroot00000000000000require 'naught/null_class_builder/command' module Naught class NullClassBuilder module Commands class Pebble < ::Naught::NullClassBuilder::Command def initialize(builder, output = $stdout) @builder = builder @output = output end def call defer do |subject| subject.module_exec(@output) do |output| define_method(:method_missing) do |method_name, *args, &block| pretty_args = args.collect(&:inspect).join(', ').gsub("\"", "'") output.puts "#{method_name}(#{pretty_args}) from #{parse_caller}" self end def parse_caller caller = Kernel.caller(2).first method_name = caller.match(/\`([\w\s]+(\(\d+\s\w+\))?[\w\s]*)/) method_name ? method_name[1] : caller end private :parse_caller end end end end end end end ruby-naught-1.0.0/lib/naught/null_class_builder/commands/predicates_return.rb000066400000000000000000000024221231624255200275300ustar00rootroot00000000000000require 'naught/null_class_builder/command' module Naught::NullClassBuilder::Commands class PredicatesReturn < Naught::NullClassBuilder::Command def initialize(builder, return_value) super(builder) @predicate_return_value = return_value end def call defer do |subject| define_method_missing(subject) define_predicate_methods(subject) end end private def define_method_missing(subject) subject.module_exec(@predicate_return_value) do |return_value| if subject.method_defined?(:method_missing) original_method_missing = instance_method(:method_missing) define_method(:method_missing) do |method_name, *args, &block| if method_name.to_s.end_with?('?') return_value else original_method_missing.bind(self).call(method_name, *args, &block) end end end end end def define_predicate_methods(subject) subject.module_exec(@predicate_return_value) do |return_value| instance_methods.each do |method_name| if method_name.to_s.end_with?('?') define_method(method_name) do |*| return_value end end end end end end end ruby-naught-1.0.0/lib/naught/null_class_builder/commands/singleton.rb000066400000000000000000000010131231624255200260030ustar00rootroot00000000000000require 'naught/null_class_builder/command' module Naught::NullClassBuilder::Commands class Singleton < Naught::NullClassBuilder::Command def call defer(:class => true) do |subject| require 'singleton' subject.module_eval do include ::Singleton def self.get(*) instance end %w(dup clone).each do |method_name| define_method method_name do self end end end end end end end ruby-naught-1.0.0/lib/naught/null_class_builder/commands/traceable.rb000066400000000000000000000011201231624255200257220ustar00rootroot00000000000000require 'naught/null_class_builder/command' module Naught::NullClassBuilder::Commands class Traceable < Naught::NullClassBuilder::Command def call defer do |subject| subject.module_eval do attr_reader :__file__, :__line__ def initialize(options = {}) range = (RUBY_VERSION.to_f == 1.9 && RUBY_PLATFORM != 'java') ? 4 : 3 backtrace = options.fetch(:caller) { Kernel.caller(range) } @__file__, line, _ = backtrace[0].split(':') @__line__ = line.to_i end end end end end end ruby-naught-1.0.0/lib/naught/version.rb000066400000000000000000000000461231624255200200250ustar00rootroot00000000000000module Naught VERSION = '1.0.0' end ruby-naught-1.0.0/metadata.yml000066400000000000000000000065231231624255200162700ustar00rootroot00000000000000--- !ruby/object:Gem::Specification name: naught version: !ruby/object:Gem::Version version: 1.0.0 platform: ruby authors: - Avdi Grimm autorequire: bindir: bin cert_chain: [] date: 2014-01-26 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: bundler requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.3' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.3' description: Naught is a toolkit for building Null Objects email: - avdi@avdi.org executables: [] extensions: [] extra_rdoc_files: [] files: - ".gitignore" - ".rspec" - ".rubocop.yml" - ".travis.yml" - Changelog.md - Gemfile - Guardfile - LICENSE.txt - README.markdown - Rakefile - lib/naught.rb - lib/naught/basic_object.rb - lib/naught/conversions.rb - lib/naught/null_class_builder.rb - lib/naught/null_class_builder/command.rb - lib/naught/null_class_builder/commands.rb - lib/naught/null_class_builder/commands/define_explicit_conversions.rb - lib/naught/null_class_builder/commands/define_implicit_conversions.rb - lib/naught/null_class_builder/commands/impersonate.rb - lib/naught/null_class_builder/commands/mimic.rb - lib/naught/null_class_builder/commands/pebble.rb - lib/naught/null_class_builder/commands/predicates_return.rb - lib/naught/null_class_builder/commands/singleton.rb - lib/naught/null_class_builder/commands/traceable.rb - lib/naught/version.rb - naught.gemspec - spec/base_object_spec.rb - spec/basic_null_object_spec.rb - spec/blackhole_spec.rb - spec/explicit_conversions_spec.rb - spec/functions/actual_spec.rb - spec/functions/just_spec.rb - spec/functions/maybe_spec.rb - spec/functions/null_spec.rb - spec/implicit_conversions_spec.rb - spec/mimic_spec.rb - spec/naught/null_object_builder/command_spec.rb - spec/naught/null_object_builder_spec.rb - spec/naught_spec.rb - spec/pebble_spec.rb - spec/predicate_spec.rb - spec/singleton_null_object_spec.rb - spec/spec_helper.rb - spec/support/convertable_null.rb - spec/support/jruby.rb - spec/support/rubinius.rb - spec/support/ruby_18.rb homepage: https://github.com/avdi/naught licenses: - MIT metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.2.1 signing_key: specification_version: 4 summary: Naught is a toolkit for building Null Objects test_files: - spec/base_object_spec.rb - spec/basic_null_object_spec.rb - spec/blackhole_spec.rb - spec/explicit_conversions_spec.rb - spec/functions/actual_spec.rb - spec/functions/just_spec.rb - spec/functions/maybe_spec.rb - spec/functions/null_spec.rb - spec/implicit_conversions_spec.rb - spec/mimic_spec.rb - spec/naught/null_object_builder/command_spec.rb - spec/naught/null_object_builder_spec.rb - spec/naught_spec.rb - spec/pebble_spec.rb - spec/predicate_spec.rb - spec/singleton_null_object_spec.rb - spec/spec_helper.rb - spec/support/convertable_null.rb - spec/support/jruby.rb - spec/support/rubinius.rb - spec/support/ruby_18.rb ruby-naught-1.0.0/naught.gemspec000066400000000000000000000014661231624255200166210ustar00rootroot00000000000000# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'naught/version' Gem::Specification.new do |spec| spec.name = 'naught' spec.version = Naught::VERSION spec.authors = ['Avdi Grimm'] spec.email = ['avdi@avdi.org'] spec.description = %q{Naught is a toolkit for building Null Objects} spec.summary = spec.description spec.homepage = 'https://github.com/avdi/naught' spec.license = 'MIT' spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR) spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) } spec.test_files = spec.files.grep(/^(test|spec|features)\//) spec.require_paths = ['lib'] spec.add_development_dependency 'bundler', '~> 1.3' end ruby-naught-1.0.0/spec/000077500000000000000000000000001231624255200147115ustar00rootroot00000000000000ruby-naught-1.0.0/spec/base_object_spec.rb000066400000000000000000000020541231624255200205110ustar00rootroot00000000000000require 'spec_helper' describe 'null object with a custom base class' do subject(:null) { custom_base_null_class.new } let(:custom_base_null_class) do Naught.build do |b| b.base_class = Object end end it 'respond to base class methods' do expect(null.methods).to be_an Array end it 'respond to unknown methods' do expect(null.foo).to be_nil end it 'exposes the default base class choice, for the curious' do default_base_class = :not_set Naught.build do |b| default_base_class = b.base_class end expect(default_base_class).to eq(Naught::BasicObject) end describe 'singleton null object' do subject(:null_instance) { custom_base_singleton_null_class.instance } let(:custom_base_singleton_null_class) do Naught.build do |b| b.singleton b.base_class = Object end end it 'can be cloned' do expect(null_instance.clone).to be(null_instance) end it 'can be duplicated' do expect(null_instance.dup).to be(null_instance) end end end ruby-naught-1.0.0/spec/basic_null_object_spec.rb000066400000000000000000000014261231624255200217140ustar00rootroot00000000000000require 'spec_helper' describe 'basic null object' do let(:null_class) { Naught.build } subject(:null) { null_class.new } it 'responds to arbitrary messages and returns nil' do expect(null.info).to be_nil expect(null.foobaz).to be_nil expect(null.to_s).to be_nil end it 'accepts any arguments for any messages' do null.foobaz(1, 2, 3) end it 'reports that it responds to any message' do expect(null).to respond_to(:info) expect(null).to respond_to(:foobaz) expect(null).to respond_to(:to_s) end it 'can be inspected' do expect(null.inspect).to eq('') end it 'knows its own class' do expect(null.class).to eq(null_class) end it 'aliases .new to .get' do expect(null_class.get.class).to be(null_class) end end ruby-naught-1.0.0/spec/blackhole_spec.rb000066400000000000000000000005301231624255200201720ustar00rootroot00000000000000require 'spec_helper' describe 'black hole null object' do subject(:null) { null_class.new } let(:null_class) do Naught.build do |b| b.black_hole end end it 'returns self from arbitray method calls' do expect(null.info).to be(null) expect(null.foobaz).to be(null) expect(null << 'bar').to be(null) end end ruby-naught-1.0.0/spec/explicit_conversions_spec.rb000066400000000000000000000011321231624255200225160ustar00rootroot00000000000000require 'spec_helper.rb' describe 'explicitly convertable null object' do let(:null_class) do Naught.build do |b| b.define_explicit_conversions end end subject(:null) { null_class.new } it 'defines common explicit conversions to return zero values' do expect(null.to_s).to eq('') expect(null.to_a).to eq([]) expect(null.to_i).to eq(0) expect(null.to_f).to eq(0.0) if RUBY_VERSION >= '2.0' expect(null.to_h).to eq({}) elsif RUBY_VERSION >= '1.9' expect(null.to_c).to eq(Complex(0)) expect(null.to_r).to eq(Rational(0)) end end end ruby-naught-1.0.0/spec/functions/000077500000000000000000000000001231624255200167215ustar00rootroot00000000000000ruby-naught-1.0.0/spec/functions/actual_spec.rb000066400000000000000000000010361231624255200215310ustar00rootroot00000000000000require 'spec_helper' describe 'Actual()' do include ConvertableNull::Conversions specify 'given a null object, returns nil' do null = ConvertableNull.get expect(Actual(null)).to be_nil end specify 'given anything else, returns the input unchanged' do expect(Actual(false)).to be(false) str = 'hello' expect(Actual(str)).to be(str) expect(Actual(nil)).to be_nil end it 'also works with blocks' do expect(Actual { ConvertableNull.new }).to be_nil expect(Actual { 'foo' }).to eq('foo') end end ruby-naught-1.0.0/spec/functions/just_spec.rb000066400000000000000000000011301231624255200212400ustar00rootroot00000000000000require 'spec_helper' describe 'Just()' do include ConvertableNull::Conversions specify 'passes non-nullish values through' do expect(Just(false)).to be(false) str = 'hello' expect(Just(str)).to be(str) end specify 'rejects nullish values' do expect { Just(nil) }.to raise_error(ArgumentError) expect { Just('') }.to raise_error(ArgumentError) expect { Just(ConvertableNull.get) }.to raise_error(ArgumentError) end it 'also works with blocks' do expect { Just { nil }.class }.to raise_error(ArgumentError) expect(Just { 'foo' }).to eq('foo') end end ruby-naught-1.0.0/spec/functions/maybe_spec.rb000066400000000000000000000016531231624255200213620ustar00rootroot00000000000000require 'spec_helper' describe 'Maybe()' do include ConvertableNull::Conversions specify 'given nil, returns a null object' do expect(Maybe(nil).class).to be(ConvertableNull) end specify 'given a null object, returns the same null object' do null = ConvertableNull.get expect(Maybe(null)).to be(null) end specify 'given anything in null_equivalents, return a null object' do expect(Maybe('').class).to be(ConvertableNull) end specify 'given anything else, returns the input unchanged' do expect(Maybe(false)).to be(false) str = 'hello' expect(Maybe(str)).to be(str) end it 'generates null objects with useful trace info' do null, line = Maybe(), __LINE__ expect(null.__file__).to eq(__FILE__) expect(null.__line__).to eq(line) end it 'also works with blocks' do expect(Maybe { nil }.class).to eq(ConvertableNull) expect(Maybe { 'foo' }).to eq('foo') end end ruby-naught-1.0.0/spec/functions/null_spec.rb000066400000000000000000000016411231624255200212340ustar00rootroot00000000000000require 'spec_helper' describe 'Null()' do include ConvertableNull::Conversions specify 'given no input, returns a null object' do expect(Null().class).to be(ConvertableNull) end specify 'given nil, returns a null object' do expect(Null(nil).class).to be(ConvertableNull) end specify 'given a null object, returns the same null object' do null = ConvertableNull.get expect(Null(null)).to be(null) end specify 'given anything in null_equivalents, return a null object' do expect(Null('').class).to be(ConvertableNull) end specify 'given anything else, raises an ArgumentError' do expect { Null(false) }.to raise_error(ArgumentError) expect { Null('hello') }.to raise_error(ArgumentError) end it 'generates null objects with useful trace info' do null, line = Null(), __LINE__ expect(null.__file__).to eq(__FILE__) expect(null.__line__).to eq(line) end end ruby-naught-1.0.0/spec/implicit_conversions_spec.rb000066400000000000000000000011431231624255200225110ustar00rootroot00000000000000require 'spec_helper' describe 'implicitly convertable null object' do subject(:null) { null_class.new } let(:null_class) do Naught.build do |b| b.define_implicit_conversions end end it 'implicitly splats the same way an empty array does' do a, b = null expect(a).to be_nil expect(b).to be_nil end it 'is implicitly convertable to String' do expect(instance_eval(null)).to be_nil end it 'implicitly converts to an empty array' do expect(null.to_ary).to eq([]) end it 'implicitly converts to an empty string' do expect(null.to_str).to eq('') end end ruby-naught-1.0.0/spec/mimic_spec.rb000066400000000000000000000051131231624255200173460ustar00rootroot00000000000000require 'spec_helper' require 'logger' describe 'null object mimicking a class' do class User def login 'bob' end end module Authorizable def authorized_for?(object) true end end class LibraryPatron < User include Authorizable def member? true end def name 'Bob' end def notify_of_overdue_books(titles) puts 'Notifying...' end end subject(:null) { mimic_class.new } let(:mimic_class) do Naught.build do |b| b.mimic LibraryPatron end end it 'responds to all methods defined on the target class' do expect(null.member?).to be_nil expect(null.name).to be_nil expect(null.notify_of_overdue_books(['The Grapes of Wrath'])).to be_nil end it 'does not respond to methods not defined on the target class' do expect { null.foobar }.to raise_error(NoMethodError) end it 'reports which messages it does and does not respond to' do expect(null).to respond_to(:member?) expect(null).to respond_to(:name) expect(null).to respond_to(:notify_of_overdue_books) expect(null).not_to respond_to(:foobar) end it 'has an informative inspect string' do expect(null.inspect).to eq('') end it 'excludes Object methods from being mimicked' do expect(null.object_id).not_to be_nil expect(null.hash).not_to be_nil end it 'includes inherited methods' do expect(null.authorized_for?('something')).to be_nil expect(null.login).to be_nil end describe 'with include_super: false' do let(:mimic_class) do Naught.build do |b| b.mimic LibraryPatron, :include_super => false end end it 'excludes inherited methods' do expect(null).to_not respond_to(:authorized_for?) expect(null).to_not respond_to(:login) end end end describe 'using mimic with black_hole' do subject(:null) { mimic_class.new } let(:mimic_class) do Naught.build do |b| b.mimic Logger b.black_hole end end def self.it_behaves_like_a_black_hole_mimic it 'returns self from mimicked methods' do expect(null.info).to equal(null) expect(null.error).to equal(null) expect(null << 'test').to equal(null) end it 'does not respond to methods not defined on the target class' do expect { null.foobar }.to raise_error(NoMethodError) end end it_behaves_like_a_black_hole_mimic describe '(reverse order)' do let(:mimic_class) do Naught.build do |b| b.black_hole b.mimic Logger end end it_behaves_like_a_black_hole_mimic end end ruby-naught-1.0.0/spec/naught/000077500000000000000000000000001231624255200161775ustar00rootroot00000000000000ruby-naught-1.0.0/spec/naught/null_object_builder/000077500000000000000000000000001231624255200222055ustar00rootroot00000000000000ruby-naught-1.0.0/spec/naught/null_object_builder/command_spec.rb000066400000000000000000000003541231624255200251640ustar00rootroot00000000000000require 'spec_helper' module Naught describe NullClassBuilder::Command do it 'is abstract' do command = NullClassBuilder::Command.new(nil) expect { command.call }.to raise_error(NotImplementedError) end end end ruby-naught-1.0.0/spec/naught/null_object_builder_spec.rb000066400000000000000000000017001231624255200235420ustar00rootroot00000000000000require 'spec_helper' module Naught class NullClassBuilder module Commands class TestCommand end end end describe NullClassBuilder do subject(:builder) { NullClassBuilder.new } it 'responds to commands defined in NullObjectBuilder::Commands' do expect(builder).to respond_to(:test_command) end it 'translates method calls into command invocations including arguments' do test_command = double expect(NullClassBuilder::Commands::TestCommand).to receive(:new). with(builder, 'foo', 42). and_return(test_command) expect(test_command).to receive(:call).and_return('COMMAND RESULT') expect(builder.test_command('foo', 42)).to eq('COMMAND RESULT') end it 'handles missing non-command missing methods normally' do expect(builder).not_to respond_to(:nonexistant_method) expect { builder.nonexistent_method }.to raise_error(NoMethodError) end end end ruby-naught-1.0.0/spec/naught_spec.rb000066400000000000000000000042131231624255200175360ustar00rootroot00000000000000require 'spec_helper' describe 'null object impersonating another type' do class Point def x 23 end def y 42 end end subject(:null) { impersonation_class.new } let(:impersonation_class) do Naught.build do |b| b.impersonate Point end end it 'matches the impersonated type' do expect(null).to be_a Point end it 'responds to methods from the impersonated type' do expect(null.x).to be_nil expect(null.y).to be_nil end it 'does not respond to unknown methods' do expect { null.foo }.to raise_error(NoMethodError) end end describe 'traceable null object' do subject(:trace_null) do null_object_and_line.first end let(:null_object_and_line) do obj, line = trace_null_class.new, __LINE__ [obj, line] end let(:instantiation_line) { null_object_and_line.last } let(:trace_null_class) do Naught.build do |b| b.traceable end end it 'remembers the file it was instantiated from' do expect(trace_null.__file__).to eq(__FILE__) end it 'remembers the line it was instantiated from' do expect(trace_null.__line__).to eq(instantiation_line) end def make_null trace_null_class.get(:caller => caller(1)) end it 'can accept custom backtrace info' do obj, line = make_null, __LINE__ expect(obj.__line__).to eq(line) end end describe 'customized null object' do subject(:custom_null) { custom_null_class.new } let(:custom_null_class) do Naught.build do |b| b.define_explicit_conversions def to_path '/dev/null' end def to_s 'NOTHING TO SEE HERE' end end end it 'responds to custom-defined methods' do expect(custom_null.to_path).to eq('/dev/null') end it 'allows generated methods to be overridden' do expect(custom_null.to_s).to eq('NOTHING TO SEE HERE') end end TestNull = Naught.build describe 'a named null object class' do it 'has named ancestor modules', :pending => rubinius? do expect(TestNull.ancestors[0..2].collect(&:name)).to eq([ 'TestNull', 'TestNull::Customizations', 'TestNull::GeneratedMethods' ]) end end ruby-naught-1.0.0/spec/pebble_spec.rb000066400000000000000000000040731231624255200175050ustar00rootroot00000000000000require 'spec_helper' require 'stringio' describe 'pebble null object' do class Caller def call_method(thing) thing.info end def call_method_inside_block(thing) 2.times.each { thing.info } end def call_method_inside_nested_block(thing) 2.times.each { 2.times.each { thing.info } } end end subject(:null) { null_class.new } let(:null_class) do output = test_output # getting local binding Naught.build do |b| b.pebble output end end let(:test_output) { StringIO.new } it 'prints the name of the method called' do expect(test_output).to receive(:puts).with(/^info\(\)/) null.info end it 'prints the arguments received' do expect(test_output).to receive(:puts).with(/^info\(\'foo\', 5, \:sym\)/) null.info('foo', 5, :sym) end it 'prints the name of the caller' do expect(test_output).to receive(:puts).with(/from call_method$/) Caller.new.call_method(null) end it 'returns self' do expect(null.info).to be(null) end context 'when is called from a block' do it 'prints the indication of a block', :pending => jruby? || rubinius? || ruby_18? do expect(test_output).to receive(:puts).twice. with(/from block/) Caller.new.call_method_inside_block(null) end it 'prints the name of the method that has the block' do expect(test_output).to receive(:puts).twice. with(/call_method_inside_block$/) Caller.new.call_method_inside_block(null) end end context 'when is called from many levels blocks' do it 'prints the indication of blocks and its levels', :pending => jruby? || rubinius? || ruby_18? do expect(test_output).to receive(:puts).exactly(4).times. with(/from block \(2 levels\)/) Caller.new.call_method_inside_nested_block(null) end it 'prints the name of the method that has the block' do expect(test_output).to receive(:puts).exactly(4).times. with(/call_method_inside_nested_block$/) Caller.new.call_method_inside_nested_block(null) end end end ruby-naught-1.0.0/spec/predicate_spec.rb000066400000000000000000000035031231624255200202110ustar00rootroot00000000000000require 'spec_helper' describe 'a null object with predicates_return(false)' do subject(:null) { null_class.new } let(:null_class) do Naught.build do |config| config.predicates_return false end end it 'responds to predicate-style methods with false' do expect(null.too_much_coffee?).to eq(false) end it 'responds to other methods with nil' do expect(null.foobar).to eq(nil) end describe '(black hole)' do let(:null_class) do Naught.build do |config| config.black_hole config.predicates_return false end end it 'responds to predicate-style methods with false' do expect(null.too_much_coffee?).to eq(false) end it 'responds to other methods with self' do expect(null.foobar).to be(null) end end describe '(black hole, reverse order config)' do let(:null_class) do Naught.build do |config| config.predicates_return false config.black_hole end end it 'responds to predicate-style methods with false' do expect(null.too_much_coffee?).to eq(false) end it 'responds to other methods with self' do expect(null.foobar).to be(null) end end class Coffee def black? true end def origin 'Ethiopia' end end describe '(mimic)' do let(:null_class) do Naught.build do |config| config.mimic Coffee config.predicates_return false end end it 'responds to predicate-style methods with false' do expect(null.black?).to eq(false) end it 'responds to other methods with nil' do expect(null.origin).to be(nil) end it 'does not respond to undefined methods' do expect(null).not_to respond_to(:leaf_variety) expect { null.leaf_variety }.to raise_error(NoMethodError) end end end ruby-naught-1.0.0/spec/singleton_null_object_spec.rb000066400000000000000000000013701231624255200226330ustar00rootroot00000000000000require 'spec_helper' describe 'singleton null object' do subject(:null_class) do Naught.build do |b| b.singleton end end it 'does not respond to .new' do expect { null_class.new }.to raise_error end it 'has only one instance' do null1 = null_class.instance null2 = null_class.instance expect(null1).to be(null2) end it 'can be cloned' do null = null_class.instance expect(null.clone).to be(null) end it 'can be duplicated' do null = null_class.instance expect(null.dup).to be(null) end it 'aliases .instance to .get' do expect(null_class.get).to be null_class.instance end it 'permits arbitrary arguments to be passed to .get' do null_class.get(42, :foo => 'bar') end end ruby-naught-1.0.0/spec/spec_helper.rb000066400000000000000000000004511231624255200175270ustar00rootroot00000000000000GEM_ROOT = File.expand_path('../../', __FILE__) $LOAD_PATH.unshift File.join(GEM_ROOT, 'lib') if ENV['TRAVIS'] require 'coveralls' Coveralls.wear! else require 'simplecov' SimpleCov.start end require 'naught' Dir[File.join(GEM_ROOT, 'spec', 'support', '**/*.rb')].each { |f| require f } ruby-naught-1.0.0/spec/support/000077500000000000000000000000001231624255200164255ustar00rootroot00000000000000ruby-naught-1.0.0/spec/support/convertable_null.rb000066400000000000000000000001231231624255200223040ustar00rootroot00000000000000ConvertableNull = Naught.build do |b| b.null_equivalents << '' b.traceable end ruby-naught-1.0.0/spec/support/jruby.rb000066400000000000000000000000511231624255200201010ustar00rootroot00000000000000def jruby? RUBY_PLATFORM == 'java' end ruby-naught-1.0.0/spec/support/rubinius.rb000066400000000000000000000001021231624255200206030ustar00rootroot00000000000000def rubinius? defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx' end ruby-naught-1.0.0/spec/support/ruby_18.rb000066400000000000000000000000541231624255200202420ustar00rootroot00000000000000def ruby_18? RUBY_VERSION.to_f == 1.8 end