data_class_factory 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 248fcc0579eee6284c5b4f87deb9b1e14bc132d164306c79b674248fff88f39e
|
4
|
+
data.tar.gz: d80f4e6b79f37c08d07a4de9ccc0041dd95c6d4adda20a3796aa18813f40db8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f5afad37080bbadea3401f205e7b67af8c4fe428bff36685f55187f7db3422f195230ebd8f3bd9bfa8ed8b396dfa2fa46c9a5332d941a789277d5c494de6e87
|
7
|
+
data.tar.gz: d841d810645c0b1dbf277eb73a1ee9bade0741dccbf347e38c4856a9d2724707d63eecb7ac8b843682544929b5ff9fae088b1284b7fe1e1c3863963fa5003f42
|
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
module DataClass
|
4
4
|
# An internal class for providing implementation of `Data.define`.
|
5
|
-
class
|
6
|
-
# @param
|
7
|
-
def initialize(
|
8
|
-
@definition =
|
5
|
+
class Definer
|
6
|
+
# @param definition [Definition]
|
7
|
+
def initialize(definition)
|
8
|
+
@definition = definition
|
9
9
|
end
|
10
10
|
|
11
11
|
# @param parent_class [Data]
|
12
12
|
# @return [Class<Data>]
|
13
|
-
def
|
13
|
+
def define_class(parent_class:, &block)
|
14
14
|
attribute_names = @definition.attribute_names
|
15
15
|
|
16
16
|
# defines a subclass of Data.
|
@@ -8,7 +8,7 @@ module DataClass
|
|
8
8
|
# @param attribute_names [Array<Symbol>]
|
9
9
|
def initialize(attribute_names)
|
10
10
|
validate_attribute_names(attribute_names)
|
11
|
-
@attribute_names = attribute_names
|
11
|
+
@attribute_names = attribute_names
|
12
12
|
end
|
13
13
|
attr_reader :attribute_names
|
14
14
|
|
@@ -37,7 +37,5 @@ module DataClass
|
|
37
37
|
checked << key
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
41
|
-
def validate_attribute_name(key); end
|
42
40
|
end
|
43
41
|
end
|
data/lib/data_class_factory.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'data_class_factory/version'
|
4
|
+
require 'data_class/definer'
|
4
5
|
require 'data_class/definition'
|
5
|
-
require 'data_class/factory'
|
6
6
|
require 'data_class/instance_methods'
|
7
7
|
|
8
8
|
# Defining a factory class.
|
@@ -12,8 +12,9 @@ require 'data_class/instance_methods'
|
|
12
12
|
# # @param attribute_names [Array<Symbol>]
|
13
13
|
# # @return [Class<Data>]
|
14
14
|
# def self.define(*attribute_names, &block)
|
15
|
-
#
|
16
|
-
#
|
15
|
+
# definition = DataClass::Definition.new(attribute_names)
|
16
|
+
# definer = DataClass::Definer.new(definition)
|
17
|
+
# definer.define_class(parent_class: self, &block)
|
17
18
|
# end
|
18
19
|
# ...
|
19
20
|
# end
|
@@ -26,8 +27,9 @@ module DataClassFactory
|
|
26
27
|
def define_factory_class
|
27
28
|
Class.new do
|
28
29
|
define_singleton_method(:define) do |*attribute_names, &block|
|
29
|
-
|
30
|
-
|
30
|
+
definition = DataClass::Definition.new(attribute_names)
|
31
|
+
definer = DataClass::Definer.new(definition)
|
32
|
+
definer.define_class(parent_class: self, &block)
|
31
33
|
end
|
32
34
|
private_class_method :new
|
33
35
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_class_factory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YusukeIwaki
|
@@ -109,8 +109,8 @@ files:
|
|
109
109
|
- bin/setup
|
110
110
|
- data_class_factory.gemspec
|
111
111
|
- lib/data.rb
|
112
|
+
- lib/data_class/definer.rb
|
112
113
|
- lib/data_class/definition.rb
|
113
|
-
- lib/data_class/factory.rb
|
114
114
|
- lib/data_class/instance_methods.rb
|
115
115
|
- lib/data_class_factory.rb
|
116
116
|
- lib/data_class_factory/version.rb
|