moguro 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 20d8318dd46d4570fc9c5d140c68fa087145eb8c
4
+ data.tar.gz: 3a293294e954957648dce4d8114424f7a3e9a2bd
5
+ SHA512:
6
+ metadata.gz: ac3bf6f2383a37457493cc566549f5f7c6fd5e98f0ede5f73fc9f40ee0a6c72f0b82369d7a222bd216be5578ded7b5813bc7796750d6337128e7a02a33408a15
7
+ data.tar.gz: 7a627bee4dba295c125602b206d6b5a6b75b543781f64a21221a774ebb8cf3b12141f39fff661cf7faefaa2fb8eeeec1c124c3334dca3442a7aeb5a071f413ca
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor/
10
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,48 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ Exclude:
4
+ - 'vendor/**/*'
5
+ - 'test/fixtures/**/*'
6
+ - 'tmp/**/*'
7
+
8
+ Metrics/BlockLength:
9
+ Enabled: false
10
+
11
+ Metrics/ModuleLength:
12
+ Enabled: false
13
+
14
+ Metrics/ClassLength:
15
+ Enabled: false
16
+
17
+ Metrics/MethodLength:
18
+ Max: 50
19
+
20
+ Metrics/LineLength:
21
+ Max: 150
22
+
23
+ Metrics/AbcSize:
24
+ Exclude:
25
+ - 'test/**/*'
26
+
27
+ Style/CaseEquality:
28
+ Exclude:
29
+ - 'test/**/*'
30
+
31
+ Style/AsciiComments:
32
+ Enabled: false
33
+
34
+ Style/Lambda:
35
+ Enabled: false
36
+
37
+ Naming/ConstantName:
38
+ Enabled: false
39
+
40
+ Naming/UncommunicativeMethodParamName:
41
+ Exclude:
42
+ - 'test/**/*'
43
+
44
+ Lint/Void:
45
+ Exclude:
46
+ - 'test/**/*'
47
+
48
+
@@ -0,0 +1,9 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.7
5
+ - 2.4.2
6
+ - 2.5
7
+ before_install: gem install bundler -v 1.16.1
8
+ env:
9
+ - CI=true
@@ -0,0 +1 @@
1
+ --markup markdown --title "numeja Documentation" --protected
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at TODO: Write your email address. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in moguro.gemspec
8
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,91 @@
1
+ # Moguro [![Gem Version](https://badge.fury.io/rb/moguro.svg)](https://badge.fury.io/rb/moguro) [![Build Status](https://travis-ci.org/rike422/moguro.svg?branch=master)](https://travis-ci.org/rike422/moguro) [![Code Climate](https://codeclimate.com/github/rike422/moguro/badges/gpa.svg)](https://codeclimate.com/github/rike422/moguro) [![Coverage Status](https://coveralls.io/repos/github/rike422/moguro/badge.svg?branch=master)](https://coveralls.io/github/rike422/moguro?branch=master)
2
+
3
+
4
+ Decorator style assertions and type check library for Contract programming
5
+
6
+ This gem is still in development and it isnt available to production.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'moguro'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install moguro
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ require 'moguro'
28
+
29
+ class MockClass
30
+ include Moguro::Decorator
31
+
32
+ # Must match argument names of decorate method
33
+ pre_c ->(a: Integer, b: String) {
34
+ assert_equal(a, 1)
35
+ assert_equal(b, 'b')
36
+ }
37
+
38
+ def puts_method(a, b)
39
+ puts b
40
+ a + 1
41
+ end
42
+
43
+ # Return values are auto assigned in order
44
+ post_c -> (first: String) {
45
+ p first
46
+ }
47
+ def post_contract_violation_method
48
+ 1
49
+ end
50
+
51
+ end
52
+
53
+ c = MockClass.new
54
+ c.puts_method(1, 'b')
55
+ # 1
56
+ # => 2
57
+
58
+ begin
59
+ c.puts_method('a', 1)
60
+ rescue => e
61
+ p e
62
+ end
63
+ # =>
64
+ # Type MissMatch: a is expected (Integer) actual a(String) (Moguro::Errors::ArgumentsTypeMismatchError)
65
+ # Expected: [a: (Integer), b: (String)]
66
+ # Actual: [a: a(String), b: 1(Integer)]
67
+ # Value guarded in: MockClass::puts_method
68
+ # At: #{source_location}
69
+
70
+ begin
71
+ c.post_contract_violation_method
72
+ rescue => e
73
+ p e
74
+ end
75
+
76
+ # =>
77
+ # Type MissMatch: first is expected (String) actual 1(Integer)
78
+ # Expected: [first: (String)]
79
+ # Actual: [first: 1(Integer)]
80
+ # Value guarded in: MockClass::post_contract_violation_method
81
+ # At: #{source_location}
82
+
83
+ ```
84
+
85
+ ## License
86
+
87
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
88
+
89
+ ## Code of Conduct
90
+
91
+ Everyone interacting in the Moguro project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/moguro/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,64 @@
1
+ require 'moguro'
2
+
3
+ class MockClass
4
+ include Moguro::Decorator
5
+ pre_c ->(a: Integer, b: String) {
6
+ assert_equal(b, 'b')
7
+ }
8
+
9
+ # auto assign return value
10
+ post_c -> (first: Integer) {
11
+ p first
12
+ assert_equal(first, 2)
13
+ }
14
+
15
+ def puts_method(a, b)
16
+ puts b
17
+ a + 1
18
+ end
19
+
20
+ post_c -> (first: String) {
21
+ p first
22
+ }
23
+ def post_contract_violation_method
24
+ 1
25
+ end
26
+ end
27
+
28
+ c = MockClass.new
29
+
30
+ c.puts_method(1, 'b')
31
+ # => 1
32
+ # => b
33
+
34
+ begin
35
+ c.puts_method('a', 1)
36
+ rescue => e
37
+ p e
38
+ end
39
+
40
+ # =>
41
+ # ArgumentsTypeError => Type MissMatch: a is expected (Integer) actual a(String) (Moguro::Errors::ArgumentsTypeMismatchError)
42
+ # Expected: [a: (Integer), b: (String)]
43
+ # Actual: [a: a(String), b: 1(Integer)]
44
+ # Value guarded in: MockClass::puts_method
45
+ # At: #{source_location}
46
+
47
+ begin
48
+ c.puts_method(1, 'b')
49
+ rescue => e
50
+ p e
51
+ end
52
+
53
+
54
+ begin
55
+ c.post_contract_violation_method
56
+ rescue => e
57
+ p e
58
+ end
59
+
60
+ begin
61
+ c.puts_method(2, 'b')
62
+ rescue => e
63
+ p e
64
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'moguro/version'
4
+ require 'parser/current'
5
+ require 'method_source'
6
+ require 'delegate'
7
+
8
+ # 'Easy' contract programming library for ruby
9
+ # @since 0.0.1
10
+ module Moguro
11
+ class << self
12
+ attr_writer :enabled
13
+
14
+ def enabled=(bool)
15
+ @enabled = bool
16
+ end
17
+
18
+ def enabled?
19
+ @enabled ||= true
20
+ end
21
+ end
22
+ end
23
+
24
+ require 'moguro/values'
25
+ require 'moguro/errors'
26
+ require 'moguro/types'
27
+ require 'moguro/extractor'
28
+ require 'moguro/method_reference'
29
+ require 'moguro/caluse'
30
+ require 'moguro/contract'
31
+ require 'moguro/handler'
32
+ require 'moguro/decorator'
33
+ require 'moguro/processros'
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Moguro
4
+ class DataTypeClause
5
+ attr_reader :key
6
+
7
+ def initialize(key)
8
+ @types = []
9
+ @key = key
10
+ end
11
+
12
+ def add_type(type)
13
+ @types << type
14
+ end
15
+
16
+ def pop_type
17
+ @types.pop
18
+ end
19
+
20
+ def types
21
+ if @types.empty?
22
+ [Moguro::Types::Any.new]
23
+ else
24
+ @types
25
+ end
26
+ end
27
+
28
+ def type_inspect
29
+ klasses = types.map(&:type)
30
+ "(#{klasses.join('|')})"
31
+ end
32
+
33
+ def inspect
34
+ "#{key}: #{type_inspect}"
35
+ end
36
+
37
+ def verify!(val)
38
+ return if types.empty?
39
+ raise Moguro::Errors::TypeMismatchError.new(self, val) if types.none? { |c| c.valid?(val) }
40
+ end
41
+ end
42
+
43
+ class Clauses < DelegateClass(Array)
44
+ ###
45
+ # @private
46
+ ###
47
+ def initialize
48
+ super([])
49
+ end
50
+
51
+ def add_verified_argument(argument_key)
52
+ self << DataTypeClause.new(argument_key)
53
+ end
54
+
55
+ ###
56
+ # Validation arguments
57
+ # @param args Moguro::ArgumentsExtractor::Values
58
+ ###
59
+ def verify!(args)
60
+ verify_arguments!(args)
61
+ end
62
+
63
+ def inspect
64
+ map(&:inspect)
65
+ end
66
+
67
+ private
68
+
69
+ def verify_arguments!(args)
70
+ verify_arguments_length!(args)
71
+ verify_arguments_types!(args)
72
+ end
73
+
74
+ def verify_arguments_length!(args)
75
+ missing_keys = args.select(&:missing?).map(&:key)
76
+ raise Moguro::Errors::ArgumentError, "Missing required parameters at ##{@name}: #{missing_keys.join(', ')}" if missing_keys.any?
77
+ end
78
+
79
+ def verify_arguments_types!(args)
80
+ each do |clause|
81
+ args_i = args.index { |a| a.key == clause.key }
82
+ clause.verify!(args[args_i])
83
+ end
84
+ rescue Moguro::Errors::TypeMismatchError => e
85
+ e.actual = args
86
+ e.expected = self
87
+ raise e
88
+ end
89
+ end
90
+ end