ncs_navigator_configuration 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -5,3 +5,5 @@ pkg/*
5
5
 
6
6
  .yardoc
7
7
  doc
8
+
9
+ reports
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm @ncs_config
@@ -1,6 +1,11 @@
1
1
  NCS Navigator Configuration gem history
2
2
  =======================================
3
3
 
4
+ 0.1.0
5
+ -----
6
+
7
+ - Ruby 1.9 compatibility.
8
+
4
9
  0.0.1
5
10
  -----
6
11
 
data/README.md CHANGED
@@ -33,8 +33,10 @@ file's sections and the second level the keys.
33
33
 
34
34
  In addition to the typed configuration properties available on
35
35
  `NcsNavigator::Configuration`, there are also three
36
- application-specific accessors: {#staff_portal, #core, and
37
- #psc}. These provide untyped direct access to the configuration
38
- properties in the respective sections of the INI file, allowing
39
- applications to define their own additional configuration properties
40
- without modifying this library.
36
+ application-specific accessors:
37
+ {NcsNavigator::Configuration#staff_portal #staff_portal},
38
+ {NcsNavigator::Configuration#core #core}, and
39
+ {NcsNavigator::Configuration#psc #psc}. These provide untyped direct
40
+ access to the configuration properties in the respective sections of
41
+ the INI file, allowing applications to define their own additional
42
+ configuration properties without modifying this library.
data/Rakefile CHANGED
@@ -1,7 +1,15 @@
1
1
  require 'bundler/gem_tasks'
2
2
 
3
3
  require 'rspec/core/rake_task'
4
+ require 'ci/reporter/rake/rspec'
4
5
 
5
6
  RSpec::Core::RakeTask.new do |t|
6
7
  t.pattern = "spec/**/*_spec.rb"
7
8
  end
9
+
10
+ namespace :ci do
11
+ ENV["CI_REPORTS"] = "reports/spec-xml"
12
+
13
+ desc "Run specs for CI"
14
+ task :spec => ['ci:setup:rspec', 'rake:spec']
15
+ end
@@ -0,0 +1,43 @@
1
+ #!/bin/bash -xe
2
+
3
+ BUNDLER_VERSION=1.0.18
4
+ GEMSET=ncs_config
5
+
6
+ if [ -z $CI_RUBY ]; then
7
+ echo "CI_RUBY must be set"
8
+ exit 1
9
+ fi
10
+
11
+ set +xe
12
+ echo "Initializing RVM"
13
+ source ~/.rvm/scripts/rvm
14
+ set -xe
15
+
16
+ # On the overnight build, reinstall all gems
17
+ if [ `date +%H` -lt 5 ]; then
18
+ set +xe
19
+ echo "Purging gemset to verify that all deps can still be installed"
20
+ rvm --force $CI_RUBY gemset delete $GEMSET
21
+ set -xe
22
+ fi
23
+
24
+ RVM_CONFIG="${CI_RUBY}@${GEMSET}"
25
+ set +xe
26
+ echo "Switching to ${RVM_CONFIG}"
27
+ rvm use $RVM_CONFIG
28
+ set -xe
29
+
30
+ which ruby
31
+ ruby -v
32
+
33
+ set +e
34
+ gem list -i bundler -v $BUNDLER_VERSION
35
+ if [ $? -ne 0 ]; then
36
+ set -e
37
+ gem install bundler -v $BUNDLER_VERSION
38
+ fi
39
+ set -e
40
+
41
+ bundle update
42
+
43
+ bundle exec rake ci:spec --trace
@@ -1,6 +1,5 @@
1
1
  require 'inifile'
2
2
  require 'pathname'
3
- require 'fastercsv'
4
3
  require 'uri'
5
4
 
6
5
  module NcsNavigator
@@ -75,6 +74,21 @@ module NcsNavigator
75
74
  attr_accessor name
76
75
  end
77
76
 
77
+ ##
78
+ # Defines an attribute that exposes the raw contents of a
79
+ # section.
80
+ #
81
+ # @param [#to_s] section_name the name of the section in the INI
82
+ # file.
83
+ # @param [#to_sym] accessor_name the name for the generated accessor.
84
+ #
85
+ # @return [void]
86
+ def section_accessor(section_name, accessor_name)
87
+ define_method accessor_name.to_sym do
88
+ @application_sections[section_name.to_s] ||= {}
89
+ end
90
+ end
91
+
78
92
  ##
79
93
  # @private used by instances, but not intended to be public.
80
94
  def configuration_attributes
@@ -232,6 +246,23 @@ module NcsNavigator
232
246
  # it. Defaults to false.
233
247
  configuration_attribute :smtp_starttls, 'SMTP', 'starttls', 'Boolean', :default => false
234
248
 
249
+ # While the following could be generated metaprogrammatically
250
+ # using APPLICATION_SECTIONS, they are unrolled for the benefit of
251
+ # YARD.
252
+
253
+ ##
254
+ # @macro [attach] section_accessor
255
+ # @method $2
256
+ #
257
+ # Exposes all the values from the [$1] section. This allows for
258
+ # flexibility in adding new options. The downside is that they are
259
+ # not automatically coerced or documented.
260
+ #
261
+ # @return [Hash<String, String>] the raw values from the [$1] section
262
+ section_accessor 'Staff Portal', :staff_portal
263
+ section_accessor 'Core', :core
264
+ section_accessor 'PSC', :psc
265
+
235
266
  ##
236
267
  # Creates a new Configuration.
237
268
  #
@@ -253,7 +284,7 @@ module NcsNavigator
253
284
  def init_from_ini(filename)
254
285
  if File.readable?(filename)
255
286
  @ini_filename = Pathname.new(filename)
256
- init_from_hash(IniFile.new(filename).to_h)
287
+ init_from_hash(IniFile.new(filename, :encoding => 'UTF-8').to_h)
257
288
  else
258
289
  raise Error.new("NCS Navigator configuration file #{filename.inspect} does not exist or is not readable.")
259
290
  end
@@ -304,7 +335,7 @@ module NcsNavigator
304
335
  raise Error.new("Could not read sampling units CSV #{sampling_units_file}")
305
336
  end
306
337
 
307
- FasterCSV.foreach(sampling_units_file, :headers => true) do |row|
338
+ faster_csv_class.foreach(sampling_units_file, :headers => true, :encoding => 'utf-8') do |row|
308
339
  psu = (psus[row['PSU_ID']] ||= PrimarySamplingUnit.new(row['PSU_ID']))
309
340
  area = (areas[row['AREA']] ||= SamplingUnitArea.new(row['AREA'], psu))
310
341
  ssu = (ssus[row['SSU_ID']] ||= SecondarySamplingUnit.new(row['SSU_ID'], row['SSU_NAME'], area))
@@ -345,18 +376,6 @@ module NcsNavigator
345
376
  end
346
377
  end
347
378
 
348
- APPLICATION_SECTIONS.each do |section|
349
- ##
350
- # Exposes all the values from the [#{section}] section. This
351
- # allows for flexibility in adding new options, with the downside
352
- # that they are not automatically coerced or documented.
353
- #
354
- # @return [Hash<String, String>]
355
- define_method section.downcase.gsub(' ', '_').to_sym do
356
- @application_sections[section] ||= {}
357
- end
358
- end
359
-
360
379
  ##
361
380
  # Provides a configuration hash suitable for passing to
362
381
  # `ActionMailer::Base.smtp_settings`.
@@ -376,6 +395,21 @@ module NcsNavigator
376
395
  ]
377
396
  end
378
397
 
398
+ ##
399
+ # @return [Class] the main class for FasterCSV-like behavior. On
400
+ # 1.9+, this is the built-in CSV lib.
401
+ def faster_csv_class
402
+ @faster_csv_class ||=
403
+ if RUBY_VERSION < '1.9'
404
+ require 'fastercsv'
405
+ FasterCSV
406
+ else
407
+ require 'csv'
408
+ CSV
409
+ end
410
+ end
411
+ private :faster_csv_class
412
+
379
413
  class Error < StandardError; end
380
414
  end
381
415
  end
@@ -1,5 +1,5 @@
1
1
  module NcsNavigator
2
2
  class Configuration
3
- VERSION = "0.0.1"
3
+ VERSION = '0.1.0'
4
4
  end
5
5
  end
@@ -26,5 +26,6 @@ Gem::Specification.new do |s|
26
26
  s.add_development_dependency 'rake', '~> 0.9.2'
27
27
  s.add_development_dependency 'rspec', '~> 2.6'
28
28
  s.add_development_dependency 'yard', '~> 0.7.2'
29
- s.add_development_dependency 'fakefs', '~> 0.3'
29
+ s.add_development_dependency 'fakefs', '~> 0.3.2'
30
+ s.add_development_dependency 'ci_reporter', '~> 1.6'
30
31
  end
@@ -49,7 +49,7 @@ sampling_units_file = "sample_ssus.csv"
49
49
 
50
50
  # The text that should appear in the center of the footer in Staff
51
51
  # Portal and Core. Line breaks in this text will be preserved.
52
- footer_text = "National Childrens Study - Greater Chicago Study Center
52
+ footer_text = "National Children's Study - Greater Chicago Study Center
53
53
  Institute for Healthcare Studies, Feinberg School of Medicine
54
54
  Northwestern University
55
55
  420 East Superior, 10th Floor
@@ -1,9 +1,13 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require File.expand_path('../../spec_helper', __FILE__)
2
3
 
3
4
  describe NcsNavigator do
4
5
  # Load the test INI into memory so it can be put into FakeFS
5
6
  let(:everything_file) { File.expand_path('../everything.ini', __FILE__) }
6
- let!(:everything_contents) { File.read(everything_file) }
7
+ let!(:everything_contents) {
8
+ opts = ({ :external_encoding => 'UTF-8' } if RUBY_VERSION > '1.9')
9
+ File.read(everything_file, opts)
10
+ }
7
11
 
8
12
  after do
9
13
  NcsNavigator.configuration = nil
@@ -13,6 +17,8 @@ describe NcsNavigator do
13
17
  include FakeFS::SpecHelpers
14
18
 
15
19
  before do
20
+ pending "FakeFS issue #93" if RUBY_VERSION > '1.9'
21
+
16
22
  File.open('/etc/nubic/ncs/navigator.ini', 'w') do |f|
17
23
  f.puts '[Study Center]'
18
24
  f.puts 'sc_id = 18'
@@ -25,7 +31,9 @@ describe NcsNavigator do
25
31
  f.puts 'uri = https://foo.example.com/psc'
26
32
  end
27
33
 
28
- File.open(everything_file, 'w') { |f| f.write everything_contents }
34
+ File.open(everything_file, RUBY_VERSION > '1.9' ? 'w:UTF-8' : 'w') { |f|
35
+ f.write everything_contents
36
+ }
29
37
  end
30
38
 
31
39
  it 'is read from /etc/nubic/ncs/navigator.ini' do
@@ -275,6 +283,12 @@ module NcsNavigator
275
283
  it 'preserves newlines' do
276
284
  subject.split(/\n/).size.should == 5
277
285
  end
286
+
287
+ if RUBY_VERSION > '1.9'
288
+ it 'can contain non-ASCII characters' do
289
+ subject.should =~ /’/
290
+ end
291
+ end
278
292
  end
279
293
 
280
294
  describe '#footer_center_html' do
metadata CHANGED
@@ -1,147 +1,120 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ncs_navigator_configuration
3
- version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 1
10
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Rhett Sutphin
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-08-24 00:00:00 -05:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2011-09-12 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: ncs_mdes
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2152457280 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
18
+ requirements:
27
19
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- - 4
33
- version: "0.4"
20
+ - !ruby/object:Gem::Version
21
+ version: '0.4'
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: inifile
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2152457280
25
+ - !ruby/object:Gem::Dependency
26
+ name: inifile
27
+ requirement: &2157337660 !ruby/object:Gem::Requirement
40
28
  none: false
41
- requirements:
29
+ requirements:
42
30
  - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 13
45
- segments:
46
- - 0
47
- - 4
48
- - 1
31
+ - !ruby/object:Gem::Version
49
32
  version: 0.4.1
50
33
  type: :runtime
51
- version_requirements: *id002
52
- - !ruby/object:Gem::Dependency
53
- name: fastercsv
54
34
  prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *2157337660
36
+ - !ruby/object:Gem::Dependency
37
+ name: fastercsv
38
+ requirement: &2157337200 !ruby/object:Gem::Requirement
56
39
  none: false
57
- requirements:
40
+ requirements:
58
41
  - - ~>
59
- - !ruby/object:Gem::Version
60
- hash: 5
61
- segments:
62
- - 1
63
- - 5
64
- version: "1.5"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.5'
65
44
  type: :runtime
66
- version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
68
- name: rake
69
45
  prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *2157337200
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &2157336740 !ruby/object:Gem::Requirement
71
50
  none: false
72
- requirements:
51
+ requirements:
73
52
  - - ~>
74
- - !ruby/object:Gem::Version
75
- hash: 63
76
- segments:
77
- - 0
78
- - 9
79
- - 2
53
+ - !ruby/object:Gem::Version
80
54
  version: 0.9.2
81
55
  type: :development
82
- version_requirements: *id004
83
- - !ruby/object:Gem::Dependency
84
- name: rspec
85
56
  prerelease: false
86
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *2157336740
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ requirement: &2157336280 !ruby/object:Gem::Requirement
87
61
  none: false
88
- requirements:
62
+ requirements:
89
63
  - - ~>
90
- - !ruby/object:Gem::Version
91
- hash: 15
92
- segments:
93
- - 2
94
- - 6
95
- version: "2.6"
64
+ - !ruby/object:Gem::Version
65
+ version: '2.6'
96
66
  type: :development
97
- version_requirements: *id005
98
- - !ruby/object:Gem::Dependency
99
- name: yard
100
67
  prerelease: false
101
- requirement: &id006 !ruby/object:Gem::Requirement
68
+ version_requirements: *2157336280
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: &2157335820 !ruby/object:Gem::Requirement
102
72
  none: false
103
- requirements:
73
+ requirements:
104
74
  - - ~>
105
- - !ruby/object:Gem::Version
106
- hash: 7
107
- segments:
108
- - 0
109
- - 7
110
- - 2
75
+ - !ruby/object:Gem::Version
111
76
  version: 0.7.2
112
77
  type: :development
113
- version_requirements: *id006
114
- - !ruby/object:Gem::Dependency
78
+ prerelease: false
79
+ version_requirements: *2157335820
80
+ - !ruby/object:Gem::Dependency
115
81
  name: fakefs
82
+ requirement: &2157335360 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 0.3.2
88
+ type: :development
116
89
  prerelease: false
117
- requirement: &id007 !ruby/object:Gem::Requirement
90
+ version_requirements: *2157335360
91
+ - !ruby/object:Gem::Dependency
92
+ name: ci_reporter
93
+ requirement: &2157334900 !ruby/object:Gem::Requirement
118
94
  none: false
119
- requirements:
95
+ requirements:
120
96
  - - ~>
121
- - !ruby/object:Gem::Version
122
- hash: 13
123
- segments:
124
- - 0
125
- - 3
126
- version: "0.3"
97
+ - !ruby/object:Gem::Version
98
+ version: '1.6'
127
99
  type: :development
128
- version_requirements: *id007
129
- description: "\n An internal component of the NCS Navigator suite, this gem provides a common view\n onto shared configuration elements.\n "
130
- email:
100
+ prerelease: false
101
+ version_requirements: *2157334900
102
+ description: ! "\n An internal component of the NCS Navigator suite, this gem provides
103
+ a common view\n onto shared configuration elements.\n "
104
+ email:
131
105
  - r-sutphin@northwestern.edu
132
106
  executables: []
133
-
134
107
  extensions: []
135
-
136
108
  extra_rdoc_files: []
137
-
138
- files:
109
+ files:
139
110
  - .gitignore
111
+ - .rvmrc
140
112
  - .yardopts
141
113
  - CHANGELOG.md
142
114
  - Gemfile
143
115
  - README.md
144
116
  - Rakefile
117
+ - ci-exec.sh
145
118
  - lib/ncs_navigator/configuration.rb
146
119
  - lib/ncs_navigator/configuration/sampling_units.rb
147
120
  - lib/ncs_navigator/configuration/version.rb
@@ -153,41 +126,31 @@ files:
153
126
  - spec/ncs_navigator/everything.ini
154
127
  - spec/ncs_navigator/no_tsus.csv
155
128
  - spec/spec_helper.rb
156
- has_rdoc: true
157
- homepage: ""
129
+ homepage: ''
158
130
  licenses: []
159
-
160
131
  post_install_message:
161
132
  rdoc_options: []
162
-
163
- require_paths:
133
+ require_paths:
164
134
  - lib
165
- required_ruby_version: !ruby/object:Gem::Requirement
135
+ required_ruby_version: !ruby/object:Gem::Requirement
166
136
  none: false
167
- requirements:
168
- - - ">="
169
- - !ruby/object:Gem::Version
170
- hash: 3
171
- segments:
172
- - 0
173
- version: "0"
174
- required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
142
  none: false
176
- requirements:
177
- - - ">="
178
- - !ruby/object:Gem::Version
179
- hash: 3
180
- segments:
181
- - 0
182
- version: "0"
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
183
147
  requirements: []
184
-
185
148
  rubyforge_project:
186
- rubygems_version: 1.3.7
149
+ rubygems_version: 1.8.6
187
150
  signing_key:
188
151
  specification_version: 3
189
152
  summary: Common configuration elements for the NCS Navigator suite
190
- test_files:
153
+ test_files:
191
154
  - spec/ncs_navigator/configuration/version_spec.rb
192
155
  - spec/ncs_navigator/configuration_spec.rb
193
156
  - spec/ncs_navigator/every_su.csv