pseudo_object 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 90763d9ad331d2ba6fb3f64585444063ec1a1576
4
- data.tar.gz: fce9f859259c9a5fc7e33fe6178bb45471c914a5
3
+ metadata.gz: adcc177f010518912ca7fb4ff2b488111fa9c391
4
+ data.tar.gz: c4156b21915ba803504a04f882d4364991c2d01e
5
5
  SHA512:
6
- metadata.gz: c998035df3bf327b3559506d4b1ab6e47cd4f974c86cbc8036ee3756ebe6f83b0cfaeb6405ec984d9eb4f9a50a6623fd1e93f605b121ae35d8c6030297ef3b32
7
- data.tar.gz: e3ddd39b95e70dd79072d10363969dac3c9240b23d524a05b4160a781e976fe8cb71f6cdcc92236d4c245b344ea69016adea9ffc250704d4c419e8c081697af0
6
+ metadata.gz: 9d2e428546c69dd68a58c261d5904124b20a6f0d3b87b9bec951f20ba4e0fd980d96230762e8921634eaa7bebadf3738c39a17745a08f38713a1aeab296441c3
7
+ data.tar.gz: 58457babb8022ffe446503a0361c11e91d0e3a06f71f8ec78c68e9da58e64ea2323310864f070d3f8f55d13c738f117d4c56c570b846d01a7d689f1daf6c9b48
@@ -1,16 +1,29 @@
1
+ require_relative 'ext/definer/pseudo_method_list'
2
+
1
3
  module PseudoObject
2
4
  class BasicObject < ::BasicObject
3
5
  attr_reader \
4
6
  :pseudo_object
5
7
 
6
- PSEUDO_CLASS = ::BasicObject
7
- PSEUDO_INSTANCE_METHODS = %i/
8
- pseudo?
9
- pseudo_infection=
10
- pseudo_infection?
11
- pseudo_object
12
- pseudo_object=
13
- /
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
14
27
 
15
28
  # - - - - - - - - - - - - - - -
16
29
  # error
@@ -19,67 +32,65 @@ module PseudoObject
19
32
  def initialize(object)
20
33
  message = '%s is not a kind of %s class' % [
21
34
  object.class,
22
- PSEUDO_CLASS.name]
35
+ @@pseudo_model.name]
23
36
  super(message)
24
37
  end
25
38
  }
26
39
 
27
40
  # - - - - - - - - - - - - - - -
28
- # initialize
41
+ # override - initialize
29
42
 
30
- def initialize(
31
- object,
43
+ def initialize(**options)
44
+ self.pseudo_object = @@pseudo_model.new
45
+ pseudo_initialize_options(**options)
46
+ end
47
+
48
+ def pseudo_initialize_options(
32
49
  infection: true
33
50
  )
34
- self.pseudo_object = object
35
51
  self.pseudo_infection = infection
36
52
  end
53
+ private :pseudo_initialize_options
37
54
 
38
55
  # - - - - - - - - - - - - - - -
39
- # setter, bool
56
+ # pseudo original - set
40
57
 
41
- def pseudo?
42
- true
58
+ def pseudo_infection=(bool)
59
+ @pseudo_infection = !!bool
43
60
  end
44
61
 
45
62
  def pseudo_object=(other)
46
- validate_class(other)
63
+ validate_pseudo_class(other)
47
64
  @pseudo_object = other
48
65
  end
49
66
 
50
- def pseudo_infection?
51
- @pseudo_infection
67
+ # - - - - - - - - - - - - - - -
68
+ # pseudo original - get - bool
69
+
70
+ def pseudo?
71
+ true
52
72
  end
53
73
 
54
- def pseudo_infection=(bool)
55
- @pseudo_infection = !!bool
74
+ def pseudo_infection?
75
+ @pseudo_infection
56
76
  end
57
77
 
58
78
  # - - - - - - - - - - - - - - -
59
- # private - validate
60
-
61
- def method_missing(method_name, *args, &block)
62
- @pseudo_object.__send__(method_name, *args, &block)
63
- end
64
- private :method_missing
79
+ # pseudo original - private - validate
65
80
 
66
- def validate_class(object)
67
- unless object.kind_of?(PSEUDO_CLASS)
81
+ def validate_pseudo_class(object)
82
+ unless object.kind_of?(@@pseudo_model)
68
83
  fail TypeError.new(object)
69
84
  end
70
85
  end
71
- private :validate_class
86
+ private :validate_pseudo_class
72
87
 
73
88
  # - - - - - - - - - - - - - - -
74
- # pseudo - compare
89
+ # override - compare
75
90
 
76
91
  def ==(other)
77
- if other.kind_of?(PSEUDO_CLASS) \
78
- && other == @pseudo_object
79
- return true
80
- end
81
-
82
- false
92
+ __id__ == other.__id__ \
93
+ || @pseudo_object.__id__ == other.__id__
83
94
  end
84
95
 
85
96
  def !=(other)
@@ -87,10 +98,18 @@ module PseudoObject
87
98
  end
88
99
 
89
100
  # - - - - - - - - - - - - - - -
90
- # pseudo - other
101
+ # override - convert
91
102
 
92
103
  def !
93
104
  !@pseudo_object
94
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
95
114
  end
96
115
  end
@@ -0,0 +1,90 @@
1
+ module PseudoObject
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 PseudoObject.
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 PseudoObject
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
@@ -1,3 +1,3 @@
1
1
  module PseudoObject
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -22,4 +22,10 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "bundler", "~> 1.10"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "rspec"
25
+
26
+ spec.post_install_message = <<-MESSAGE
27
+ ! The 'PseudoObject' 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
25
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pseudo_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - indeep-xyz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-21 00:00:00.000000000 Z
11
+ date: 2016-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,13 +70,18 @@ files:
70
70
  - bin/setup
71
71
  - lib/pseudo_object.rb
72
72
  - lib/pseudo_object/model/basic_object.rb
73
+ - lib/pseudo_object/model/ext/definer/pseudo_method_list.rb
74
+ - lib/pseudo_object/model/object.rb
73
75
  - lib/pseudo_object/version.rb
74
76
  - pseudo_object.gemspec
75
77
  homepage: https://github.com/indeep-xyz/pseudo-object
76
78
  licenses:
77
79
  - MIT
78
80
  metadata: {}
79
- post_install_message:
81
+ post_install_message: |
82
+ ! The 'PseudoObject' 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
80
85
  rdoc_options: []
81
86
  require_paths:
82
87
  - lib