naught-1.1.0/0000755000004100000410000000000012604541220013023 5ustar www-datawww-datanaught-1.1.0/Rakefile0000644000004100000410000000042312604541220014467 0ustar www-datawww-datarequire '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] naught-1.1.0/Gemfile0000644000004100000410000000120212604541220014311 0ustar www-datawww-datasource 'https://rubygems.org' # Specify your gem's dependencies in naught.gemspec gemspec gem 'rake' group :development do platforms :ruby_19, :ruby_20, :ruby_21, :ruby_22 do gem 'guard' gem 'guard-bundler' gem 'guard-rspec' end gem 'pry' 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 'rest-client', '~> 1.6.0', :platforms => [:jruby, :ruby_18] gem 'rspec', '>= 2.14' gem 'rubocop', '~> 0.34.0', :platforms => [:ruby_19, :ruby_20, :ruby_21, :ruby_22] end naught-1.1.0/.rspec0000644000004100000410000000002712604541220014137 0ustar www-datawww-data--color --order random naught-1.1.0/Changelog.md0000644000004100000410000000155012604541220015235 0ustar www-datawww-data## 1.1.0 - [Make it possible to supply an example object to mimic, with no class.](https://github.com/avdi/naught/commit/df2b62c027812760ce200177ce056929b5aea339) - [Define implicit conversion for to_hash](https://github.com/avdi/naught/commit/e20dc472d3bc71ba927d6ddb0fb0032e1646df77) - [Define implicit conversion for to_int](https://github.com/avdi/naught/commit/d32d4ea32a9a847bffd6cf18f480bdfaaf7a3641) ## 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) naught-1.1.0/LICENSE.txt0000644000004100000410000000205312604541220014646 0ustar www-datawww-dataCopyright (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. naught-1.1.0/spec/0000755000004100000410000000000012604541220013755 5ustar www-datawww-datanaught-1.1.0/spec/base_object_spec.rb0000644000004100000410000000205512604541220017556 0ustar www-datawww-datarequire '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 'responds to base class methods' do expect(null.methods).to be_an Array end it 'responds 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 naught-1.1.0/spec/singleton_null_object_spec.rb0000644000004100000410000000136312604541220021701 0ustar www-datawww-datarequire 'spec_helper' describe 'singleton null object' do subject(:null_class) do Naught.build(&:singleton) end it 'does not respond to .new' do expect { null_class.new }.to raise_error(NoMethodError) 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 naught-1.1.0/spec/spec_helper.rb0000644000004100000410000000061512604541220016575 0ustar www-datawww-dataGEM_ROOT = File.expand_path('../../', __FILE__) $LOAD_PATH.unshift File.join(GEM_ROOT, 'lib') require 'simplecov' require 'coveralls' SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter] SimpleCov.start do add_filter '/spec/' minimum_coverage(97.7) end require 'naught' Dir[File.join(GEM_ROOT, 'spec', 'support', '**/*.rb')].each { |f| require f } naught-1.1.0/spec/implicit_conversions_spec.rb0000644000004100000410000000136312604541220021561 0ustar www-datawww-datarequire 'spec_helper' describe 'implicitly convertable null object' do subject(:null) { null_class.new } let(:null_class) do Naught.build(&:define_implicit_conversions) 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 hash' do expect(null.to_hash).to eq({}) end it 'implicitly converts to zero' do expect(null.to_int).to eq(0) end it 'implicitly converts to an empty string' do expect(null.to_str).to eq('') end end naught-1.1.0/spec/basic_null_object_spec.rb0000644000004100000410000000142512604541220020757 0ustar www-datawww-datarequire '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 naught-1.1.0/spec/naught/0000755000004100000410000000000012604541220015243 5ustar www-datawww-datanaught-1.1.0/spec/naught/null_object_builder/0000755000004100000410000000000012604541220021251 5ustar www-datawww-datanaught-1.1.0/spec/naught/null_object_builder/command_spec.rb0000644000004100000410000000035412604541220024230 0ustar www-datawww-datarequire '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 naught-1.1.0/spec/naught/null_object_builder_spec.rb0000644000004100000410000000170012604541220022606 0ustar www-datawww-datarequire '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 naught-1.1.0/spec/functions/0000755000004100000410000000000012604541220015765 5ustar www-datawww-datanaught-1.1.0/spec/functions/actual_spec.rb0000644000004100000410000000103612604541220020575 0ustar www-datawww-datarequire '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 naught-1.1.0/spec/functions/just_spec.rb0000644000004100000410000000113012604541220020304 0ustar www-datawww-datarequire '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 naught-1.1.0/spec/functions/maybe_spec.rb0000644000004100000410000000172112604541220020422 0ustar www-datawww-datarequire '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, returns 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__ # rubocop:disable ParallelAssignment 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 naught-1.1.0/spec/functions/null_spec.rb0000644000004100000410000000170612604541220020302 0ustar www-datawww-datarequire '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, returns 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__ # rubocop:disable ParallelAssignment expect(null.__file__).to eq(__FILE__) expect(null.__line__).to eq(line) end end naught-1.1.0/spec/mimic_spec.rb0000644000004100000410000000571212604541220016417 0ustar www-datawww-datarequire 'spec_helper' require 'logger' describe 'null object mimicking a class' do class User attr_reader :login end module Authorizable def authorized_for?(_); end end class LibraryPatron < User include Authorizable attr_reader :name def member?; end def notify_of_overdue_books(_); 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 describe 'with an instance as example' do let(:mimic_class) do milton = LibraryPatron.new def milton.stapler; end Naught.build do |b| b.mimic :example => milton end end it 'responds to method defined only on the example instance' do expect(null).to respond_to(:stapler) end it 'responds to method defined on the class of the instance' do expect(null).to respond_to(:member?) 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 shared_examples_for 'a black hole mimic' do 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_should_behave_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_should_behave_like 'a black hole mimic' end end naught-1.1.0/spec/explicit_conversions_spec.rb0000644000004100000410000000110612604541220021563 0ustar www-datawww-datarequire 'spec_helper.rb' describe 'explicitly convertable null object' do let(:null_class) do Naught.build(&:define_explicit_conversions) 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 naught-1.1.0/spec/pebble_spec.rb0000644000004100000410000000407312604541220016551 0ustar www-datawww-datarequire '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 naught-1.1.0/spec/support/0000755000004100000410000000000012604541220015471 5ustar www-datawww-datanaught-1.1.0/spec/support/jruby.rb0000644000004100000410000000005112604541220017145 0ustar www-datawww-datadef jruby? RUBY_PLATFORM == 'java' end naught-1.1.0/spec/support/ruby_18.rb0000644000004100000410000000005412604541220017306 0ustar www-datawww-datadef ruby_18? RUBY_VERSION.to_f == 1.8 end naught-1.1.0/spec/support/rubinius.rb0000644000004100000410000000010212604541220017647 0ustar www-datawww-datadef rubinius? defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx' end naught-1.1.0/spec/support/convertable_null.rb0000644000004100000410000000012312604541220021350 0ustar www-datawww-dataConvertableNull = Naught.build do |b| b.null_equivalents << '' b.traceable end naught-1.1.0/spec/blackhole_spec.rb0000644000004100000410000000050412604541220017237 0ustar www-datawww-datarequire 'spec_helper' describe 'black hole null object' do subject(:null) { null_class.new } let(:null_class) do Naught.build(&:black_hole) 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 naught-1.1.0/spec/predicate_spec.rb0000644000004100000410000000344412604541220017261 0ustar www-datawww-datarequire '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 be(false) end it 'responds to other methods with nil' do expect(null.foobar).to be(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 be(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 be(false) end it 'responds to other methods with self' do expect(null.foobar).to be(null) end end class Coffee attr_reader :origin def black?; 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 be(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 naught-1.1.0/spec/naught_spec.rb0000644000004100000410000000420312604541220016601 0ustar www-datawww-datarequire 'spec_helper' describe 'null object impersonating another type' do class Point attr_reader :x, :y 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__ # rubocop:disable ParallelAssignment [obj, line] end let(:instantiation_line) { null_object_and_line.last } let(:trace_null_class) do Naught.build(&:traceable) 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__ # rubocop:disable ParallelAssignment 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' do expect(TestNull.ancestors[0..2].collect(&:name)).to eq([ 'TestNull', 'TestNull::Customizations', 'TestNull::GeneratedMethods', ]) end end naught-1.1.0/.travis.yml0000644000004100000410000000061512604541220015136 0ustar www-datawww-databefore_install: gem update bundler bundler_args: --without development --retry=3 --jobs=3 cache: bundler env: global: - JRUBY_OPTS="$JRUBY_OPTS --debug" language: ruby rvm: - 1.8.7 - 1.9.3 - 2.0.0 - 2.1 - 2.2 - jruby-9000 - jruby-head - rbx-2 - ruby-head matrix: allow_failures: - rvm: jruby-head - rvm: rbx-2 - rvm: ruby-head fast_finish: true sudo: false naught-1.1.0/lib/0000755000004100000410000000000012604541220013571 5ustar www-datawww-datanaught-1.1.0/lib/naught/0000755000004100000410000000000012604541220015057 5ustar www-datawww-datanaught-1.1.0/lib/naught/null_class_builder.rb0000644000004100000410000001204612604541220021254 0ustar www-datawww-datarequire 'naught/basic_object' require 'naught/conversions' module Naught class NullClassBuilder # rubocop:disable ClassLength # make sure this module exists module Commands end attr_accessor :base_class, :inspect_proc, :interface_defined alias_method :interface_defined?, :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 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 # rubocop:disable AbcSize 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 ############################################################################ # 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 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) respond_to_definition(method_name, include_private, :respond_to_missing?) end else def respond_to?(method_name, include_private = false) respond_to_definition(method_name, include_private, :respond_to?) end end private def respond_to_definition(method_name, include_private, respond_to_method_name) command_name = command_name_for_method(method_name) Commands.const_defined?(command_name) || super_duper(respond_to_method_name, method_name, include_private) rescue NameError super_duper(respond_to_method_name, method_name, include_private) end def super_duper(method_name, *args) self.class.superclass.send(method_name, *args) end 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 naught-1.1.0/lib/naught/conversions.rb0000644000004100000410000000226412604541220017760 0ustar www-datawww-datamodule 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.new("#{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.new("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 naught-1.1.0/lib/naught/basic_object.rb0000644000004100000410000000072112604541220020013 0ustar www-datawww-datamodule 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 naught-1.1.0/lib/naught/version.rb0000644000004100000410000000004612604541220017071 0ustar www-datawww-datamodule Naught VERSION = '1.1.0' end naught-1.1.0/lib/naught/null_class_builder/0000755000004100000410000000000012604541220020724 5ustar www-datawww-datanaught-1.1.0/lib/naught/null_class_builder/commands/0000755000004100000410000000000012604541220022525 5ustar www-datawww-datanaught-1.1.0/lib/naught/null_class_builder/commands/singleton.rb0000644000004100000410000000116212604541220025054 0ustar www-datawww-datarequire 'naught/null_class_builder/command' module Naught class NullClassBuilder module 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 end end naught-1.1.0/lib/naught/null_class_builder/commands/impersonate.rb0000644000004100000410000000045712604541220025406 0ustar www-datawww-datamodule Naught class NullClassBuilder module Commands class Impersonate < Naught::NullClassBuilder::Commands::Mimic def initialize(builder, class_to_impersonate, options = {}) super builder.base_class = class_to_impersonate end end end end end naught-1.1.0/lib/naught/null_class_builder/commands/predicates_return.rb0000644000004100000410000000264112604541220026577 0ustar www-datawww-datarequire 'naught/null_class_builder/command' module Naught class NullClassBuilder module 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| next unless 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 def define_predicate_methods(subject) subject.module_exec(@predicate_return_value) do |return_value| instance_methods.each do |method_name| next unless method_name.to_s.end_with?('?') define_method(method_name) do |*| return_value end end end end end end end end naught-1.1.0/lib/naught/null_class_builder/commands/define_explicit_conversions.rb0000644000004100000410000000072512604541220030641 0ustar www-datawww-datarequire 'forwardable' require 'naught/null_class_builder/command' module Naught class NullClassBuilder module 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 end end naught-1.1.0/lib/naught/null_class_builder/commands/traceable.rb0000644000004100000410000000125012604541220024772 0ustar www-datawww-datarequire 'naught/null_class_builder/command' module Naught class NullClassBuilder module 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 end end naught-1.1.0/lib/naught/null_class_builder/commands/pebble.rb0000644000004100000410000000173212604541220024306 0ustar www-datawww-datarequire '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| pretty_args = args.collect(&:inspect).join(', ').tr("\"", "'") 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 naught-1.1.0/lib/naught/null_class_builder/commands/mimic.rb0000644000004100000410000000332312604541220024151 0ustar www-datawww-datarequire 'naught/basic_object' require 'naught/null_class_builder/command' module Naught class NullClassBuilder module Commands class Mimic < Naught::NullClassBuilder::Command NULL_SINGLETON_CLASS = (class << Object.new; self; end) attr_reader :class_to_mimic, :include_super, :singleton_class def initialize(builder, class_to_mimic_or_options, options = {}) super(builder) if class_to_mimic_or_options.is_a?(Hash) options = class_to_mimic_or_options.merge(options) instance = options.fetch(:example) @singleton_class = (class << instance; self; end) @class_to_mimic = instance.class else @singleton_class = NULL_SINGLETON_CLASS @class_to_mimic = class_to_mimic_or_options end @include_super = options.fetch(:include_super) { true } builder.base_class = root_class_of(@class_to_mimic) class_to_mimic = @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 methods_to_mimic = class_to_mimic.instance_methods(include_super) | singleton_class.instance_methods(false) methods_to_mimic - Object.instance_methods end end end end end naught-1.1.0/lib/naught/null_class_builder/commands/define_implicit_conversions.rb0000644000004100000410000000110612604541220030624 0ustar www-datawww-datarequire 'naught/null_class_builder/command' module Naught class NullClassBuilder module Commands class DefineImplicitConversions < ::Naught::NullClassBuilder::Command def call defer do |subject| subject.module_eval do def to_ary [] end def to_hash {} end def to_int 0 end def to_str '' end end end end end end end end naught-1.1.0/lib/naught/null_class_builder/command.rb0000644000004100000410000000057012604541220022671 0ustar www-datawww-datamodule Naught class NullClassBuilder class Command attr_reader :builder def initialize(builder) @builder = builder end def call fail(NotImplementedError.new('Method #call should be overriden in child classes')) end def defer(options = {}, &block) @builder.defer(options, &block) end end end end naught-1.1.0/lib/naught/null_class_builder/commands.rb0000644000004100000410000000073712604541220023061 0ustar www-datawww-datarequire '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' naught-1.1.0/lib/naught.rb0000644000004100000410000000046112604541220015405 0ustar www-datawww-datarequire '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 naught-1.1.0/README.markdown0000644000004100000410000003013112604541220015522 0ustar www-datawww-data[![Gem Version](https://badge.fury.io/rb/naught.svg)][gem] [![Build Status](https://travis-ci.org/avdi/naught.svg?branch=master)][travis] [![Dependency Status](https://gemnasium.com/avdi/naught.svg)][gemnasium] [![Code Climate](https://codeclimate.com/github/avdi/naught/badges/gpa.svg)][codeclimate] [![Coverage Status](https://coveralls.io/repos/avdi/naught/badge.svg?branch=master&service=github)][coveralls] [![Inline docs](http://inch-ci.org/github/avdi/naught.svg?branch=master)][docs] [gem]: https://rubygems.org/gems/naught [travis]: https://travis-ci.org/avdi/naught [gemnasium]: https://gemnasium.com/avdi/naught [codeclimate]: https://codeclimate.com/github/avdi/naught [coveralls]: https://coveralls.io/github/avdi/naught?branch=master [docs]: http://inch-ci.org/github/avdi/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! ``` #### My objects are unique and special snowflakes, with new methods added to them at runtime. How are you gonna mimic *that*, hotshot? So long as you can create an object to serve as an example, Naught can copy the interface of that object (both the methods defined by its class, and its singleton methods). ```ruby require "naught" require "logging" log = Logging.logger["test"] log.info NullLog = Naught.build do |config| config.mimic example: log end null_log = NullLog.new null_log.info # => nil ``` #### 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 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) The Book -------- If you've read this far, you might be interested in the short ebook, [*Much Ado About Naught*](https://shiprise.dpdcart.com/cart/add?product_id=64334&method_id=66165), I (Avdi) wrote as I developed this library. It's a fun exploration of Ruby metaprogramming techniques as applied to writing a Ruby gem. You can [read the introduction here](http://devblog.avdi.org/introduction-to-much-ado-about-naught/). 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 Libraries Using Naught ----------------------- - [ActiveNull](https://github.com/Originate/active_null) Null Model support for ActiveRecord. - [Twitter](https://github.com/sferik/twitter) A Ruby interface to the Twitter API. naught-1.1.0/.rubocop.yml0000644000004100000410000000201412604541220015272 0ustar www-datawww-dataLint/NestedMethodDefinition: Enabled: false Metrics/BlockNesting: Max: 2 Metrics/LineLength: AllowURI: true Max: 93 # TODO: Lower to 80 Metrics/MethodLength: CountComments: false Max: 21 # TODO: Lower to 15 Metrics/ParameterLists: Max: 4 CountKeywordArgs: true Style/AccessModifierIndentation: EnforcedStyle: outdent Style/ClassVars: Enabled: false Style/CollectionMethods: Enabled: true PreferredMethods: map: 'collect' map!: 'collect!' reduce: 'inject' find: 'detect' find_all: 'select' Style/Documentation: Enabled: false Style/DotPosition: EnforcedStyle: trailing Style/DoubleNegation: Enabled: false Style/EachWithObject: Enabled: false Style/Encoding: Enabled: false Style/HashSyntax: EnforcedStyle: hash_rockets Style/Lambda: Enabled: false Style/MethodName: Enabled: false Style/RaiseArgs: EnforcedStyle: compact Style/SpaceInsideHashLiteralBraces: EnforcedStyle: no_space Style/TrailingComma: EnforcedStyleForMultiline: 'comma' naught-1.1.0/metadata.yml0000644000004100000410000000652512604541220015336 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: naught version: !ruby/object:Gem::Version version: 1.1.0 platform: ruby authors: - Avdi Grimm autorequire: bindir: bin cert_chain: [] date: 2015-09-08 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.4.5.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 naught-1.1.0/.gitignore0000644000004100000410000000031712604541220015014 0ustar www-datawww-data*.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 naught-1.1.0/naught.gemspec0000644000004100000410000000146612604541220015665 0ustar www-datawww-data# 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 = '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(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ['lib'] spec.add_development_dependency 'bundler', '~> 1.3' end naught-1.1.0/Guardfile0000644000004100000410000000063412604541220014653 0ustar www-datawww-dataguard '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(%r{^(lib|spec/support)/.*\.rb$}) watch('Gemfile.lock') end