methodic 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/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+ gem "yard-rspec"
3
+ gem "rspec", :require => "spec"
4
+ gem "rake"
5
+ gem "yard"
6
+ gem "rdoc"
7
+ gem "rcov"
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ json (1.6.5)
6
+ rake (0.9.2.2)
7
+ rcov (1.0.0)
8
+ rdoc (3.12)
9
+ json (~> 1.4)
10
+ rspec (2.9.0)
11
+ rspec-core (~> 2.9.0)
12
+ rspec-expectations (~> 2.9.0)
13
+ rspec-mocks (~> 2.9.0)
14
+ rspec-core (2.9.0)
15
+ rspec-expectations (2.9.0)
16
+ diff-lcs (~> 1.1.3)
17
+ rspec-mocks (2.9.0)
18
+ yard (0.7.5)
19
+ yard-rspec (0.1)
20
+ yard
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ rake
27
+ rcov
28
+ rdoc
29
+ rspec
30
+ yard
31
+ yard-rspec
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+
3
+ require 'rspec'
4
+ require 'rake'
5
+ require "rake/clean"
6
+ require "rubygems/package_task"
7
+ require "rdoc/task"
8
+ require 'code_statistics'
9
+ require 'rspec/core/rake_task'
10
+ require 'yard'
11
+ require 'yard/rake/yardoc_task.rb'
12
+
13
+
14
+ CLEAN.include('*.tmp','*.old')
15
+ CLOBBER.include('*.tmp', 'build/*','#*#')
16
+
17
+
18
+ content = File::readlines(File.join(File.dirname(__FILE__), 'methodic.gemspec')).join
19
+ spec = eval(content)
20
+
21
+ RSpec::Core::RakeTask.new('spec')
22
+
23
+
24
+
25
+ YARD::Rake::YardocTask.new do |t|
26
+ t.files = [ 'lib/**/*.rb', '-', 'doc/**/*','spec/**/*_spec.rb']
27
+ t.options += ['--title', "Gem Documentation"]
28
+ t.options += ['-o', "yardoc"]
29
+ t.options += ['-r', "doc/manual.rdoc"]
30
+ end
31
+ YARD::Config.load_plugin('yard-rspec')
32
+
33
+ namespace :yardoc do
34
+ task :clobber do
35
+ rm_r "yardoc" rescue nil
36
+ rm_r ".yardoc" rescue nil
37
+ end
38
+ end
39
+ task :clobber => "yardoc:clobber"
40
+
41
+
42
+ Gem::PackageTask.new(spec) do |pkg|
43
+ pkg.need_tar = true
44
+ pkg.need_zip = true
45
+ end
46
+
47
+ Rake::RDocTask.new('rdoc') do |d|
48
+ d.rdoc_files.include('doc/**/*','bin/*')
49
+ d.main = 'doc/manual.rdoc'
50
+ d.title = 'Uglibs : Ultragreen libraries'
51
+ d.options << '--line-numbers' << '--diagram' << '-SHN'
52
+ end
53
+
54
+ task :default => [:gem]
data/doc/manual.rdoc ADDED
@@ -0,0 +1 @@
1
+ =Methodic
data/lib/methodic.rb ADDED
@@ -0,0 +1,90 @@
1
+
2
+ module Methodic
3
+ class Options < Hash
4
+
5
+ attr_accessor :classes
6
+ attr_accessor :mandatories
7
+ attr_accessor :defaults
8
+ attr_accessor :formats
9
+
10
+ def initialize(_options = {})
11
+ self.replace _options
12
+ @defaults = Hash::new
13
+ @formats = Hash::new
14
+ @classes = Hash::new
15
+ @mandatories = Array::new
16
+ end
17
+
18
+ def options
19
+ return @classes.keys
20
+ end
21
+
22
+ def specify_default_value_of(values)
23
+ @defaults.merge! values
24
+ end
25
+ alias :specify_defaults_values_of :specify_default_value_of
26
+
27
+ def specify_class_of(values)
28
+ @classes.merge! values
29
+ end
30
+ alias :specify_classes_of :specify_class_of
31
+
32
+ def specify_presence_of(values)
33
+ @mandatories << values
34
+ @mandatories.flatten!
35
+ end
36
+ alias :specify_presences_of :specify_presence_of
37
+
38
+ def specify_format_of(values)
39
+ @formats.merge! values
40
+ end
41
+ alias :specify_formats_of :specify_format_of
42
+
43
+ def specify_condition_for
44
+ raise NotYetImplemented
45
+ end
46
+ alias :specify_conditions_for :specify_condition_for
47
+
48
+ def merge_with_defaults
49
+ self.replace(@defaults.merge self)
50
+ end
51
+
52
+ def validate
53
+ table = []
54
+ table.push validate_options_and_classes unless @classes.empty?
55
+ table.push validate_formats unless @formats.empty?
56
+ table.push validate_presences unless @mandatories.empty?
57
+ return true unless table.include?(false)
58
+ end
59
+ alias :validate! :validate
60
+
61
+ private
62
+ def validate_formats
63
+ self.each do |option,value|
64
+ if @formats.key? option then
65
+ raise ArgumentError::new("Option : #{option} don't match /#{@formats[option]}/") and return false unless value =~ @formats[option]
66
+ end
67
+ end
68
+
69
+ return true
70
+ end
71
+
72
+ def validate_presences
73
+ @mandatories.each do |mdt|
74
+ raise ArgumentError::new("Missing option : #{mdt}") and return false unless self.include?(mdt)
75
+ end
76
+ return true
77
+ end
78
+
79
+ def validate_options_and_classes
80
+ self.each do |option,value|
81
+ raise ArgumentError::new("Unknown option : #{option}") and return fasle unless @classes.include?(option)
82
+ raise ArgumentError::new("Option : #{option} type mismatch must be a #{@classes[option]}") and return false unless value.class == @classes[option]
83
+ end
84
+ return true
85
+ end
86
+ end
87
+ def Methodic::get_options(_options = {})
88
+ return Methodic::Options::new(_options)
89
+ end
90
+ end
data/methodic.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{methodic}
3
+ s.author = "Romain GEORGES"
4
+ s.version = "0.2"
5
+ s.date = %q{2012-03-21}
6
+ s.summary = %q{Methodic : Hash table options specification and validation componant}
7
+ s.email = %q{romain@ultragreen.net}
8
+ s.homepage = %q{http://www.ultragreen.net}
9
+ s.description = %q{Methodic : provide Hash table options arguments manager (specifications and validations}
10
+ s.has_rdoc = true
11
+ s.files = Dir['*/*/*/*'] + Dir['*/*/*'] + Dir['*/*'] + Dir['*']
12
+ s.bindir = nil
13
+ s.required_ruby_version = '>= 1.8.1'
14
+ s.add_development_dependency "rspec", ">= 2.0.0"
15
+ s.rdoc_options << '--title' << 'Methodic : Ge�m documentation' << '--main' << 'doc/manual.rdoc' << '--line-numbers' << '--diagram'
16
+ s.rubyforge_project = "nowarning"
17
+ end
data/spec/init_spec.rb ADDED
@@ -0,0 +1 @@
1
+ require "spec_helper"
@@ -0,0 +1,11 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: methodic
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ version: "0.2"
10
+ platform: ruby
11
+ authors:
12
+ - Romain GEORGES
13
+ autorequire:
14
+ bindir:
15
+ cert_chain: []
16
+
17
+ date: 2012-03-21 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 15
29
+ segments:
30
+ - 2
31
+ - 0
32
+ - 0
33
+ version: 2.0.0
34
+ type: :development
35
+ version_requirements: *id001
36
+ description: "Methodic : provide Hash table options arguments manager (specifications and validations"
37
+ email: romain@ultragreen.net
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - doc/manual.rdoc
46
+ - lib/methodic.rb
47
+ - spec/init_spec.rb
48
+ - spec/spec_helper.rb
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - methodic.gemspec
52
+ - Rakefile
53
+ has_rdoc: true
54
+ homepage: http://www.ultragreen.net
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options:
59
+ - --title
60
+ - "Methodic : Ge\xC3m documentation"
61
+ - --main
62
+ - doc/manual.rdoc
63
+ - --line-numbers
64
+ - --diagram
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 53
73
+ segments:
74
+ - 1
75
+ - 8
76
+ - 1
77
+ version: 1.8.1
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ requirements: []
88
+
89
+ rubyforge_project: nowarning
90
+ rubygems_version: 1.4.2
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: "Methodic : Hash table options specification and validation componant"
94
+ test_files: []
95
+