pseudoo 0.2.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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/pseudoo/model/basic_object.rb +115 -0
- data/lib/pseudoo/model/ext/definer/pseudo_method_list.rb +90 -0
- data/lib/pseudoo/model/object.rb +47 -0
- data/lib/pseudoo/version.rb +3 -0
- data/lib/pseudoo.rb +5 -0
- data/pseudoo.gemspec +31 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 128bba7b3d06084e0f1142e4d692857f0bf23dd1
|
4
|
+
data.tar.gz: 733e3aa0a70c0cd9443bca70f8a3100bfc45c878
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a3710a0c3fe11aa07f7f086a3885fe010ba7ecaa859b7cb61e7a2ed7aadcc009edd48e8610049db7a3e82cb1a6a6323acc760884170a76e40ef9b17d0eca758e
|
7
|
+
data.tar.gz: 9c5e5632a7d828f94d1fcdf56f6a4b7060d7dc8e24ea7127b9c43679bcbaa9e226379e2cbd90d3716f73a6521407fbdce1736a0d9784effe0737610249dea79d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 indeep-xyz
|
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,37 @@
|
|
1
|
+
Pseudoo
|
2
|
+
====
|
3
|
+
|
4
|
+
[](https://badge.fury.io/rb/pseudoo)
|
5
|
+
|
6
|
+
Installation
|
7
|
+
----
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'pseudoo'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install pseudoo
|
22
|
+
|
23
|
+
Usage
|
24
|
+
----
|
25
|
+
|
26
|
+
TODO: Write usage instructions here
|
27
|
+
|
28
|
+
Contributing
|
29
|
+
----
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/indeep-xyz/pseudoo.
|
32
|
+
|
33
|
+
|
34
|
+
License
|
35
|
+
----
|
36
|
+
|
37
|
+
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 "pseudoo"
|
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,115 @@
|
|
1
|
+
require_relative 'ext/definer/pseudo_method_list'
|
2
|
+
|
3
|
+
module Pseudoo
|
4
|
+
class BasicObject < ::BasicObject
|
5
|
+
attr_reader \
|
6
|
+
:pseudo_object
|
7
|
+
|
8
|
+
@@pseudo_substance = self
|
9
|
+
@@pseudo_model = ::BasicObject
|
10
|
+
|
11
|
+
class << self
|
12
|
+
ModelExt::Definer::PseudoMethodList.define_methods(self)
|
13
|
+
|
14
|
+
%w/
|
15
|
+
pseudo_substance
|
16
|
+
pseudo_model
|
17
|
+
/.each do |method_name|
|
18
|
+
define_method(method_name) do
|
19
|
+
class_variable_get(:"@@#{method_name}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def pseudo_superclass
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# - - - - - - - - - - - - - - -
|
29
|
+
# error
|
30
|
+
|
31
|
+
TypeError = ::Class.new(::TypeError) {
|
32
|
+
def initialize(object)
|
33
|
+
message = '%s is not a kind of %s class' % [
|
34
|
+
object.class,
|
35
|
+
@@pseudo_model.name]
|
36
|
+
super(message)
|
37
|
+
end
|
38
|
+
}
|
39
|
+
|
40
|
+
# - - - - - - - - - - - - - - -
|
41
|
+
# override - initialize
|
42
|
+
|
43
|
+
def initialize(**options)
|
44
|
+
self.pseudo_object = @@pseudo_model.new
|
45
|
+
pseudo_initialize_options(**options)
|
46
|
+
end
|
47
|
+
|
48
|
+
def pseudo_initialize_options(
|
49
|
+
infection: true
|
50
|
+
)
|
51
|
+
self.pseudo_infection = infection
|
52
|
+
end
|
53
|
+
private :pseudo_initialize_options
|
54
|
+
|
55
|
+
# - - - - - - - - - - - - - - -
|
56
|
+
# pseudo original - set
|
57
|
+
|
58
|
+
def pseudo_infection=(bool)
|
59
|
+
@pseudo_infection = !!bool
|
60
|
+
end
|
61
|
+
|
62
|
+
def pseudo_object=(other)
|
63
|
+
validate_pseudo_class(other)
|
64
|
+
@pseudo_object = other
|
65
|
+
end
|
66
|
+
|
67
|
+
# - - - - - - - - - - - - - - -
|
68
|
+
# pseudo original - get - bool
|
69
|
+
|
70
|
+
def pseudo?
|
71
|
+
true
|
72
|
+
end
|
73
|
+
|
74
|
+
def pseudo_infection?
|
75
|
+
@pseudo_infection
|
76
|
+
end
|
77
|
+
|
78
|
+
# - - - - - - - - - - - - - - -
|
79
|
+
# pseudo original - private - validate
|
80
|
+
|
81
|
+
def validate_pseudo_class(object)
|
82
|
+
unless object.kind_of?(@@pseudo_model)
|
83
|
+
fail TypeError.new(object)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
private :validate_pseudo_class
|
87
|
+
|
88
|
+
# - - - - - - - - - - - - - - -
|
89
|
+
# override - compare
|
90
|
+
|
91
|
+
def ==(other)
|
92
|
+
__id__ == other.__id__ \
|
93
|
+
|| @pseudo_object.__id__ == other.__id__
|
94
|
+
end
|
95
|
+
|
96
|
+
def !=(other)
|
97
|
+
!(self == other)
|
98
|
+
end
|
99
|
+
|
100
|
+
# - - - - - - - - - - - - - - -
|
101
|
+
# override - convert
|
102
|
+
|
103
|
+
def !
|
104
|
+
!@pseudo_object
|
105
|
+
end
|
106
|
+
|
107
|
+
# - - - - - - - - - - - - - - -
|
108
|
+
# override - private - other
|
109
|
+
|
110
|
+
def method_missing(method_name, *args, &block)
|
111
|
+
@pseudo_object.__send__(method_name, *args, &block)
|
112
|
+
end
|
113
|
+
private :method_missing
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module Pseudoo
|
2
|
+
module ModelExt
|
3
|
+
module Definer
|
4
|
+
class PseudoMethodList
|
5
|
+
|
6
|
+
METHOD_TYPES = %w/
|
7
|
+
instance_methods
|
8
|
+
methods
|
9
|
+
private_instance_methods
|
10
|
+
protected_instance_methods
|
11
|
+
public_instance_methods
|
12
|
+
/
|
13
|
+
|
14
|
+
class << self
|
15
|
+
def define_methods(cls)
|
16
|
+
instance = new(cls)
|
17
|
+
|
18
|
+
instance.define_pseudo_methods
|
19
|
+
instance.define_pseudized_methods
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(cls)
|
24
|
+
@class = cls
|
25
|
+
end
|
26
|
+
|
27
|
+
def define_pseudo_methods
|
28
|
+
METHOD_TYPES.each do |type|
|
29
|
+
define_pseudo_method(type)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def define_pseudized_methods
|
34
|
+
define_pseudized_method('instance_methods')
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
# - - - - - - - - - - - - - - - -
|
40
|
+
# Define
|
41
|
+
|
42
|
+
# Define the class method of "pseudized_*" series
|
43
|
+
#
|
44
|
+
# It returns an array including the names of methods
|
45
|
+
# overriding the model's.
|
46
|
+
#
|
47
|
+
# @m [String] method name of the method to list methods
|
48
|
+
def define_pseudized_method(m)
|
49
|
+
@class.class_eval <<-EOT
|
50
|
+
define_method('#{pseudized_method_name(m)}') do
|
51
|
+
collection = ancestors[0..-2].inject([]) do |result, cls|
|
52
|
+
result |= cls.#{m}
|
53
|
+
end & pseudo_model.#{m}
|
54
|
+
|
55
|
+
head_of_commons = collection.index(:instance_eval)
|
56
|
+
collection[0...head_of_commons]
|
57
|
+
end
|
58
|
+
EOT
|
59
|
+
end
|
60
|
+
|
61
|
+
# Define the class method of "pseudo_*" series
|
62
|
+
#
|
63
|
+
# It returns an array including the names of methods
|
64
|
+
# defined in Pseudoo.
|
65
|
+
#
|
66
|
+
# @m [String] method name of the method to list methods
|
67
|
+
def define_pseudo_method(m)
|
68
|
+
@class.class_eval <<-EOT
|
69
|
+
define_method('#{pseudo_method_name(m)}') do
|
70
|
+
ancestors[0..-2].inject([]) do |result, cls|
|
71
|
+
result |= cls.#{m}
|
72
|
+
end - pseudo_model.#{m}
|
73
|
+
end
|
74
|
+
EOT
|
75
|
+
end
|
76
|
+
|
77
|
+
# - - - - - - - - - - - - - - - -
|
78
|
+
# Parts
|
79
|
+
|
80
|
+
def pseudized_method_name(method_name)
|
81
|
+
'pseudized_%s' % method_name
|
82
|
+
end
|
83
|
+
|
84
|
+
def pseudo_method_name(method_name)
|
85
|
+
'pseudo_%s' % method_name
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative 'basic_object'
|
2
|
+
|
3
|
+
module Pseudoo
|
4
|
+
class Object < BasicObject
|
5
|
+
@@pseudo_substance = self
|
6
|
+
@@pseudo_model = ::Object
|
7
|
+
|
8
|
+
class << self
|
9
|
+
end
|
10
|
+
|
11
|
+
# - - - - - - - - - - - - - - -
|
12
|
+
# pseudo original - compare
|
13
|
+
|
14
|
+
def pseudo_kind_of?(klass)
|
15
|
+
@@pseudo_substance.ancestors.include?(klass) \
|
16
|
+
|| @@pseudo_model.ancestors.include?(klass)
|
17
|
+
end
|
18
|
+
alias_method :pseudo_is_a?, :pseudo_kind_of?
|
19
|
+
|
20
|
+
def pseudo_instance_of?(klass)
|
21
|
+
@@pseudo_substance == klass \
|
22
|
+
|| @@pseudo_model == klass
|
23
|
+
end
|
24
|
+
|
25
|
+
# - - - - - - - - - - - - - - -
|
26
|
+
# override - compare
|
27
|
+
|
28
|
+
def kind_of?(klass)
|
29
|
+
pseudo_kind_of?(klass) \
|
30
|
+
|| @pseudo_object.__send__(:kind_of?, *[klass])
|
31
|
+
end
|
32
|
+
alias_method :is_a?, :kind_of?
|
33
|
+
|
34
|
+
def instance_of?(klass)
|
35
|
+
pseudo_instance_of?(klass) \
|
36
|
+
|| @pseudo_object.__send__(:instance_of?, *[klass])
|
37
|
+
end
|
38
|
+
alias_method :===, :instance_of?
|
39
|
+
|
40
|
+
# - - - - - - - - - - - - - - -
|
41
|
+
# override - get
|
42
|
+
|
43
|
+
def class
|
44
|
+
@@pseudo_model
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/pseudoo.rb
ADDED
data/pseudoo.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pseudoo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pseudoo"
|
8
|
+
spec.version = Pseudoo::VERSION
|
9
|
+
spec.authors = ["indeep-xyz"]
|
10
|
+
spec.email = ["indeep.xyz@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Pseudo class objects of standard library in Ruby.}
|
13
|
+
spec.description = %q{Pseudo class objects of standard library in Ruby.}
|
14
|
+
spec.homepage = "https://github.com/indeep-xyz/pseudoo"
|
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
|
+
|
26
|
+
spec.post_install_message = <<-MESSAGE
|
27
|
+
! The 'Pseudoo' gem has been deprecated and has been replaced by 'Pseudoo'.
|
28
|
+
! See: https://rubygems.org/gems/pseudoo
|
29
|
+
! And: https://github.com/indeep-xyz/pseudoo
|
30
|
+
MESSAGE
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pseudoo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- indeep-xyz
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-06 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: Pseudo class objects of standard library in Ruby.
|
56
|
+
email:
|
57
|
+
- indeep.xyz@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- lib/pseudoo.rb
|
72
|
+
- lib/pseudoo/model/basic_object.rb
|
73
|
+
- lib/pseudoo/model/ext/definer/pseudo_method_list.rb
|
74
|
+
- lib/pseudoo/model/object.rb
|
75
|
+
- lib/pseudoo/version.rb
|
76
|
+
- pseudoo.gemspec
|
77
|
+
homepage: https://github.com/indeep-xyz/pseudoo
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message: |
|
82
|
+
! The 'Pseudoo' gem has been deprecated and has been replaced by 'Pseudoo'.
|
83
|
+
! See: https://rubygems.org/gems/pseudoo
|
84
|
+
! And: https://github.com/indeep-xyz/pseudoo
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.4.5.1
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Pseudo class objects of standard library in Ruby.
|
104
|
+
test_files: []
|