record 1.1.1 → 1.2.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
  SHA1:
3
- metadata.gz: 905b06c2d1e681e1ae4a2f99b31e1293ab8d455d
4
- data.tar.gz: 9a2876f8c7ca014181d75a1e0e02052b17c1546f
3
+ metadata.gz: cc59075082029afa3cb880dd9048246c0f24e467
4
+ data.tar.gz: 33b1756e6572e6a251aca77d610311606504cf51
5
5
  SHA512:
6
- metadata.gz: a6a98f18f4b684db22b4099ccd0bf2a962d7cde44216facd03de97733000ddff62120709ab3766b85fadef58d5e60b88871a278282f9d7a3451cf6432a4edf67
7
- data.tar.gz: c48238cbdedd1f50f36aad3ecbc5e9b437af5fd8f356bda68e1d16f5182c5d5af2d1d7866eb0d9a6d04832aff459fec1a133cf2af1a6af746a093aaab30ec485
6
+ metadata.gz: 2faf17a51b130aefd4b935e58503beefba5798940df7b47fcb8dc8c0455fa1e8c0cae4748e56bbf04c2e764a5e8e37e382269e30ca97433ea60f6f5b188a8bda
7
+ data.tar.gz: 4321d9fc421c88d573df8016e3f0fb6d960151044ea0d641a43863ef9d63ec7ca0d301f24a157aed3371b4cc528d6ccedf890a4312ec29f78d0214941e1926ed
data/README.md CHANGED
@@ -1,15 +1,103 @@
1
- # record
1
+ # record - named tuples / records with typed structs / schemas
2
2
 
3
- * home :: [github.com/rubylibs/record](https://github.com/rubylibs/record)
4
- * bugs :: [github.com/rubylibs/record/issues](https://github.com/rubylibs/record/issues)
3
+ * home :: [github.com/rubycoco/record](https://github.com/rubycoco/record)
4
+ * bugs :: [github.com/rubycoco/record/issues](https://github.com/rubycoco/record/issues)
5
5
  * gem :: [rubygems.org/gems/record](https://rubygems.org/gems/record)
6
6
  * rdoc :: [rubydoc.info/gems/record](http://rubydoc.info/gems/record)
7
7
  * forum :: [wwwmake](http://groups.google.com/group/wwwmake)
8
8
 
9
9
 
10
+
10
11
  ## Usage
11
12
 
12
13
 
14
+ Step 1: Define a (typed) struct for your records / named tuples. Example:
15
+
16
+ ```ruby
17
+ require 'record'
18
+
19
+ Beer = Record.define do
20
+ field :brewery ## note: default type is :string
21
+ field :city
22
+ field :name
23
+ field :abv, Float ## allows type specified as class (or use :float)
24
+ end
25
+ ```
26
+
27
+ or in "classic" style:
28
+
29
+ ```ruby
30
+ class Beer < Record::Base
31
+ field :brewery
32
+ field :city
33
+ field :name
34
+ field :abv, Float
35
+ end
36
+ ```
37
+
38
+
39
+
40
+ Step 2: Use the new class to create new (typed) records. Example:
41
+
42
+
43
+ ``` ruby
44
+ beer = Beer.new( 'Andechser Klosterbrauerei',
45
+ 'Andechs',
46
+ 'Doppelbock Dunkel',
47
+ '7%' )
48
+
49
+ # -or-
50
+
51
+ values = ['Andechser Klosterbrauerei', 'Andechs', 'Doppelbock Dunkel', '7%']
52
+ beer = Beer.new( values )
53
+
54
+ # -or-
55
+
56
+ beer = Beer.new( brewery: 'Andechser Klosterbrauerei',
57
+ city: 'Andechs',
58
+ name: 'Doppelbock Dunkel',
59
+ abv: '7%' )
60
+
61
+ # -or-
62
+
63
+ hash = { brewery: 'Andechser Klosterbrauerei',
64
+ city: 'Andechs',
65
+ name: 'Doppelbock Dunkel',
66
+ abv: '7%' }
67
+ beer = Beer.new( hash )
68
+
69
+
70
+ # -or-
71
+
72
+ beer = Beer.new
73
+ beer.update( brewery: 'Andechser Klosterbrauerei',
74
+ city: 'Andechs',
75
+ name: 'Doppelbock Dunkel' )
76
+ beer.update( abv: 7.0 )
77
+
78
+ # -or-
79
+
80
+ beer = Beer.new
81
+ beer.parse( ['Andechser Klosterbrauerei', 'Andechs', 'Doppelbock Dunkel', '7%'] )
82
+
83
+ # -or-
84
+
85
+ beer = Beer.new
86
+ beer.parse( 'Andechser Klosterbrauerei,Andechs,Doppelbock Dunkel,7%' )
87
+
88
+ # -or-
89
+
90
+ beer = Beer.new
91
+ beer.brewery = 'Andechser Klosterbrauerei'
92
+ beer.name = 'Doppelbock Dunkel'
93
+ beer.abv = 7.0
94
+ ```
95
+
96
+
97
+ And so on. That's it.
98
+
99
+
100
+
13
101
 
14
102
  ## License
15
103
 
data/Rakefile CHANGED
@@ -5,10 +5,10 @@ Hoe.spec 'record' do
5
5
 
6
6
  self.version = Record::VERSION
7
7
 
8
- self.summary = "record"
8
+ self.summary = "record - named tuples / records with typed structs / schemas"
9
9
  self.description = summary
10
10
 
11
- self.urls = ['https://github.com/rubylibs/record']
11
+ self.urls = ['https://github.com/rubycoco/record']
12
12
 
13
13
  self.author = 'Gerald Bauer'
14
14
  self.email = 'wwwmake@googlegroups.com'
@@ -20,7 +20,7 @@ Hoe.spec 'record' do
20
20
  self.licenses = ['Public Domain']
21
21
 
22
22
  self.spec_extras = {
23
- :required_ruby_version => '>= 2.2.2'
23
+ required_ruby_version: '>= 2.2.2'
24
24
  }
25
25
 
26
26
  end
@@ -1,6 +1,8 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'pp'
4
+ require 'logger'
5
+
4
6
 
5
7
 
6
8
  ###
@@ -11,4 +13,5 @@ require 'record/base'
11
13
  require 'record/builder'
12
14
 
13
15
 
14
- puts Record.banner # say hello
16
+ # say hello
17
+ puts Record.banner if $DEBUG || (defined?($RUBYCOCO_DEBUG) && $RUBYCOCO_DEBUG)
@@ -5,27 +5,45 @@
5
5
  module Record
6
6
 
7
7
  class Builder # check: rename to RecordDefinition or RecordDsl or similar - why? why not?
8
+
9
+ ###################################
10
+ ## add simple logger with debug flag/switch
11
+ #
12
+ # use Parser.debug = true # to turn on
13
+ #
14
+ # todo/fix: use logutils instead of std logger - why? why not?
15
+
16
+ def self.build_logger()
17
+ l = Logger.new( STDOUT )
18
+ l.level = :info ## set to :info on start; note: is 0 (debug) by default
19
+ l
20
+ end
21
+ def self.logger() @@logger ||= build_logger; end
22
+ def logger() self.class.logger; end
23
+
24
+
25
+
8
26
  def initialize( super_class=Base )
9
27
  @clazz = Class.new( super_class )
10
28
  end
11
29
 
12
30
  def field( name, type=:string ) ## note: type defaults to string
13
- puts " adding field >#{name}< with type >#{type}<"
31
+ logger.debug " adding field >#{name}< with type >#{type}<"
14
32
  @clazz.field( name, type ) ## auto-add getter and setter
15
33
  end
16
34
 
17
35
  def string( name )
18
- puts " adding string field >#{name}<"
36
+ logger.debug " adding string field >#{name}<"
19
37
  field( name, :string )
20
38
  end
21
39
 
22
40
  def integer( name ) ## use number for alias for integer - why? why not???
23
- puts " adding integer number field >#{name}<"
41
+ logger.debug " adding integer number field >#{name}<"
24
42
  field( name, :integer )
25
43
  end
26
44
 
27
45
  def float( name )
28
- puts " adding float number field >#{name}<"
46
+ logger.debug " adding float number field >#{name}<"
29
47
  field( name, :float )
30
48
  end
31
49
 
@@ -9,6 +9,24 @@ module Record
9
9
  ## - fields (NOT columns or attributes) -- might add an alias later - why? why not?
10
10
 
11
11
  class Field ## ruby record class field
12
+
13
+
14
+ ###################################
15
+ ## add simple logger with debug flag/switch
16
+ #
17
+ # use Parser.debug = true # to turn on
18
+ #
19
+ # todo/fix: use logutils instead of std logger - why? why not?
20
+
21
+ def self.build_logger()
22
+ l = Logger.new( STDOUT )
23
+ l.level = :info ## set to :info on start; note: is 0 (debug) by default
24
+ l
25
+ end
26
+ def self.logger() @@logger ||= build_logger; end
27
+ def logger() self.class.logger; end
28
+
29
+
12
30
  attr_reader :name, :type
13
31
 
14
32
  ## zero-based position index (0,1,2,3,...)
@@ -28,7 +46,7 @@ module Record
28
46
  else
29
47
  @type = Type.registry[type.to_sym]
30
48
  if @type.nil?
31
- puts "!!!! warn unknown type >#{type}< - no class mapping found; add missing type to Record::Type.registry[]"
49
+ logger.warn "!!!! warn unknown type >#{type}< - no class mapping found; add missing type to Record::Type.registry[]"
32
50
  ## todo/fix: raise exception!!!!
33
51
  end
34
52
  end
@@ -46,16 +64,16 @@ module Record
46
64
  elsif @type == Float
47
65
  ## note: allow/check for nil values - why? why not?
48
66
  float = (value.nil? || value.empty?) ? nil : value.to_f
49
- puts "typecast >#{value}< to float number >#{float}<"
67
+ logger.debug "typecast >#{value}< to float number >#{float}<"
50
68
  float
51
69
  elsif @type == Integer
52
70
  number = (value.nil? || value.empty?) ? nil : value.to_i(10) ## always use base10 for now (e.g. 010 => 10 etc.)
53
- puts "typecast >#{value}< to integer number >#{number}<"
71
+ logger.debug "typecast >#{value}< to integer number >#{number}<"
54
72
  number
55
73
  else
56
74
  ## todo/fix: raise exception about unknow type
57
- pp @type
58
- puts "!!!! unknown type >#{@type}< - don't know how to convert/typecast string value >#{value}<"
75
+ logger.warn "!!!! unknown type >#{@type}< - don't know how to convert/typecast string value >#{value}<"
76
+ logger.warn @type.inspect
59
77
  value
60
78
  end
61
79
  end
@@ -3,10 +3,14 @@
3
3
 
4
4
  module Record
5
5
 
6
- MAJOR = 1 ## todo: namespace inside version or something - why? why not??
7
- MINOR = 1
8
- PATCH = 1
9
- VERSION = [MAJOR,MINOR,PATCH].join('.')
6
+ module Version
7
+ MAJOR = 1
8
+ MINOR = 2
9
+ PATCH = 0
10
+ end
11
+ VERSION = [Version::MAJOR,
12
+ Version::MINOR,
13
+ Version::PATCH].join('.')
10
14
 
11
15
 
12
16
  def self.version
@@ -7,3 +7,9 @@ require 'minitest/autorun'
7
7
 
8
8
  ## our own code
9
9
  require 'record'
10
+
11
+
12
+
13
+ ## turn on "global" logging
14
+ Record::Field.logger.level = :debug
15
+ Record::Builder.logger.level = :debug
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: record
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-15 00:00:00.000000000 Z
11
+ date: 2018-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.16'
41
- description: record
41
+ description: record - named tuples / records with typed structs / schemas
42
42
  email: wwwmake@googlegroups.com
43
43
  executables: []
44
44
  extensions: []
@@ -61,7 +61,7 @@ files:
61
61
  - test/helper.rb
62
62
  - test/test_record.rb
63
63
  - test/test_version.rb
64
- homepage: https://github.com/rubylibs/record
64
+ homepage: https://github.com/rubycoco/record
65
65
  licenses:
66
66
  - Public Domain
67
67
  metadata: {}
@@ -86,5 +86,5 @@ rubyforge_project:
86
86
  rubygems_version: 2.5.2
87
87
  signing_key:
88
88
  specification_version: 4
89
- summary: record
89
+ summary: record - named tuples / records with typed structs / schemas
90
90
  test_files: []