naught 0.0.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -0
  3. data/.rubocop.yml +74 -0
  4. data/.travis.yml +20 -2
  5. data/Changelog.md +8 -2
  6. data/Gemfile +24 -2
  7. data/README.markdown +30 -7
  8. data/Rakefile +11 -2
  9. data/lib/naught.rb +1 -1
  10. data/lib/naught/basic_object.rb +17 -0
  11. data/lib/naught/conversions.rb +55 -0
  12. data/lib/naught/null_class_builder.rb +33 -21
  13. data/lib/naught/null_class_builder/command.rb +3 -3
  14. data/lib/naught/null_class_builder/commands/define_explicit_conversions.rb +3 -7
  15. data/lib/naught/null_class_builder/commands/define_implicit_conversions.rb +7 -2
  16. data/lib/naught/null_class_builder/commands/impersonate.rb +2 -3
  17. data/lib/naught/null_class_builder/commands/mimic.rb +4 -7
  18. data/lib/naught/null_class_builder/commands/pebble.rb +3 -5
  19. data/lib/naught/null_class_builder/commands/predicates_return.rb +1 -2
  20. data/lib/naught/null_class_builder/commands/singleton.rb +1 -1
  21. data/lib/naught/null_class_builder/commands/traceable.rb +3 -2
  22. data/lib/naught/version.rb +1 -1
  23. data/naught.gemspec +11 -16
  24. data/spec/base_object_spec.rb +2 -2
  25. data/spec/basic_null_object_spec.rb +3 -3
  26. data/spec/blackhole_spec.rb +4 -4
  27. data/spec/explicit_conversions_spec.rb +23 -0
  28. data/spec/functions/actual_spec.rb +4 -4
  29. data/spec/functions/just_spec.rb +7 -7
  30. data/spec/functions/maybe_spec.rb +7 -7
  31. data/spec/functions/null_spec.rb +6 -6
  32. data/spec/implicit_conversions_spec.rb +5 -5
  33. data/spec/mimic_spec.rb +30 -35
  34. data/spec/naught/null_object_builder/command_spec.rb +1 -1
  35. data/spec/naught/null_object_builder_spec.rb +5 -5
  36. data/spec/naught_spec.rb +29 -23
  37. data/spec/pebble_spec.rb +13 -11
  38. data/spec/predicate_spec.rb +18 -14
  39. data/spec/singleton_null_object_spec.rb +4 -4
  40. data/spec/spec_helper.rb +4 -4
  41. data/spec/support/convertable_null.rb +2 -2
  42. data/spec/support/jruby.rb +3 -0
  43. data/spec/support/rubinius.rb +3 -0
  44. data/spec/support/ruby_18.rb +3 -0
  45. metadata +21 -82
  46. data/lib/naught/null_class_builder/conversions_module.rb +0 -57
  47. data/spec/conversions_spec.rb +0 -20
@@ -1,57 +0,0 @@
1
- module Naught
2
- class ConversionsModule < Module
3
- attr_reader :null_class
4
- attr_reader :null_equivs
5
-
6
- def initialize(null_class, null_equivs)
7
- @null_class = null_class
8
- @null_equivs = null_equivs
9
- mod = self
10
- super() do
11
- %w[Null Maybe Just Actual].each do |method_name|
12
- define_method(method_name, &mod.method(method_name))
13
- end
14
- end
15
- end
16
-
17
- def Null(object=:nothing_passed)
18
- case object
19
- when NullObjectTag then object
20
- when :nothing_passed, *null_equivs
21
- null_class.get(caller: caller(1))
22
- else raise ArgumentError, "#{object.inspect} is not null!"
23
- end
24
- end
25
-
26
- def Maybe(object=nil, &block)
27
- object = block ? block.call : object
28
- case object
29
- when NullObjectTag then object
30
- when *null_equivs
31
- null_class.get(caller: caller(1))
32
- else
33
- object
34
- end
35
- end
36
-
37
- def Just(object=nil, &block)
38
- object = block ? block.call : object
39
- case object
40
- when NullObjectTag, *null_equivs
41
- raise ArgumentError, "Null value: #{object.inspect}"
42
- else
43
- object
44
- end
45
- end
46
-
47
- def Actual(object=nil, &block)
48
- object = block ? block.call : object
49
- case object
50
- when NullObjectTag then nil
51
- else
52
- object
53
- end
54
- end
55
-
56
- end
57
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper.rb'
2
-
3
- describe 'explicitly convertable null object' do
4
- let(:null_class) {
5
- Naught.build do |b|
6
- b.define_explicit_conversions
7
- end
8
- }
9
- subject(:null) { null_class.new }
10
-
11
- it "defines common explicit conversions to return zero values" do
12
- expect(null.to_s).to eq("")
13
- expect(null.to_a).to eq([])
14
- expect(null.to_i).to eq(0)
15
- expect(null.to_f).to eq(0.0)
16
- expect(null.to_c).to eq(Complex(0))
17
- expect(null.to_r).to eq(Rational(0))
18
- expect(null.to_h).to eq({})
19
- end
20
- end