pikelet 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pikelet/file_definition.rb +2 -2
- data/lib/pikelet/record_definer.rb +29 -0
- data/lib/pikelet/record_definition.rb +3 -12
- data/lib/pikelet/version.rb +1 -1
- data/spec/pikelet/record_definition_spec.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f85a72791e86e65cc0074bbb3912015240b280f
|
4
|
+
data.tar.gz: 76b4aab6edad8e711a2df279b07d616e33de878d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acc91a2a79c79bfb32f361ee41a0085cbf80c1196202e250335f7666625d153675de3ea163884c8ff3b5634f3b9a78c4498f243a19fd54f554da894cbbb13805
|
7
|
+
data.tar.gz: ce8f7386d344c99f65548b124dc6f0d3909296c04773ed744a33c8fdd77daf89b7595d7df66950f483c7783739b96e8d3280e6baa8e9107f68fe75a9d278d6a1
|
@@ -3,12 +3,12 @@ module Pikelet
|
|
3
3
|
attr_reader :base_record_definition
|
4
4
|
|
5
5
|
def initialize(&block)
|
6
|
-
@base_record_definition =
|
6
|
+
@base_record_definition = RecordDefiner.new(self).define(&block)
|
7
7
|
end
|
8
8
|
|
9
9
|
def record(type_signature, base_definition: nil, &block)
|
10
10
|
base_definition ||= base_record_definition
|
11
|
-
record_definitions[type_signature] =
|
11
|
+
record_definitions[type_signature] = RecordDefiner.new(self, base_definition: base_definition).define(&block)
|
12
12
|
end
|
13
13
|
|
14
14
|
def record_definitions
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Pikelet
|
2
|
+
class RecordDefiner
|
3
|
+
attr_reader :file_definition, :definition
|
4
|
+
|
5
|
+
def initialize(file_definition, base_definition: nil)
|
6
|
+
@file_definition = file_definition
|
7
|
+
@definition = RecordDefinition.new(file_definition, base_definition: base_definition)
|
8
|
+
end
|
9
|
+
|
10
|
+
def define(&block)
|
11
|
+
if block_given?
|
12
|
+
instance_eval(&block)
|
13
|
+
end
|
14
|
+
definition
|
15
|
+
end
|
16
|
+
|
17
|
+
def field(name, index, &block)
|
18
|
+
definition.field(name, index, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def record(type_signature, &block)
|
22
|
+
file_definition.record(type_signature, base_definition: definition, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
def method_missing(method, *args, &block)
|
26
|
+
field(method, *args, &block)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,13 +1,12 @@
|
|
1
|
+
require "pikelet/record_definer"
|
2
|
+
|
1
3
|
module Pikelet
|
2
4
|
class RecordDefinition
|
3
5
|
attr_reader :file_definition, :field_definitions
|
4
6
|
|
5
|
-
def initialize(file_definition, base_definition:
|
7
|
+
def initialize(file_definition, base_definition:)
|
6
8
|
@file_definition = file_definition
|
7
9
|
@field_definitions = base_definition && base_definition.field_definitions.dup || {}
|
8
|
-
if block_given?
|
9
|
-
instance_eval(&block)
|
10
|
-
end
|
11
10
|
end
|
12
11
|
|
13
12
|
def field(name, index, &block)
|
@@ -15,10 +14,6 @@ module Pikelet
|
|
15
14
|
field_definitions[name] = Pikelet::FieldDefinition.new(index, &block)
|
16
15
|
end
|
17
16
|
|
18
|
-
def record(type_signature, &block)
|
19
|
-
file_definition.record(type_signature, base_definition: self, &block)
|
20
|
-
end
|
21
|
-
|
22
17
|
def parse(data)
|
23
18
|
record_class.new(*field_definitions.values.map { |field| field.parse(data) })
|
24
19
|
end
|
@@ -27,10 +22,6 @@ module Pikelet
|
|
27
22
|
record_class.new(*hash.values_at(*field_definitions.keys))
|
28
23
|
end
|
29
24
|
|
30
|
-
def method_missing(method, *args, &block)
|
31
|
-
field(method, *args, &block)
|
32
|
-
end
|
33
|
-
|
34
25
|
def record_class
|
35
26
|
@record_class ||= Struct.new(*field_definitions.keys.map(&:to_sym))
|
36
27
|
end
|
data/lib/pikelet/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pikelet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Carney
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- lib/pikelet.rb
|
129
129
|
- lib/pikelet/field_definition.rb
|
130
130
|
- lib/pikelet/file_definition.rb
|
131
|
+
- lib/pikelet/record_definer.rb
|
131
132
|
- lib/pikelet/record_definition.rb
|
132
133
|
- lib/pikelet/version.rb
|
133
134
|
- pikelet.gemspec
|