From ccd4d284a92f064a8f9e4567c8143141589f2271 Mon Sep 17 00:00:00 2001 From: Kirill Leonov Date: Fri, 2 Aug 2024 19:48:51 +0300 Subject: [PATCH] mvp --- .rubocop.yml | 1 + Gemfile | 1 + Gemfile.lock | 5 ++++- Rakefile | 1 + lib/simple_monads.rb | 11 +++++++++++ lib/simple_monads/failure_object.rb | 24 ++++++++++++++++++++++++ lib/simple_monads/success_object.rb | 24 ++++++++++++++++++++++++ lib/simple_monads/version.rb | 2 +- 8 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 lib/simple_monads/failure_object.rb create mode 100644 lib/simple_monads/success_object.rb diff --git a/.rubocop.yml b/.rubocop.yml index 5bccfe2..ce3587f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,6 @@ require: - rubocop-minitest + - rubocop-rake AllCops: NewCops: enable diff --git a/Gemfile b/Gemfile index 059f3b1..57c073e 100644 --- a/Gemfile +++ b/Gemfile @@ -11,4 +11,5 @@ group :development do gem 'rake' gem 'rubocop' gem 'rubocop-minitest' + gem 'rubocop-rake' end diff --git a/Gemfile.lock b/Gemfile.lock index 7a9c3bc..7d5e0c5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - simple_monads (0.1.1) + simple_monads (0.1.2) GEM remote: https://rubygems.org/ @@ -44,6 +44,8 @@ GEM rubocop-minitest (0.35.1) rubocop (>= 1.61, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) ruby-progressbar (1.13.0) strscan (3.1.0) unicode-display_width (2.5.0) @@ -59,6 +61,7 @@ DEPENDENCIES rake rubocop rubocop-minitest + rubocop-rake simple_monads! BUNDLED WITH diff --git a/Rakefile b/Rakefile index f56f424..5787b9c 100644 --- a/Rakefile +++ b/Rakefile @@ -9,6 +9,7 @@ Rake::TestTask.new(:test) do |t| t.test_files = FileList['test/**/*_test.rb'] end +desc 'build and push gem versions' task :build_and_push do puts "build simple_monads #{SimpleMonads::VERSION}" system 'gem build simple_monads.gemspec' diff --git a/lib/simple_monads.rb b/lib/simple_monads.rb index 297dac7..2e8dc6c 100644 --- a/lib/simple_monads.rb +++ b/lib/simple_monads.rb @@ -1,4 +1,15 @@ # frozen_string_literal: true +require_relative 'simple_monads/failure_object' +require_relative 'simple_monads/success_object' + +# Main module module SimpleMonads + def Success(object) # rubocop:disable Naming/MethodName + SuccessObject.new(object) + end + + def Failure(object) # rubocop:disable Naming/MethodName + FailureObject.new(object) + end end diff --git a/lib/simple_monads/failure_object.rb b/lib/simple_monads/failure_object.rb new file mode 100644 index 0000000..5fdd4a1 --- /dev/null +++ b/lib/simple_monads/failure_object.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module SimpleMonads + # failure object + class FailureObject + attr_reader :object + + def initialize(object) + @object = object + end + + def failure? + true + end + + def success? + false + end + + def inspect + "Failure(#{object})" + end + end +end diff --git a/lib/simple_monads/success_object.rb b/lib/simple_monads/success_object.rb new file mode 100644 index 0000000..9baa4ad --- /dev/null +++ b/lib/simple_monads/success_object.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module SimpleMonads + # success object + class SuccessObject + attr_reader :object + + def initialize(object) + @object = object + end + + def failure? + false + end + + def success? + true + end + + def inspect + "Success(#{object})" + end + end +end diff --git a/lib/simple_monads/version.rb b/lib/simple_monads/version.rb index 069c547..a83ff1d 100644 --- a/lib/simple_monads/version.rb +++ b/lib/simple_monads/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module SimpleMonads - VERSION = '0.1.1' + VERSION = '0.1.2' end