typed_accessors 0.1 → 0.2

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/README CHANGED
@@ -1,9 +1,12 @@
1
- This rails plugin creates a set of typed accessors for data types.
2
- This is very handy when you are interacting with a service that
3
- returns strings and you want them automatically turned into more
4
- useful types.
1
+ = Overview
5
2
 
6
- Ex:
3
+ Typed accessors creates a set of accessors with a predefined typed.
4
+ Often when dealing with webservices all the data comes back as
5
+ strings, but you really want to be working with these things as
6
+ numbers or dates. Manually converting them is duplication, and can be
7
+ error prone.
8
+
9
+ == Example
7
10
 
8
11
  class Foo
9
12
  float_accessor :float
@@ -27,4 +30,21 @@ Ex:
27
30
  >> f.date.to_s
28
31
  => "2009-10-30"
29
32
 
30
- This work was done by Patt Ladd. Sean Dague has helped in packaging it.
33
+ == Installation
34
+
35
+ First install the gem
36
+
37
+ gem install typed_accesors
38
+
39
+ Then include it in your environment
40
+
41
+ require "typed_accessors"
42
+
43
+ == Authors
44
+
45
+ Creator: Pat Ladd
46
+ Packager: Sean Dague
47
+
48
+ == License
49
+
50
+ This is released under an MIT license, see COPYING for full details.
data/Rakefile CHANGED
@@ -4,8 +4,10 @@ require 'rake/testtask'
4
4
  require 'rake/rdoctask'
5
5
  require 'rake/clean'
6
6
  require 'rake/contrib/sshpublisher'
7
+ require 'rake/contrib/rubyforgepublisher'
7
8
 
8
- PKG_VERSION = "0.1"
9
+ PKG_NAME = "typed_accessors"
10
+ PKG_VERSION = "0.2"
9
11
 
10
12
  $VERBOSE = nil
11
13
  TEST_CHANGES_SINCE = Time.now - 600 # Recent tests = changed in last 10 minutes
@@ -49,32 +51,32 @@ Rake::RDocTask.new(:doc) { |rdoc|
49
51
  rdoc.main = 'README'
50
52
  rdoc.rdoc_files.include('lib/**/*.rb', 'README')
51
53
  rdoc.rdoc_files.include('COPYING')
52
- rdoc.rdoc_dir = 'docs/api'
54
+ rdoc.rdoc_dir = 'docs/typed_accessors'
53
55
  rdoc.title = "Typed Accessors"
54
56
  rdoc.options << "--include=examples --line-numbers --inline-source"
55
- rdoc.options << "--accessor=ical_component,ical_property,ical_multi_property"
56
57
  }
57
58
 
58
59
  Gem::manage_gems
59
60
  require 'rake/gempackagetask'
60
61
 
61
62
  spec = Gem::Specification.new do |s|
62
- s.name = "typed_accessors"
63
- s.version = PKG_VERSION
64
- s.homepage = "http://github.com/sdague/typed_accessors"
65
- s.platform = Gem::Platform::RUBY
66
- s.summary = "Predefined typed accessors"
67
- s.description = "Defines easy to use additional functions to creating typed accessors, which auto convert the attributes to non string types"
68
-
69
- s.files = FileList["{test,lib,docs,examples}/**/*"].to_a
70
- s.files += ["Rakefile", "README", "COPYING" ]
71
- s.require_path = "lib"
72
- s.autorequire = "typed_accessors"
73
- s.has_rdoc = true
74
- s.extra_rdoc_files = ["README", "COPYING"]
75
- s.rdoc_options.concat ['--main', 'README']
76
-
77
- s.author = "Pat Ladd"
63
+ s.name = "typed_accessors"
64
+ s.version = PKG_VERSION
65
+ s.homepage = "http://github.com/sdague/typed_accessors"
66
+ s.platform = Gem::Platform::RUBY
67
+ s.summary = "Predefined typed accessors"
68
+ s.description = "Defines easy to use additional functions to creating typed accessors, which auto convert the attributes to non string types"
69
+ s.rubyforge_project = "http://rubyforge.org/projects/sdaguegems"
70
+ s.files = FileList["{test,lib,docs,examples}/**/*"].to_a
71
+ s.files += ["Rakefile", "README", "COPYING" ]
72
+ s.require_path = "lib"
73
+ s.autorequire = "typed_accessors"
74
+ s.has_rdoc = true
75
+ s.extra_rdoc_files = ["README", "COPYING"]
76
+ s.rdoc_options.concat ['--main', 'README']
77
+ s.rdoc_options.concat ['--accessor int_accessor="RW int" --accessor int_reader="R int" --accessor int_writer="W int" --accessor float_accessor="RW float" --accessor float_reader="R float" --accessor float_writer="W float" --accessor bool_yn_accessor="RW bool" --accessor bool_yn_reader="R bool" --accessor bool_yn_writer="W bool"']
78
+ s.author = "Sean Dague"
79
+ s.email = "sean@dague.net"
78
80
  end
79
81
 
80
82
  Rake::GemPackageTask.new(spec) do |pkg|
@@ -83,18 +85,50 @@ Rake::GemPackageTask.new(spec) do |pkg|
83
85
  pkg.need_zip = true
84
86
  end
85
87
 
88
+ desc "Publish the release files to RubyForge."
89
+ task :release => [ :package, :publish_docs ] do
90
+ require 'rubyforge'
91
+ packages = %w( gem tgz zip ).collect{ |ext| "pkg/#{PKG_NAME}-#{PKG_VERSION}.#{ext}" }
92
+ rubyforge = RubyForge.new
93
+ rubyforge.configure
94
+ rubyforge.login
95
+ rubyforge.scrape_project("sdaguegems")
96
+ rubyforge.add_release("sdaguegems", PKG_NAME, "v#{PKG_VERSION}", *packages)
97
+ end
98
+
86
99
  desc 'Install the gem globally (requires sudo)'
87
100
  task :install => :package do |t|
88
101
  `sudo gem install pkg/typed_accessors-#{PKG_VERSION}.gem`
89
102
  end
90
103
 
104
+ desc "Upload Docs to RubyForge"
105
+ task :publish_docs => [:doc] do
106
+ publisher = Rake::SshDirPublisher.new(
107
+ "sdague@rubyforge.org",
108
+ "/var/www/gforge-projects/sdaguegems",
109
+ "docs"
110
+ )
111
+ publisher.upload
112
+ end
113
+
114
+ # task :release => [:clobber, :verify_committed, :spec, :publish_packages, :tag, :publish_news]
115
+
116
+ desc "Verifies that there is no uncommitted code"
117
+ task :verify_committed do
118
+ IO.popen('svn stat') do |io|
119
+ io.each_line do |line|
120
+ raise "\n!!! Do a svn commit first !!!\n\n" if line =~ /^\s*modified:\s*/
121
+ end
122
+ end
123
+ end
124
+
91
125
  task :lines do
92
126
  lines = 0
93
127
  codelines = 0
94
- Dir.foreach("lib/typed_accessors") { |file_name|
128
+ Dir.foreach("lib") { |file_name|
95
129
  next unless file_name =~ /.*rb/
96
130
 
97
- f = File.open("lib/typed_accessors/" + file_name)
131
+ f = File.open("lib/" + file_name)
98
132
 
99
133
  while line = f.gets
100
134
  lines += 1
@@ -0,0 +1,260 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Class: Class</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Class</strong></td>
53
+ <td class="class-name-in-header">Class</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/typed_accessors_rb.html">
59
+ lib/typed_accessors.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ <tr class="top-aligned-row">
66
+ <td><strong>Parent:</strong></td>
67
+ <td>
68
+ Object
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ </div>
73
+ <!-- banner header -->
74
+
75
+ <div id="bodyContent">
76
+
77
+
78
+
79
+ <div id="contextContent">
80
+
81
+ <div id="description">
82
+ <p>
83
+ Typed accessors works as a Mixin on <a href="Class.html">Class</a>. It
84
+ creates a set of functions that are used in the class definition which eval
85
+ and create new accessor methods at class eval time (so little performance
86
+ penalty). For now, this is limitted to built in types, float, int, boolean,
87
+ and date, though this approach could clearly be expanded.
88
+ </p>
89
+ <p>
90
+ Example of a class definition
91
+ </p>
92
+ <pre>
93
+ class MyClass
94
+ float_accessor :distance
95
+ int_accessor :count
96
+ bool_yn_accessor :onfire
97
+ date_accessor :day
98
+ end
99
+ </pre>
100
+
101
+ </div>
102
+
103
+
104
+ </div>
105
+
106
+ <div id="method-list">
107
+ <h3 class="section-bar">Methods</h3>
108
+
109
+ <div class="name-list">
110
+ <a href="#M000001">bool_yn_accessor</a>&nbsp;&nbsp;
111
+ <a href="#M000004">date_accessor</a>&nbsp;&nbsp;
112
+ <a href="#M000002">float_accessor</a>&nbsp;&nbsp;
113
+ <a href="#M000003">int_accessor</a>&nbsp;&nbsp;
114
+ </div>
115
+ </div>
116
+
117
+ </div>
118
+
119
+
120
+ <!-- if includes -->
121
+
122
+ <div id="section">
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+ <!-- if method_list -->
132
+ <div id="methods">
133
+ <h3 class="section-bar">Public Instance methods</h3>
134
+
135
+ <div id="method-M000001" class="method-detail">
136
+ <a name="M000001"></a>
137
+
138
+ <div class="method-heading">
139
+ <a href="#M000001" class="method-signature">
140
+ <span class="method-name">bool_yn_accessor</span><span class="method-args">( *symbols )</span>
141
+ </a>
142
+ </div>
143
+
144
+ <div class="method-description">
145
+ <p>
146
+ Creates a boolean accessor. It will convert and incoming string to a true /
147
+ false value. If the string is &quot;y&quot; or &quot;yes&quot; it will be
148
+ true, otherwise false.
149
+ </p>
150
+ <p><a class="source-toggle" href="#"
151
+ onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
152
+ <div class="method-source-code" id="M000001-source">
153
+ <pre>
154
+ <span class="ruby-comment cmt"># File lib/typed_accessors.rb, line 22</span>
155
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">bool_yn_accessor</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">symbols</span> )
156
+ <span class="ruby-identifier">attr_reader</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">symbols</span> )
157
+ <span class="ruby-identifier">bool_yn_writer</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">symbols</span> )
158
+ <span class="ruby-keyword kw">end</span>
159
+ </pre>
160
+ </div>
161
+ </div>
162
+ </div>
163
+
164
+ <div id="method-M000004" class="method-detail">
165
+ <a name="M000004"></a>
166
+
167
+ <div class="method-heading">
168
+ <a href="#M000004" class="method-signature">
169
+ <span class="method-name">date_accessor</span><span class="method-args">( *symbols )</span>
170
+ </a>
171
+ </div>
172
+
173
+ <div class="method-description">
174
+ <p>
175
+ Creates a data accessor using the Date parse function on strings. Not
176
+ defined for other input types.
177
+ </p>
178
+ <p><a class="source-toggle" href="#"
179
+ onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
180
+ <div class="method-source-code" id="M000004-source">
181
+ <pre>
182
+ <span class="ruby-comment cmt"># File lib/typed_accessors.rb, line 44</span>
183
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">date_accessor</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">symbols</span> )
184
+ <span class="ruby-identifier">attr_reader</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">symbols</span> )
185
+ <span class="ruby-identifier">date_writer</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">symbols</span> )
186
+ <span class="ruby-keyword kw">end</span>
187
+ </pre>
188
+ </div>
189
+ </div>
190
+ </div>
191
+
192
+ <div id="method-M000002" class="method-detail">
193
+ <a name="M000002"></a>
194
+
195
+ <div class="method-heading">
196
+ <a href="#M000002" class="method-signature">
197
+ <span class="method-name">float_accessor</span><span class="method-args">( *symbols )</span>
198
+ </a>
199
+ </div>
200
+
201
+ <div class="method-description">
202
+ <p>
203
+ Creates a float accessor, using built in .to_f functions on objects. Any
204
+ object that has a .to_f is supported.
205
+ </p>
206
+ <p><a class="source-toggle" href="#"
207
+ onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
208
+ <div class="method-source-code" id="M000002-source">
209
+ <pre>
210
+ <span class="ruby-comment cmt"># File lib/typed_accessors.rb, line 30</span>
211
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">float_accessor</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">symbols</span> )
212
+ <span class="ruby-identifier">attr_reader</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">symbols</span> )
213
+ <span class="ruby-identifier">float_writer</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">symbols</span> )
214
+ <span class="ruby-keyword kw">end</span>
215
+ </pre>
216
+ </div>
217
+ </div>
218
+ </div>
219
+
220
+ <div id="method-M000003" class="method-detail">
221
+ <a name="M000003"></a>
222
+
223
+ <div class="method-heading">
224
+ <a href="#M000003" class="method-signature">
225
+ <span class="method-name">int_accessor</span><span class="method-args">( *symbols )</span>
226
+ </a>
227
+ </div>
228
+
229
+ <div class="method-description">
230
+ <p>
231
+ Creates an int accessor, using built in .to_i functions on objects. Any
232
+ object that has a .to_i is supported.
233
+ </p>
234
+ <p><a class="source-toggle" href="#"
235
+ onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
236
+ <div class="method-source-code" id="M000003-source">
237
+ <pre>
238
+ <span class="ruby-comment cmt"># File lib/typed_accessors.rb, line 37</span>
239
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">int_accessor</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">symbols</span> )
240
+ <span class="ruby-identifier">attr_reader</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">symbols</span> )
241
+ <span class="ruby-identifier">int_writer</span>( <span class="ruby-operator">*</span><span class="ruby-identifier">symbols</span> )
242
+ <span class="ruby-keyword kw">end</span>
243
+ </pre>
244
+ </div>
245
+ </div>
246
+ </div>
247
+
248
+
249
+ </div>
250
+
251
+
252
+ </div>
253
+
254
+
255
+ <div id="validator-badges">
256
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
257
+ </div>
258
+
259
+ </body>
260
+ </html>
@@ -0,0 +1 @@
1
+ Sun, 29 Mar 2009 12:38:25 -0400
@@ -0,0 +1,133 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>File: COPYING</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="fileHeader">
50
+ <h1>COPYING</h1>
51
+ <table class="header-table">
52
+ <tr class="top-aligned-row">
53
+ <td><strong>Path:</strong></td>
54
+ <td>COPYING
55
+ </td>
56
+ </tr>
57
+ <tr class="top-aligned-row">
58
+ <td><strong>Last Update:</strong></td>
59
+ <td>Fri Mar 27 16:49:34 -0400 2009</td>
60
+ </tr>
61
+ </table>
62
+ </div>
63
+ <!-- banner header -->
64
+
65
+ <div id="bodyContent">
66
+
67
+
68
+
69
+ <div id="contextContent">
70
+
71
+ <div id="description">
72
+ <p>
73
+ The MIT License
74
+ </p>
75
+ <p>
76
+ Copyright (c) 2009 Patrick Ladd, Sean Dague &lt;<a
77
+ href="http://dague.net">dague.net</a>&gt;
78
+ </p>
79
+ <p>
80
+ Permission is hereby granted, free of charge, to any person obtaining a
81
+ copy of this software and associated documentation files (the
82
+ &quot;Software&quot;), to deal in the Software without restriction,
83
+ including without limitation the rights to use, copy, modify, merge,
84
+ publish, distribute, sublicense, and/or sell copies of the Software, and to
85
+ permit persons to whom the Software is furnished to do so, subject to the
86
+ following conditions:
87
+ </p>
88
+ <p>
89
+ The above copyright notice and this permission notice shall be included in
90
+ all copies or substantial portions of the Software.
91
+ </p>
92
+ <p>
93
+ THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
94
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
95
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
96
+ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
97
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
98
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
99
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
100
+ </p>
101
+
102
+ </div>
103
+
104
+
105
+ </div>
106
+
107
+
108
+ </div>
109
+
110
+
111
+ <!-- if includes -->
112
+
113
+ <div id="section">
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+ <!-- if method_list -->
123
+
124
+
125
+ </div>
126
+
127
+
128
+ <div id="validator-badges">
129
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
130
+ </div>
131
+
132
+ </body>
133
+ </html>