striuct 0.3.0 → 0.3.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.
- data/.gitignore +32 -0
- data/.travis.yml +6 -0
- data/Gemfile +12 -0
- data/History.rdoc +5 -0
- data/Manifest.txt +53 -25
- data/README.md +97 -0
- data/Rakefile +7 -21
- data/examples/README.rb +25 -0
- data/{example → examples}/example1.rb +1 -1
- data/{example → examples}/example2.rb +1 -1
- data/{example → examples}/see_trace.rb +4 -0
- data/lib/striuct/{containable/eigen → classmethods}/basic.rb +13 -5
- data/lib/striuct/classmethods/constants.rb +23 -0
- data/lib/striuct/{containable/eigen → classmethods}/constructor.rb +20 -14
- data/lib/striuct/{containable/eigen → classmethods}/handy.rb +19 -20
- data/lib/striuct/{containable/eigen → classmethods}/inner.rb +10 -32
- data/lib/striuct/{containable/eigen → classmethods}/macro.rb +37 -7
- data/lib/striuct/classmethods/requiremnets.rb +7 -0
- data/lib/striuct/{containable/eigen → classmethods}/safety.rb +6 -6
- data/lib/striuct/classmethods.rb +1 -0
- data/lib/striuct/{containable → instancemethods}/basic.rb +6 -6
- data/lib/striuct/{containable → instancemethods}/handy.rb +3 -3
- data/lib/striuct/{containable → instancemethods}/hashlike.rb +12 -6
- data/lib/striuct/{containable → instancemethods}/inner.rb +9 -8
- data/lib/striuct/instancemethods/requirements.rb +6 -0
- data/lib/striuct/{containable → instancemethods}/safety.rb +2 -2
- data/lib/striuct/instancemethods/singleton_class.rb +19 -0
- data/lib/striuct/instancemethods.rb +1 -0
- data/lib/striuct/requirements.rb +6 -0
- data/lib/striuct/singleton_class.rb +93 -0
- data/lib/striuct/specificcontainer.rb +17 -0
- data/lib/striuct/structs.rb +7 -0
- data/lib/striuct/version.rb +3 -2
- data/lib/striuct.rb +4 -9
- data/striuct.gemspec +24 -0
- data/test/{test_helper.rb → helper.rb} +3 -0
- data/test/test_striuct.rb +23 -1409
- data/test/test_striuct_define.rb +19 -0
- data/test/test_striuct_subclass_adjuster.rb +95 -0
- data/test/test_striuct_subclass_alias_member.rb +54 -0
- data/test/test_striuct_subclass_assign.rb +30 -0
- data/test/test_striuct_subclass_classlock.rb +36 -0
- data/test/test_striuct_subclass_classmethods.rb +87 -0
- data/test/test_striuct_subclass_cloning.rb +36 -0
- data/test/test_striuct_subclass_default_value.rb +129 -0
- data/test/test_striuct_subclass_for_pairs.rb +13 -0
- data/test/test_striuct_subclass_freeze.rb +19 -0
- data/test/test_striuct_subclass_functional_condition.rb +51 -0
- data/test/test_striuct_subclass_getter_validation.rb +33 -0
- data/test/test_striuct_subclass_hashlike.rb +153 -0
- data/test/test_striuct_subclass_inference.rb +51 -0
- data/test/test_striuct_subclass_inheritable.rb +58 -0
- data/test/test_striuct_subclass_instance.rb +289 -0
- data/test/test_striuct_subclass_lock.rb +40 -0
- data/test/test_striuct_subclass_safetynaming.rb +72 -0
- data/test/test_striuct_subclass_specific_conditions.rb +247 -0
- data/test/test_striuct_subclass_to_struct.rb +25 -0
- data/test/test_striuct_version.rb +9 -0
- metadata +106 -68
- data/.gemtest +0 -0
- data/README.rdoc +0 -63
- data/example/example.rb +0 -17
- data/lib/striuct/abstract.rb +0 -74
- data/lib/striuct/containable/classutil.rb +0 -22
- data/lib/striuct/containable/eigen.rb +0 -29
- data/lib/striuct/containable.rb +0 -38
- /data/{example/benchmarks.rb → benchmarks/basics.rb} +0 -0
- /data/{example → examples}/example.old.rdoc +0 -0
data/.gitignore
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
coverage
|
6
|
+
coverage.data
|
7
|
+
InstalledFiles
|
8
|
+
lib/bundler/man
|
9
|
+
pkg
|
10
|
+
rdoc
|
11
|
+
spec/reports
|
12
|
+
test/tmp
|
13
|
+
test/version_tmp
|
14
|
+
tmp
|
15
|
+
|
16
|
+
# bundler
|
17
|
+
vendor/
|
18
|
+
|
19
|
+
# YARD artifacts
|
20
|
+
.yardoc
|
21
|
+
_yardoc
|
22
|
+
doc/
|
23
|
+
|
24
|
+
# tmp-old
|
25
|
+
.old
|
26
|
+
|
27
|
+
# editor
|
28
|
+
*~
|
29
|
+
.redcar
|
30
|
+
|
31
|
+
# other
|
32
|
+
*.lock
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/History.rdoc
CHANGED
data/Manifest.txt
CHANGED
@@ -1,31 +1,59 @@
|
|
1
|
+
README.md
|
2
|
+
README.ja.old.rdoc
|
3
|
+
LICENSE
|
1
4
|
History.rdoc
|
2
5
|
Manifest.txt
|
3
|
-
README.rdoc
|
4
|
-
README.ja.old.rdoc
|
5
6
|
Rakefile
|
6
|
-
|
7
|
+
Gemfile
|
8
|
+
striuct.gemspec
|
7
9
|
lib/striuct.rb
|
8
10
|
lib/striuct/version.rb
|
9
|
-
lib/striuct/
|
10
|
-
lib/striuct/
|
11
|
-
lib/striuct/
|
12
|
-
lib/striuct/
|
13
|
-
lib/striuct/
|
14
|
-
lib/striuct/
|
15
|
-
lib/striuct/
|
16
|
-
lib/striuct/
|
17
|
-
lib/striuct/
|
18
|
-
lib/striuct/
|
19
|
-
lib/striuct/
|
20
|
-
lib/striuct/
|
21
|
-
lib/striuct/
|
22
|
-
lib/striuct/
|
23
|
-
lib/striuct/
|
24
|
-
|
11
|
+
lib/striuct/specificcontainer.rb
|
12
|
+
lib/striuct/classmethods.rb
|
13
|
+
lib/striuct/classmethods/requirements.rb
|
14
|
+
lib/striuct/classmethods/constants.rb
|
15
|
+
lib/striuct/classmethods/basic.rb
|
16
|
+
lib/striuct/classmethods/constructor.rb
|
17
|
+
lib/striuct/classmethods/safety.rb
|
18
|
+
lib/striuct/classmethods/handy.rb
|
19
|
+
lib/striuct/classmethods/macro.rb
|
20
|
+
lib/striuct/classmethods/inner.rb
|
21
|
+
lib/striuct/instancemethods.rb
|
22
|
+
lib/striuct/instancemethods/requirements.rb
|
23
|
+
lib/striuct/instancemethods/singleton_class.rb
|
24
|
+
lib/striuct/instancemethods/basic.rb
|
25
|
+
lib/striuct/instancemethods/safety.rb
|
26
|
+
lib/striuct/instancemethods/handy.rb
|
27
|
+
lib/striuct/instancemethods/hashlike.rb
|
28
|
+
lib/striuct/instancemethods/inner.rb
|
29
|
+
lib/striuct/singleton_class.rb
|
30
|
+
test/helper.rb
|
25
31
|
test/test_striuct.rb
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
+
test/test_striuct_define.rb
|
33
|
+
test/test_striuct_subclass_adjuster
|
34
|
+
test/test_striuct_subclass_alias_member.rb
|
35
|
+
test/test_striuct_subclass_assign.rb
|
36
|
+
test/test_striuct_subclass_classlock.rb
|
37
|
+
test/test_striuct_subclass_classmethods.rb
|
38
|
+
test/test_striuct_subclass_cloning.rb
|
39
|
+
test_striuct_subclass_default_value.rb
|
40
|
+
test/test_striuct_subclass_for_pairs.rb
|
41
|
+
test/test_striuct_subclass_freeze.rb
|
42
|
+
test/test_striuct_subclass_functional_condition.rb
|
43
|
+
test/test_striuct_subclass_getter_validation.rb
|
44
|
+
test/test_striuct_subclass_hashlike.rb
|
45
|
+
test/test_striuct_subclass_inference.rb
|
46
|
+
test/test_striuct_subclass_inheritable.rb
|
47
|
+
test/test_striuct_subclass_instance.rb
|
48
|
+
test/test_striuct_subclass_lock.rb
|
49
|
+
test/test_striuct_subclass_safetynaming.rb
|
50
|
+
test/test_striuct_subclass_specific_conditions.rb
|
51
|
+
test/test_striuct_subclass_to_struct.rb
|
52
|
+
test/test_striuct_version.rb
|
53
|
+
examples/README.rb
|
54
|
+
examples/example1.rb
|
55
|
+
examples/example2.rb
|
56
|
+
examples/example.old.rdoc
|
57
|
+
examples/see_trace.rb
|
58
|
+
benchmarks/basics.rb
|
59
|
+
|
data/README.md
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
striuct
|
2
|
+
=======
|
3
|
+
|
4
|
+
[](http://travis-ci.org/kachick/striuct)
|
5
|
+
|
6
|
+
Description
|
7
|
+
-----------
|
8
|
+
|
9
|
+
Struct++
|
10
|
+
|
11
|
+
Features
|
12
|
+
--------
|
13
|
+
|
14
|
+
### Strict
|
15
|
+
|
16
|
+
* Base API looks like Struct
|
17
|
+
* Easy and Flexible Validations
|
18
|
+
* Prevent to conflict member names
|
19
|
+
|
20
|
+
### Useful
|
21
|
+
|
22
|
+
* Hook just before setters
|
23
|
+
* Default value
|
24
|
+
* Member aliasing
|
25
|
+
* Inheritable
|
26
|
+
|
27
|
+
### Onepoint
|
28
|
+
|
29
|
+
* Pure Ruby :)
|
30
|
+
|
31
|
+
Usage
|
32
|
+
-----
|
33
|
+
|
34
|
+
### Overview
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
require 'striuct'
|
38
|
+
|
39
|
+
class Person < Striuct
|
40
|
+
member :fullname, AND(String, /\A.+\z/) # Flexible Validation
|
41
|
+
alias_member :name, :fullname # Use other name
|
42
|
+
end
|
43
|
+
|
44
|
+
class User < Person # Inheritable
|
45
|
+
member :id, Integer, # Looks typed validation
|
46
|
+
default_proc: ->{User.next_id} # With default value
|
47
|
+
|
48
|
+
def self.next_id
|
49
|
+
@id ||= 0
|
50
|
+
@id += 1
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
john = User.new 'john'
|
55
|
+
john[:name] #=> 'john'
|
56
|
+
john.name = '' #=> Exception # Validate with setter
|
57
|
+
john.id #=> 1
|
58
|
+
ken = User[name: 'ken'] # Construct from hash
|
59
|
+
ken.id #=> 2
|
60
|
+
```
|
61
|
+
|
62
|
+
### More Examples
|
63
|
+
|
64
|
+
#### Basics
|
65
|
+
|
66
|
+
examples/*
|
67
|
+
|
68
|
+
Requirements
|
69
|
+
-------------
|
70
|
+
|
71
|
+
* Ruby 1.9.2 or later [MRI/YARV, Rubinius](http://travis-ci.org/#!/kachick/striuct)
|
72
|
+
* validation - 0.0.3
|
73
|
+
* keyvalidatable - 0.0.2
|
74
|
+
|
75
|
+
Install
|
76
|
+
-------
|
77
|
+
|
78
|
+
```shell
|
79
|
+
$ gem install striuct
|
80
|
+
```
|
81
|
+
|
82
|
+
Link
|
83
|
+
----
|
84
|
+
|
85
|
+
* [code](https://github.com/kachick/striuct)
|
86
|
+
* [issues](https://github.com/kachick/striuct/issues)
|
87
|
+
* [CI](http://travis-ci.org/#!/kachick/striuct)
|
88
|
+
* [gem](https://rubygems.org/gems/striuct)
|
89
|
+
* [gem+](http://metagem.info/gems/striuct)
|
90
|
+
|
91
|
+
License
|
92
|
+
--------
|
93
|
+
|
94
|
+
The MIT X License
|
95
|
+
Copyright (c) 2011 Kenichi Kamiya
|
96
|
+
See the file LICENSE for further details.
|
97
|
+
|
data/Rakefile
CHANGED
@@ -1,25 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'hoe'
|
4
|
-
require 'fileutils'
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'bundler/gem_tasks'
|
5
3
|
|
6
|
-
|
7
|
-
# Hoe.plugin :website
|
8
|
-
# Hoe.plugin :cucumberfeatures
|
4
|
+
require 'rake/testtask'
|
9
5
|
|
10
|
-
|
11
|
-
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
12
|
-
$hoe = Hoe.spec 'striuct' do
|
13
|
-
developer 'Kenichi Kamiya', 'kachick1+ruby@gmail.com'
|
14
|
-
self.rubyforge_name = self.name
|
15
|
-
require_ruby_version '>= 1.9.2'
|
16
|
-
dependency 'validation', '~> 0.0.3', :runtime
|
17
|
-
dependency 'yard', '~> 0.7.5', :development
|
18
|
-
end
|
6
|
+
task default: [:test]
|
19
7
|
|
20
|
-
|
21
|
-
|
8
|
+
Rake::TestTask.new do |tt|
|
9
|
+
tt.verbose = true
|
10
|
+
end
|
22
11
|
|
23
|
-
# TODO - want other tests/tasks run by default? Add them to the list
|
24
|
-
# remove_task :default
|
25
|
-
# task :default => [:spec, :features]
|
data/examples/README.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
$VERBOSE = true
|
2
|
+
|
3
|
+
require '../lib/striuct'
|
4
|
+
|
5
|
+
class Person < Striuct
|
6
|
+
member :fullname, AND(String, /\A.+\z/) # Flexible Validation
|
7
|
+
alias_member :name, :fullname # Use other name
|
8
|
+
end
|
9
|
+
|
10
|
+
class User < Person # Inheritable
|
11
|
+
member :id, Integer, # Looks typed validation
|
12
|
+
default_proc: ->{User.next_id} # With default value
|
13
|
+
|
14
|
+
def self.next_id
|
15
|
+
@id ||= 0
|
16
|
+
@id += 1
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
john = User.new 'john'
|
21
|
+
p john[:name] #=> 'john'
|
22
|
+
#~ p john.name = '' #=> error
|
23
|
+
p john.id #=> 1
|
24
|
+
ken = User[name: 'ken'] # Construct from hash
|
25
|
+
p ken.id #=> 2
|
@@ -77,7 +77,7 @@ end
|
|
77
77
|
|
78
78
|
# through "inference", and check under first passed object class
|
79
79
|
class FlexibleContainer < Striuct.new
|
80
|
-
member :anything,
|
80
|
+
member :anything, ANYTHING?, inference: true
|
81
81
|
member :number, Numeric, inference: true
|
82
82
|
end
|
83
83
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Striuct; module
|
1
|
+
class Striuct; module ClassMethods
|
2
2
|
# @group Basic
|
3
3
|
|
4
4
|
# @return [Array<Symbol>]
|
@@ -6,11 +6,17 @@ class Striuct; module Containable; module Eigen
|
|
6
6
|
@names.dup
|
7
7
|
end
|
8
8
|
|
9
|
+
alias_method :autonyms, :names
|
9
10
|
alias_method :members, :names
|
10
11
|
alias_method :keys, :names
|
12
|
+
|
13
|
+
# @return [Array<Symbol>]
|
14
|
+
def all_members
|
15
|
+
@names + @aliases.keys
|
16
|
+
end
|
11
17
|
|
12
18
|
def has_member?(name)
|
13
|
-
|
19
|
+
autonym_for name
|
14
20
|
rescue Exception
|
15
21
|
false
|
16
22
|
else
|
@@ -36,11 +42,13 @@ class Striuct; module Containable; module Eigen
|
|
36
42
|
|
37
43
|
def dup
|
38
44
|
r = super
|
39
|
-
@names, @flavors, @defaults, @aliases,
|
40
|
-
|
45
|
+
@names, @flavors, @defaults, @aliases,
|
46
|
+
@setter_validations, @getter_validations =
|
47
|
+
*[@names, @flavors, @defaults, @aliases,
|
48
|
+
@setter_validations, @getter_validations].map(&:dup)
|
41
49
|
@conditions, @inferences = @conditions.dup, @inferences.dup
|
42
50
|
r
|
43
51
|
end
|
44
52
|
|
45
53
|
# @endgroup
|
46
|
-
end; end
|
54
|
+
end; end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Striuct
|
2
|
+
|
3
|
+
module ClassMethods
|
4
|
+
|
5
|
+
NAMING_RISKS = {
|
6
|
+
conflict: 10,
|
7
|
+
no_identifier: 9,
|
8
|
+
bad_manners: 5,
|
9
|
+
no_ascii: 3,
|
10
|
+
strict: 0
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
PROTECT_LEVELS = {
|
14
|
+
struct: {error: 99, warn: 99},
|
15
|
+
warning: {error: 99, warn: 5},
|
16
|
+
error: {error: 9, warn: 5},
|
17
|
+
prevent: {error: 5, warn: 1},
|
18
|
+
nervous: {error: 1, warn: 1}
|
19
|
+
}.each(&:freeze).freeze
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -1,21 +1,24 @@
|
|
1
|
-
|
1
|
+
require 'keyvalidatable'
|
2
|
+
|
3
|
+
class Striuct; module ClassMethods
|
2
4
|
# @group Constructor
|
3
5
|
|
4
6
|
# @return [Subclass]
|
5
|
-
def
|
7
|
+
def for_values(*values)
|
6
8
|
new_instance(*values)
|
7
9
|
end
|
8
10
|
|
9
|
-
alias_method :
|
11
|
+
alias_method :load_values, :for_values
|
12
|
+
alias_method :new, :for_values
|
10
13
|
|
11
|
-
# @param [
|
12
|
-
# @return [
|
13
|
-
def
|
14
|
+
# @param [Hash, Struct]
|
15
|
+
# @return [Striuct]
|
16
|
+
def for_pairs(pairs)
|
14
17
|
unless pairs.respond_to?(:each_pair) and pairs.respond_to?(:keys)
|
15
18
|
raise TypeError, 'no pairs object'
|
16
19
|
end
|
17
20
|
|
18
|
-
|
21
|
+
pairs.dup.extend(KeyValidatable).validate_keys let: all_members
|
19
22
|
|
20
23
|
new.tap {|instance|
|
21
24
|
pairs.each_pair do |name, value|
|
@@ -24,16 +27,19 @@ class Striuct; module Containable; module Eigen
|
|
24
27
|
}
|
25
28
|
end
|
26
29
|
|
27
|
-
alias_method :
|
30
|
+
alias_method :load_pairs, :for_pairs
|
31
|
+
alias_method :[], :for_pairs
|
28
32
|
|
29
|
-
# @yieldparam [Subclass] instance
|
30
|
-
# @yieldreturn [Subclass] instance
|
31
|
-
# @return [void]
|
32
33
|
# for build the fixed object
|
34
|
+
# @param [Hash] options
|
35
|
+
# @option options [Boolean] :lock
|
36
|
+
# @option options [Boolean] :strict
|
37
|
+
# @yieldparam [Striuct] instance
|
38
|
+
# @yieldreturn [Striuct] instance
|
39
|
+
# @return [void]
|
33
40
|
def define(options={lock: true, strict: true})
|
34
|
-
raise TypeError, 'arguments have to be pairs object' unless options.respond_to? :keys
|
35
|
-
raise ArgumentError, 'Unknown parameters' unless (options.keys - [:lock, :strict]).empty?
|
36
41
|
raise ArgumentError, 'must with block' unless block_given?
|
42
|
+
options.extend(KeyValidatable).validate_keys let: [:lock, :strict]
|
37
43
|
|
38
44
|
lock, strict = options[:lock], options[:strict]
|
39
45
|
|
@@ -55,4 +61,4 @@ class Striuct; module Containable; module Eigen
|
|
55
61
|
end
|
56
62
|
|
57
63
|
# @endgroup
|
58
|
-
end; end
|
64
|
+
end; end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Striuct; module
|
1
|
+
class Striuct; module ClassMethods
|
2
2
|
# @group Struct+ Handy
|
3
3
|
|
4
4
|
# @yield [name]
|
@@ -40,29 +40,23 @@ class Striuct; module Containable; module Eigen
|
|
40
40
|
|
41
41
|
# @param [Symbol, String] name
|
42
42
|
def original?(name)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
raise NameError
|
47
|
-
end
|
43
|
+
raise NameError unless member? name
|
44
|
+
|
45
|
+
@names.include? name
|
48
46
|
end
|
49
47
|
|
50
48
|
# @param [Symbol, String] name
|
51
49
|
def aliased?(name)
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
raise NameError
|
56
|
-
end
|
50
|
+
raise NameError unless member? name
|
51
|
+
|
52
|
+
@aliases.has_key? name
|
57
53
|
end
|
58
54
|
|
59
55
|
# @param [Symbol, String] original
|
60
56
|
def has_aliases?(original)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
raise NameError
|
65
|
-
end
|
57
|
+
raise NameError unless original? original
|
58
|
+
|
59
|
+
@aliases.has_value? original
|
66
60
|
end
|
67
61
|
|
68
62
|
# @param [Symbol, String] original
|
@@ -76,24 +70,29 @@ class Striuct; module Containable; module Eigen
|
|
76
70
|
raise NameError
|
77
71
|
end
|
78
72
|
end
|
73
|
+
|
74
|
+
# @return [Hash] alias => autonym
|
75
|
+
def aliases
|
76
|
+
@aliases.dup
|
77
|
+
end
|
79
78
|
|
80
79
|
# @param [Symbol, String] name
|
81
80
|
def has_flavor?(name)
|
82
|
-
name =
|
81
|
+
name = autonym_for name
|
83
82
|
|
84
83
|
! flavor_for(name).nil?
|
85
84
|
end
|
86
85
|
|
87
86
|
# @param [Symbol, String] name
|
88
87
|
def has_default?(name)
|
89
|
-
name =
|
88
|
+
name = autonym_for name
|
90
89
|
|
91
90
|
@defaults.has_key? name
|
92
91
|
end
|
93
92
|
|
94
93
|
# @param [Symbol, String] name
|
95
94
|
def default_for(name)
|
96
|
-
name =
|
95
|
+
name = autonym_for name
|
97
96
|
|
98
97
|
if has_default? name
|
99
98
|
_default_for name
|
@@ -122,4 +121,4 @@ class Striuct; module Containable; module Eigen
|
|
122
121
|
end
|
123
122
|
|
124
123
|
# @endgroup
|
125
|
-
end; end
|
124
|
+
end; end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Striuct; module
|
1
|
+
class Striuct; module ClassMethods
|
2
2
|
# @group Use Only Inner
|
3
3
|
|
4
4
|
private
|
@@ -48,7 +48,7 @@ class Striuct; module Containable; module Eigen
|
|
48
48
|
end
|
49
49
|
|
50
50
|
# @param [Symbol, String, #to_sym, #to_str] name
|
51
|
-
def
|
51
|
+
def autonym_for(name)
|
52
52
|
name = keyable_for name
|
53
53
|
|
54
54
|
if _names.include? name
|
@@ -62,32 +62,10 @@ class Striuct; module Containable; module Eigen
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
# @param [Symbol, String, #to_sym
|
66
|
-
# @return [Symbol]
|
65
|
+
# @param [Symbol, String, #to_sym] name
|
66
|
+
# @return [Symbol]
|
67
67
|
def keyable_for(name)
|
68
|
-
|
69
|
-
|
70
|
-
r = (
|
71
|
-
case name
|
72
|
-
when Symbol, String
|
73
|
-
name.to_sym
|
74
|
-
else
|
75
|
-
case
|
76
|
-
when name.respond_to?(:to_sym)
|
77
|
-
name.to_sym
|
78
|
-
when name.respond_to?(:to_str)
|
79
|
-
name.to_str.to_sym
|
80
|
-
else
|
81
|
-
raise TypeError
|
82
|
-
end
|
83
|
-
end
|
84
|
-
)
|
85
|
-
|
86
|
-
if r.instance_of? Symbol
|
87
|
-
r
|
88
|
-
else
|
89
|
-
raise 'must not happen'
|
90
|
-
end
|
68
|
+
name.to_sym
|
91
69
|
end
|
92
70
|
|
93
71
|
# @param [Symbol] name
|
@@ -148,8 +126,8 @@ class Striuct; module Containable; module Eigen
|
|
148
126
|
__set_condition__! name, condition unless Validation::Condition::ANYTHING.equal? condition
|
149
127
|
__set_flavor__! name, &flavor if block_given?
|
150
128
|
|
151
|
-
define_method "#{name}=" do |value|
|
152
|
-
|
129
|
+
define_method :"#{name}=" do |value|
|
130
|
+
__set__ name, value
|
153
131
|
end
|
154
132
|
|
155
133
|
nil
|
@@ -198,7 +176,7 @@ class Striuct; module Containable; module Eigen
|
|
198
176
|
|
199
177
|
# @param [Symbol, String] name
|
200
178
|
def condition_for(name)
|
201
|
-
_condition_for
|
179
|
+
_condition_for autonym_for(name)
|
202
180
|
end
|
203
181
|
|
204
182
|
def _flavor_for(name)
|
@@ -207,7 +185,7 @@ class Striuct; module Containable; module Eigen
|
|
207
185
|
|
208
186
|
# @param [Symbol, String] name
|
209
187
|
def flavor_for(name)
|
210
|
-
_flavor_for
|
188
|
+
_flavor_for autonym_for(name)
|
211
189
|
end
|
212
190
|
|
213
191
|
def _default_for(name)
|
@@ -215,4 +193,4 @@ class Striuct; module Containable; module Eigen
|
|
215
193
|
end
|
216
194
|
|
217
195
|
# @endgroup
|
218
|
-
end; end
|
196
|
+
end; end
|