oop 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/oop/basic_rules.rb +27 -0
- data/lib/oop/boundary.rb +14 -0
- data/lib/oop/cell.rb +30 -0
- data/lib/oop/non_value_arg.rb +3 -0
- data/lib/oop/tools.rb +40 -0
- data/lib/oop/value.rb +40 -0
- data/lib/oop/version.rb +3 -0
- data/lib/oop.rb +8 -0
- data/oop.gemspec +25 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3225775b05aa111970dc21a74a86577503d7f5ad
|
4
|
+
data.tar.gz: 13bce5cb42f43e4598b240b3798f9cc93ca6eab0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 89e8905c92395d905104d3f9be9f38c635d82316671a02f73d5f15d18f6335fdcdd8dc9280f99f8804b8c61d0fc29b9869994b86f93cef5663128c98f70b83aa
|
7
|
+
data.tar.gz: 380e739b0801dd31e9d76e14c8d930f166e7731475f11454e29a86d06d88403fda52f758fad4a9e91630b9e9799779e2e8bb2e77af6836c2f8df74d0b4185edb
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Serguei Filimonov
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# OOP
|
2
|
+
|
3
|
+
My take on how to write simpler Ruby code.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'oop'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install oop
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Documentation is missing right now. But the code is very short (< 200 lines).
|
24
|
+
Subclass either of `OOP::Value`, `OOP::Cell`, `OOP::Boundary` and your class will benefit from from the OOP messaging firewall IF:
|
25
|
+
|
26
|
+
1. You don't use `def` (use `message` method instead)
|
27
|
+
2. You don't use constants within that class (Constants in Ruby are anything that begins with a capital letter)
|
28
|
+
|
29
|
+
Exceptions:
|
30
|
+
1. if subclassing `OOP::Boundary`, it's ok to use constants
|
31
|
+
2. To use trusted values like `Math`, see `value_spec.rb` in this gem for an example
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sergueif/oop. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "oop"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'oop/non_value_arg'
|
2
|
+
|
3
|
+
module OOP
|
4
|
+
class BasicRules
|
5
|
+
def trusted_values
|
6
|
+
[]
|
7
|
+
end
|
8
|
+
def cast_to_value(arg)
|
9
|
+
case arg
|
10
|
+
when Value, TrueClass, FalseClass, NilClass, Proc then
|
11
|
+
arg
|
12
|
+
when Hash then
|
13
|
+
Hash[arg.map{|k,v| [cast_to_value(k), cast_to_value(v)] }.to_h].freeze
|
14
|
+
when Array then
|
15
|
+
arg.map{|v| cast_to_value(v) }.freeze
|
16
|
+
when Symbol, Fixnum, String, Float, Time then
|
17
|
+
if arg.frozen?
|
18
|
+
arg
|
19
|
+
else
|
20
|
+
arg.dup.freeze
|
21
|
+
end
|
22
|
+
else
|
23
|
+
raise NonValueArg.new(arg.class)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/oop/boundary.rb
ADDED
data/lib/oop/cell.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'oop/tools'
|
2
|
+
|
3
|
+
module OOP
|
4
|
+
class Cell
|
5
|
+
include Tools
|
6
|
+
|
7
|
+
def _rules
|
8
|
+
BasicRules.new
|
9
|
+
end
|
10
|
+
end
|
11
|
+
def Cell(*rules_and_name_to_klass)
|
12
|
+
rules, name_to_klass = if rules_and_name_to_klass.size > 1
|
13
|
+
rules_and_name_to_klass
|
14
|
+
else
|
15
|
+
[BasicRules, rules_and_name_to_klass.first]
|
16
|
+
end
|
17
|
+
|
18
|
+
c = Class.new(Cell)
|
19
|
+
c.class_exec do
|
20
|
+
define_method(:_rules) { rules.new }
|
21
|
+
end
|
22
|
+
name_to_klass.each do |name, klass|
|
23
|
+
c.class_exec do
|
24
|
+
define_method(name) { klass }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
c
|
28
|
+
end
|
29
|
+
module_function :Cell
|
30
|
+
end
|
data/lib/oop/tools.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module OOP
|
2
|
+
module Tools
|
3
|
+
module ClassMethods
|
4
|
+
def message(meth, &block)
|
5
|
+
define_method(meth) do |*args, &blk|
|
6
|
+
args = args.map do |arg|
|
7
|
+
_rules.cast_to_value(arg)
|
8
|
+
end
|
9
|
+
_rules.cast_to_value(self.instance_exec(*(args + [blk]), &block))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
def konstructor(*parts, &block)
|
13
|
+
parts = parts.first if parts.first.is_a?(Hash)
|
14
|
+
define_method(:initialize) do |opts|
|
15
|
+
if block
|
16
|
+
opts = block.call(opts) || raise("#{self} invalid with #{opts}")
|
17
|
+
end
|
18
|
+
|
19
|
+
@opts = {}
|
20
|
+
opts.each do |k, v|
|
21
|
+
if self.is_a? Value
|
22
|
+
@opts[_rules.cast_to_value(k)] = _rules.cast_to_value(v)
|
23
|
+
else
|
24
|
+
@opts[k] = v
|
25
|
+
end
|
26
|
+
end
|
27
|
+
@opts
|
28
|
+
end
|
29
|
+
parts.each do |part, defaultt|
|
30
|
+
define_method(part) do
|
31
|
+
@opts[part] ||= defaultt
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
def self.included(klass)
|
37
|
+
klass.extend(ClassMethods)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/oop/value.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'oop/tools'
|
2
|
+
require 'oop/basic_rules'
|
3
|
+
|
4
|
+
module OOP
|
5
|
+
class Value
|
6
|
+
include Tools
|
7
|
+
|
8
|
+
def ==(other)
|
9
|
+
@opts == other.instance_variable_get(:@opts)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def _rules
|
15
|
+
BasicRules.new
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def Value(*rules_and_name_to_klass)
|
20
|
+
rules, name_to_klass = if rules_and_name_to_klass.size > 1
|
21
|
+
rules_and_name_to_klass
|
22
|
+
else
|
23
|
+
[BasicRules, rules_and_name_to_klass.first]
|
24
|
+
end
|
25
|
+
c = Class.new(Value)
|
26
|
+
c.class_exec do
|
27
|
+
define_method(:_rules) { rules.new }
|
28
|
+
end
|
29
|
+
name_to_klass.each do |name, klass|
|
30
|
+
if !(klass.is_a?(Value) || klass.ancestors.include?(Value) || rules.new.trusted_values.include?(klass))
|
31
|
+
raise "imported non-value #{klass}"
|
32
|
+
end
|
33
|
+
c.class_exec do
|
34
|
+
define_method(name) { klass }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
c
|
38
|
+
end
|
39
|
+
module_function :Value
|
40
|
+
end
|
data/lib/oop/version.rb
ADDED
data/lib/oop.rb
ADDED
data/oop.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'oop/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "oop"
|
8
|
+
spec.version = OOP::VERSION
|
9
|
+
spec.authors = ["Serguei Filimonov"]
|
10
|
+
spec.email = ["serguei.filimonov@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{My take on how to write simpler Ruby code.}
|
13
|
+
spec.description = %q{half library / half discipline that polices messanging between objects}
|
14
|
+
spec.homepage = "https://github.com/sergueif/oop"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oop
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Serguei Filimonov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: half library / half discipline that polices messanging between objects
|
56
|
+
email:
|
57
|
+
- serguei.filimonov@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- lib/oop.rb
|
73
|
+
- lib/oop/basic_rules.rb
|
74
|
+
- lib/oop/boundary.rb
|
75
|
+
- lib/oop/cell.rb
|
76
|
+
- lib/oop/non_value_arg.rb
|
77
|
+
- lib/oop/tools.rb
|
78
|
+
- lib/oop/value.rb
|
79
|
+
- lib/oop/version.rb
|
80
|
+
- oop.gemspec
|
81
|
+
homepage: https://github.com/sergueif/oop
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.4.5.1
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: My take on how to write simpler Ruby code.
|
105
|
+
test_files: []
|