fixy 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/fixy.gemspec +1 -2
- data/lib/fixy/record.rb +11 -5
- data/lib/fixy/version.rb +2 -2
- data/spec/fixy/record_spec.rb +39 -0
- data/spec/spec_helper.rb +6 -0
- metadata +13 -37
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 920d1f790730e2a1fab764c52a27a6296c1864b0
|
4
|
+
data.tar.gz: 2d41058beac14b76f575244fce378390ccdb153e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3f88596d4ae34bad598b91b943dd7a57015374a1069ed4a06be59084c7409b0e52378a12557eebeaf1a2702c98c6fff38f73f9f7d397c637a7b16e508478d173
|
7
|
+
data.tar.gz: 612e1d75d45282c9a252e6ebadaf3d1c3a6e914e401d9975e13a786f3b21454f7c28d2d5b1080e94376ac725a8e0caebe2958512ebc0f6026f07625e3575364d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -106,7 +106,7 @@ A document is composed of a multitude of records (instances of a `Fixy::Record`)
|
|
106
106
|
class PeopleDocument < Fixy::Document
|
107
107
|
def build
|
108
108
|
append_record PersonRecord.new('Sarah', 'Kerrigan')
|
109
|
-
append_record
|
109
|
+
append_record PersonRecord.new('Jim', 'Raynor')
|
110
110
|
prepend_record PersonRecord.new('Arcturus', 'Mengsk')
|
111
111
|
end
|
112
112
|
end
|
data/fixy.gemspec
CHANGED
data/lib/fixy/record.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
module Fixy
|
2
2
|
class Record
|
3
|
-
require 'active_support/core_ext/proc'
|
4
|
-
|
5
3
|
class << self
|
6
4
|
def set_record_length(count)
|
7
5
|
define_singleton_method('record_length') { count }
|
8
6
|
end
|
9
7
|
|
10
8
|
def field(name, size, range, type)
|
11
|
-
@record_fields ||=
|
9
|
+
@record_fields ||= default_record_fields
|
12
10
|
range_matches = range.match /^(\d+)(?:-(\d+))?$/
|
13
11
|
|
14
12
|
# Make sure inputs are valid, we rather fail early than behave unexpectedly later.
|
@@ -45,7 +43,7 @@ module Fixy
|
|
45
43
|
end
|
46
44
|
|
47
45
|
if value.is_a? Proc
|
48
|
-
define_method(name) {
|
46
|
+
define_method(name) { self.instance_exec(&value) }
|
49
47
|
else
|
50
48
|
define_method(name) { value }
|
51
49
|
end
|
@@ -54,6 +52,14 @@ module Fixy
|
|
54
52
|
def record_fields
|
55
53
|
@record_fields
|
56
54
|
end
|
55
|
+
|
56
|
+
def default_record_fields
|
57
|
+
if superclass.respond_to?(:record_fields, true) && superclass.record_fields
|
58
|
+
superclass.record_fields.dup
|
59
|
+
else
|
60
|
+
{}
|
61
|
+
end
|
62
|
+
end
|
57
63
|
end
|
58
64
|
|
59
65
|
attr_accessor :debug_mode
|
@@ -104,4 +110,4 @@ module Fixy
|
|
104
110
|
debug_mode ? Fixy::Decorator::Debug : Fixy::Decorator::Default
|
105
111
|
end
|
106
112
|
end
|
107
|
-
end
|
113
|
+
end
|
data/lib/fixy/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Fixy
|
2
|
-
VERSION = "0.0.
|
3
|
-
end
|
2
|
+
VERSION = "0.0.2"
|
3
|
+
end
|
data/spec/fixy/record_spec.rb
CHANGED
@@ -93,4 +93,43 @@ describe 'Generating a Record' do
|
|
93
93
|
}.to raise_error(StandardError, "Undefined field for position 19")
|
94
94
|
end
|
95
95
|
end
|
96
|
+
|
97
|
+
context 'when inheriting from another record' do
|
98
|
+
class PersonRecordG < Fixy::Record
|
99
|
+
include Fixy::Formatter::Alphanumeric
|
100
|
+
set_record_length 20
|
101
|
+
|
102
|
+
field :first_name, 10, '1-10' , :alphanumeric
|
103
|
+
field_value :first_name, -> { 'Bob' }
|
104
|
+
end
|
105
|
+
|
106
|
+
class PersonRecordH < PersonRecordG
|
107
|
+
include Fixy::Formatter::Alphanumeric
|
108
|
+
set_record_length 20
|
109
|
+
field :last_name , 10, '11-20', :alphanumeric
|
110
|
+
field_value :last_name, -> { 'Williams' }
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should include fields from the superclass' do
|
114
|
+
PersonRecordH.new.generate.slice(0, 10).should eq 'Bob '
|
115
|
+
PersonRecordH.new.generate.slice(10, 10).should eq 'Williams '
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'when two records inherit' do
|
119
|
+
class PersonRecordI < PersonRecordG
|
120
|
+
include Fixy::Formatter::Alphanumeric
|
121
|
+
set_record_length 20
|
122
|
+
field :last_name , 10, '11-20', :alphanumeric
|
123
|
+
field_value :last_name, -> { 'Jacobs' }
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'does not collide' do
|
127
|
+
PersonRecordH.new.generate.slice(0, 10).should eq 'Bob '
|
128
|
+
PersonRecordH.new.generate.slice(10, 10).should eq 'Williams '
|
129
|
+
|
130
|
+
PersonRecordI.new.generate.slice(0, 10).should eq 'Bob '
|
131
|
+
PersonRecordI.new.generate.slice(10, 10).should eq 'Jacobs '
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
96
135
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,78 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Omar Skalli
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-11-13 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rake
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: activesupport
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ! '>='
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
70
|
-
type: :runtime
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ! '>='
|
52
|
+
- - '>='
|
76
53
|
- !ruby/object:Gem::Version
|
77
54
|
version: '0'
|
78
55
|
description: Library for generating fixed width flat files.
|
@@ -104,27 +81,26 @@ files:
|
|
104
81
|
homepage: https://github.com/chetane/fixy
|
105
82
|
licenses:
|
106
83
|
- MIT
|
84
|
+
metadata: {}
|
107
85
|
post_install_message:
|
108
86
|
rdoc_options: []
|
109
87
|
require_paths:
|
110
88
|
- lib
|
111
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
-
none: false
|
113
90
|
requirements:
|
114
|
-
- -
|
91
|
+
- - '>='
|
115
92
|
- !ruby/object:Gem::Version
|
116
93
|
version: '0'
|
117
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
-
none: false
|
119
95
|
requirements:
|
120
|
-
- -
|
96
|
+
- - '>='
|
121
97
|
- !ruby/object:Gem::Version
|
122
98
|
version: '0'
|
123
99
|
requirements: []
|
124
100
|
rubyforge_project:
|
125
|
-
rubygems_version:
|
101
|
+
rubygems_version: 2.4.2
|
126
102
|
signing_key:
|
127
|
-
specification_version:
|
103
|
+
specification_version: 4
|
128
104
|
summary: Provides a DSL for defining, generating, and debugging fixed width documents.
|
129
105
|
test_files:
|
130
106
|
- spec/fixtures/debug_document.txt
|