option_list 1.1.1 → 1.1.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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDlkMWJhNDU5YmJmODU0N2IyMmEyZjNiYjcxZTc4MTI4NmJkY2RlMA==
4
+ NzA5ZjFjNWY2ZDQ0NTQxN2Q3MTIxYTU1N2VmYjMwYTE3YjAzYTdlYw==
5
5
  data.tar.gz: !binary |-
6
- MTZiNTIxY2M0MzcyM2Q4NGNiN2E5NDcyNDY2ZWVjYjI3MjM3NDE0Zg==
6
+ NzE3MmExNWM1ZDZmZDUxYjhhMTY2YmMwMDhiMzk0M2UzZGYwMWRiNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZmUzZDYyM2MyYTBjYzVhMDQ4MjFkNDZjOWE4MmFlN2ZmMTQyNmU0MjQ3MWJm
10
- YWE1ZjE0N2YyZmNmZWRhNGNlNTJmMmIxYjBlODAyZWQ2NmQwMjUzZDE4Yjk2
11
- YjJlNWY4M2JjY2EyMTcwMmFiZTA1MDY2MTkxNzZjMTZkMTVmNjI=
9
+ NWQzOTA3YTgyYjkyZTUyNWNjYTE2NDg0MDZmNzQwM2I0NWQzMmNiOTc4ZTNh
10
+ ZjUyN2I5NTM1MDFlOWE0NzY3NmYxMmMxZDhiNTQ3OGZkY2JjN2I3NjhjZjlm
11
+ NjMyYjNiM2Q1NGNjOTZkYjRlMzAzNDhlYjNhMGE1ZGY5NzMxZDk=
12
12
  data.tar.gz: !binary |-
13
- Yzk2OTZjNDBhYWMzNDFhNzFlZWQ5OTAxOTUwNzcxZDFhZDI3NjhiMjIzYjFh
14
- MGIxZmFjY2M3OGNlYjdmMGYzMmMxZDRjZjIzYjFmOWU2YTUyYzYwYWI1MDI4
15
- YTllOGEzYTI5ZWQzZDM0YjIyYWVlZDE1ZTJmOTBhMGFkZGYzZWU=
13
+ M2JiOWFhNDgyZWJiY2UwYWFmMzI0ZjE4YWMyZDE4MzgzNzAxOTA3NWI4Yzk0
14
+ MTE4ZjFlYmZmMmNkMDdjZDk2MjljZmY1ZGMxYTgyNWE3YWFiMThlYWY2OWRj
15
+ NjVlMDlkNzBjZWFlZGYwYTk2OGJjYjhlNTRhNjU5OTlhMDg1ZjU=
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.bat
2
+ *.zip
3
+ *.tmp
4
+ *.gem
5
+ *.rbc
6
+ .bundle
7
+ .config
8
+ .yardoc
9
+ Gemfile.lock
10
+ InstalledFiles
11
+ _yardoc
12
+ coverage
13
+ doc/
14
+ lib/bundler/man
15
+ pkg
16
+ rdoc
17
+ spec/reports
18
+ test/tmp
19
+ test/version_tmp
20
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in option_list.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # The Option List gem.
2
+
3
+ This gem implements the concept that parameter validation is long and
4
+ tedious and something needed to be done about that. This gem implements
5
+ the idea that parameters be described separately and validated in a
6
+ single line of client method code.
7
+
8
+ This gem was my first effort in the area of gem creation, and if I'm
9
+ honest, it is rather doubtful that it brings much to the table. Most
10
+ of what it does has been subsumed by the Ruby Language itself, starting
11
+ with version 1.9 and further through versions 2.0, 2.1, and 2.2.
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'option_list'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install option_list
24
+
25
+ ## Usage
26
+
27
+ The use of option_list oocurs in three phases: Describing the Parameters,
28
+ Passing in Parameters and Validating/Accessing the Parameters. This can be
29
+ seen in the following example:
30
+
31
+ module ReadLine
32
+ #Create the parameter specification (simplified for brevity)
33
+ @spec = OptionList.new([:buffer, :history, :no_history], {:depth => 50}) do |options|
34
+ fail "Depth must be an integer" unless options.depth.is_a(Integer)
35
+ fail "Depth must be positive" if options.depth < 1
36
+ end
37
+
38
+ class << self
39
+ attr_reader :spec
40
+ end
41
+
42
+ def read_line(prompt, *options)
43
+ @options = ReadLine.spec.select(options)
44
+ #Further code deleted for brevity.
45
+ #Somewhere along the line it records the last line.
46
+ buffer_line(current_line)
47
+ current_line
48
+ end
49
+
50
+ def buffer_line(line)
51
+ @line_buffer << line if @options.history?
52
+ @line_buffer.delete_at(0) if @line_buffer.length > @options.depth
53
+ end
54
+ end
55
+
56
+ The option_list gem is described in the The option_list User's Guide
57
+ which covers version 1.1.1 which has no material change from 1.1.2
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create new Pull Request
data/docs/OL_UG.odt ADDED
Binary file
data/docs/OL_UG.pdf ADDED
Binary file
Binary file
@@ -0,0 +1,3 @@
1
+ class OptionList
2
+ VERSION = '1.1.2'
3
+ end
data/lib/option_list.rb CHANGED
@@ -11,24 +11,24 @@ require 'set'
11
11
  #Embraced reek and git and created the user's guide to pair down rdoc mark up
12
12
  #to be less obtrusive to the code.
13
13
  #=== Version 1.1.0
14
- #Added a default value of false to signify that no default exists for a
14
+ #Added a default value of false to signify that no default exists for a
15
15
  #mandatory parameter.
16
16
  #Modified processing of array specs to avoid side effects in the parameters.
17
17
  class OptionList
18
18
 
19
19
  #The option list code version.
20
20
  def self.version
21
- '1.1.1'
21
+ OptionList::VERSION
22
22
  end
23
-
23
+
24
24
  #The option list code version. This is a redirect to the class method.
25
25
  def version
26
- self.class.version
26
+ OptionList::VERSION
27
27
  end
28
28
 
29
- #Create an option list from an array of option specifications.
29
+ #Create an option list from an array of option specifications.
30
30
  #==== Parameters:
31
- #* option_specs - The comma separated option specifications, made into an
31
+ #* option_specs - The comma separated option specifications, made into an
32
32
  # array by the splat operator.
33
33
  #* select_block - An optional block of code that is called when selections
34
34
  # have been made. This allows for custom validations to be applied at that
@@ -41,7 +41,7 @@ class OptionList
41
41
  @mandatory = Array.new
42
42
  @categories = Hash.new
43
43
  @default = Hash.new
44
-
44
+
45
45
  option_specs.each do |spec|
46
46
  if spec.is_a?(Hash)
47
47
  hash_spec(spec)
@@ -51,7 +51,7 @@ class OptionList
51
51
  error "Found #{spec.class} instead of Hash or Array."
52
52
  end
53
53
  end
54
-
54
+
55
55
  @select_block = select_block
56
56
  end
57
57
 
@@ -66,26 +66,26 @@ class OptionList
66
66
  #==== Exceptions:
67
67
  #* ArgumentError for a number of invalid argument conditions.
68
68
  #==== Notes:
69
- #After processing the selections, the selection validation block is called
69
+ #After processing the selections, the selection validation block is called
70
70
  #if one was defined for the constructor.
71
71
  def select(selections=[])
72
72
  selections = [selections] unless selections.is_a?(Array)
73
73
  selected = process_selections(selections)
74
-
74
+
75
75
  @mandatory.each do |cat|
76
76
  error "Missing mandatory setting #{cat}" unless selected[cat]
77
77
  end
78
-
78
+
79
79
  @select_block.call(selected) if @select_block
80
80
  selected
81
81
  end
82
-
82
+
83
83
  private #Private stuff follows.
84
84
 
85
85
  #Process a list of option selections.
86
86
  def process_selections(selections)
87
87
  selected, dup = @default.clone, Set.new
88
-
88
+
89
89
  selections.each do |opt|
90
90
  if opt.is_a?(Symbol)
91
91
  symbolic_selection(opt, selected, dup)
@@ -95,15 +95,15 @@ class OptionList
95
95
  error "Found #{opt.class} instead of Hash or Symbol."
96
96
  end
97
97
  end
98
-
98
+
99
99
  selected
100
100
  end
101
-
101
+
102
102
  #Return a internal category marker constant for value entries.
103
103
  def value_entry
104
104
  'A value entry.'
105
105
  end
106
-
106
+
107
107
  #Process an array spec that lists all the valid values for an option. See
108
108
  #the new method for more information on these specs.
109
109
  def array_spec(spec)
@@ -113,15 +113,15 @@ class OptionList
113
113
  array_spec_default(category, default)
114
114
  array_spec_tail_rest(category, spec[2...spec_len])
115
115
  end
116
-
117
- #Process the first element of the array spec tail.
116
+
117
+ #Process the first element of the array spec tail.
118
118
  def array_spec_default(category, opt)
119
119
  opt && array_spec_single(category, opt)
120
120
  @default[category] = opt
121
121
  @mandatory << category if opt == false
122
122
  end
123
-
124
- #Process the rest of the array spec tail.
123
+
124
+ #Process the rest of the array spec tail.
125
125
  def array_spec_tail_rest(category, spec_tail_rest)
126
126
  spec_tail_rest.each do |opt|
127
127
  if opt
@@ -131,14 +131,14 @@ class OptionList
131
131
  end
132
132
  end
133
133
  end
134
-
134
+
135
135
  #Process a single array spec option
136
136
  def array_spec_single(category, opt)
137
137
  duplicate_entry_check(@categories, opt, 'option')
138
138
  @categories[opt] = category
139
139
  add_option_tester(category, opt)
140
140
  end
141
-
141
+
142
142
  #Process a hash spec that lists only the default value for an option. See
143
143
  #the new method for more information on these specs.
144
144
  def hash_spec(spec)
@@ -150,13 +150,13 @@ class OptionList
150
150
  @mandatory << category if value == false
151
151
  end
152
152
  end
153
-
153
+
154
154
  #Set the default value of a value entry.
155
155
  def set_default_option_value(category, value)
156
156
  @categories[category] = value_entry
157
- @default[category] = value
157
+ @default[category] = value
158
158
  end
159
-
159
+
160
160
  #Process a symbolic option selection.
161
161
  #==== Parameters:
162
162
  #* option - a symbol to process.
@@ -168,7 +168,7 @@ class OptionList
168
168
  hash_option_dup_check(category, dup)
169
169
  selected[category] = symbol_option
170
170
  end
171
-
171
+
172
172
  #Process a hash of option selection values.
173
173
  #==== Parameters:
174
174
  #* options - a hash of options to process.
@@ -183,7 +183,7 @@ class OptionList
183
183
  selected[category] = value
184
184
  end
185
185
  end
186
-
186
+
187
187
  #Validate a hash option value.
188
188
  def hash_option_value_check(value_category, value)
189
189
  if (@categories[value_category] != value_entry) && value
@@ -191,12 +191,12 @@ class OptionList
191
191
  error "Invalid option: #{value}." unless @categories[value] == value_category
192
192
  end
193
193
  end
194
-
195
- #Add to set with no duplicates allowed.
194
+
195
+ #Add to set with no duplicates allowed.
196
196
  def hash_option_dup_check(category, dup)
197
197
  error "Category #{category} has multiple values." unless dup.add?(category)
198
198
  end
199
-
199
+
200
200
  #Add query method for the selected category.
201
201
  def add_option_reader(name)
202
202
  duplicate_entry_check(@default, name, 'category')
@@ -208,13 +208,13 @@ class OptionList
208
208
  qry = (value.to_s + '?').to_sym
209
209
  @default.define_singleton_method(qry) { self[target] == value}
210
210
  end
211
-
211
+
212
212
  #Flag any duplicate entry errors.
213
213
  def duplicate_entry_check(target, entry, detail)
214
- error "Found #{entry.class}, expected Symbol." unless entry.is_a?(Symbol)
214
+ error "Found #{entry.class}, expected Symbol." unless entry.is_a?(Symbol)
215
215
  error "Duplicate #{detail}: #{entry}" if target.has_key?(entry)
216
216
  end
217
-
217
+
218
218
  #Flag any missing entry errors.
219
219
  def missing_entry_check(target, entry, detail)
220
220
  error "Unknown #{detail}: #{entry}" unless target.has_key?(entry)
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+
3
+ #Specify the building of the option_list gem.
4
+
5
+ lib = File.expand_path('../lib', __FILE__)
6
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
+ require 'option_list/version'
8
+
9
+ Gem::Specification.new do |s|
10
+ s.name = "option_list"
11
+ s.summary = "Flexible, Easy Function Parameters with Validation."
12
+ s.description = 'Flexible, Easy Function Parameters with Validation. '
13
+ s.version = OptionList::VERSION
14
+ s.author = ["Peter Camilleri"]
15
+ s.email = "peter.c.camilleri@gmail.com"
16
+ s.homepage = "http://teuthida-technologies.com/"
17
+ s.platform = Gem::Platform::RUBY
18
+ s.required_ruby_version = '>=1.9.3'
19
+
20
+ s.add_development_dependency "bundler", "~> 1.3"
21
+ s.add_development_dependency 'rake'
22
+ s.add_development_dependency 'reek', "~> 1.3.8"
23
+ s.add_development_dependency 'minitest', "~> 4.7.5"
24
+ s.add_development_dependency 'rdoc', "~> 4.0.1"
25
+ s.add_development_dependency 'awesome_print'
26
+
27
+ s.files = `git ls-files`.split($/)
28
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
29
+ s.extra_rdoc_files = ['license.txt']
30
+
31
+ s.license = 'MIT'
32
+ s.has_rdoc = true
33
+ s.require_path = 'lib'
34
+ end
35
+
data/rakefile.rb CHANGED
@@ -1,11 +1,16 @@
1
1
  #!/usr/bin/env rake
2
+ # coding: utf-8
3
+
2
4
  require 'rake/testtask'
3
5
  require 'rdoc/task'
6
+ require "bundler/gem_tasks"
4
7
 
5
8
  RDoc::Task.new do |rdoc|
6
9
  rdoc.rdoc_dir = "rdoc"
7
- #rdoc.main = "option_list.rb"
8
- rdoc.rdoc_files = ['lib/option_list.rb', 'license.txt']
10
+
11
+ #List out all the files to be documented.
12
+ rdoc.rdoc_files.include("lib/**/*.rb", "license.txt", "README.md")
13
+
9
14
  rdoc.options << '--visibility' << 'private'
10
15
  end
11
16
 
@@ -14,6 +19,13 @@ Rake::TestTask.new do |t|
14
19
  t.verbose = false
15
20
  end
16
21
 
22
+ desc "Run a scan for smelly code!"
17
23
  task :reek do |t|
18
24
  `reek lib\\*.rb > reek.txt`
19
25
  end
26
+
27
+ desc "What version of option_list is this?"
28
+ task :vers do |t|
29
+ puts
30
+ puts "option_list version = #{OptionList::VERSION}"
31
+ end
data/sire.rb ADDED
@@ -0,0 +1,51 @@
1
+ # Really simple program # 3
2
+ # A Simple Interactive Ruby Environment
3
+ # SIRE Version 0.2.6
4
+
5
+ require 'readline'
6
+ require 'awesome_print'
7
+ require_relative 'lib/option_list'
8
+ include Readline
9
+
10
+ class Object
11
+ def classes
12
+ begin
13
+ klass = self
14
+
15
+ begin
16
+ klass = klass.class unless klass.instance_of?(Class)
17
+ print klass
18
+ klass = klass.superclass
19
+ print " < " if klass
20
+ end while klass
21
+
22
+ puts
23
+ end
24
+ end
25
+ end
26
+
27
+ def show_args(*args)
28
+ args
29
+ end
30
+
31
+ puts "Welcome to SIRE Version 0.2.6"
32
+ puts "Simple Interactive Ruby Environment"
33
+ done = false
34
+
35
+ until done
36
+ begin
37
+ line = readline('SIRE>', true)
38
+ result = eval line
39
+ ap result unless result.nil?
40
+ rescue Interrupt
41
+ done = true
42
+ rescue Exception => e
43
+ puts "#{e.class} detected: #{e}"
44
+ puts e.backtrace
45
+ puts
46
+ end
47
+ end
48
+
49
+ puts
50
+ puts "Bye bye for now!"
51
+
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: option_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Camilleri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-10 00:00:00.000000000 Z
11
+ date: 2014-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rake
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -28,30 +42,44 @@ dependencies:
28
42
  name: reek
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ! '>='
45
+ - - ~>
32
46
  - !ruby/object:Gem::Version
33
- version: '0'
47
+ version: 1.3.8
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ! '>='
52
+ - - ~>
39
53
  - !ruby/object:Gem::Version
40
- version: '0'
54
+ version: 1.3.8
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: minitest
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ! '>='
59
+ - - ~>
46
60
  - !ruby/object:Gem::Version
47
- version: '0'
61
+ version: 4.7.5
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ! '>='
66
+ - - ~>
53
67
  - !ruby/object:Gem::Version
54
- version: '0'
68
+ version: 4.7.5
69
+ - !ruby/object:Gem::Dependency
70
+ name: rdoc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 4.0.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 4.0.1
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: awesome_print
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -73,12 +101,20 @@ extensions: []
73
101
  extra_rdoc_files:
74
102
  - license.txt
75
103
  files:
104
+ - .gitignore
105
+ - Gemfile
106
+ - README.md
107
+ - docs/OL_UG.odt
108
+ - docs/OL_UG.pdf
109
+ - docs/OL_UG_Version_1_1_1.pdf
76
110
  - lib/option_list.rb
77
- - tests/option_list_test.rb
78
- - rakefile.rb
111
+ - lib/option_list/version.rb
79
112
  - license.txt
80
- - README
113
+ - option_list.gemspec
114
+ - rakefile.rb
81
115
  - reek.txt
116
+ - sire.rb
117
+ - tests/option_list_test.rb
82
118
  homepage: http://teuthida-technologies.com/
83
119
  licenses:
84
120
  - MIT
@@ -103,5 +139,5 @@ rubygems_version: 2.1.4
103
139
  signing_key:
104
140
  specification_version: 4
105
141
  summary: Flexible, Easy Function Parameters with Validation.
106
- test_files:
107
- - tests/option_list_test.rb
142
+ test_files: []
143
+ has_rdoc: true
data/README DELETED
@@ -1,3 +0,0 @@
1
- This project contains the Ruby OptionList gem. A gem used to facilitate the
2
- passing of complex parameter options with validation and checking and
3
- minimal effort on the part of the caller and the callee.