myrrha 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ # 1.2.0 / 2011-08-15
2
+
3
+ * Added the ability to created SByC domains through simple module extension:
4
+
5
+ NegInt = Myrrha.domain(Integer){|i| i < 0}
6
+
7
+ can also be built the following way:
8
+
9
+ class NegInt < Integer
10
+ extend Myrrha::Domain
11
+
12
+ def self.predicate
13
+ @predicate ||= lambda{|i| i < 0}
14
+ end
15
+
16
+ end
17
+
18
+ * Cleaned the development dependencies, travis-ci.org continuous integration,
19
+ and ruby.noe template.
20
+
1
21
  # 1.1.0 / 2011-07-28
2
22
 
3
23
  ## Enhancements to coerce()
data/Gemfile CHANGED
@@ -1,2 +1,18 @@
1
1
  source 'http://rubygems.org'
2
- gemspec :name => "myrrha"
2
+
3
+ group :test do
4
+ gem "rake", "~> 0.9.2"
5
+ gem "rspec", "~> 2.6.0"
6
+ end
7
+
8
+ group :release do
9
+ gem "rake", "~> 0.9.2"
10
+ gem "rspec", "~> 2.6.0"
11
+ gem "wlang", "~> 0.10.1"
12
+ end
13
+
14
+ group :doc do
15
+ gem "yard", "~> 0.7.2"
16
+ gem "bluecloth", "~> 2.1.0"
17
+ end
18
+
data/Gemfile.lock CHANGED
@@ -1,19 +1,8 @@
1
- PATH
2
- remote: .
3
- specs:
4
- myrrha (1.1.0)
5
-
6
1
  GEM
7
2
  remote: http://rubygems.org/
8
3
  specs:
9
4
  bluecloth (2.1.0)
10
5
  diff-lcs (1.1.2)
11
- highline (1.6.2)
12
- noe (1.3.0)
13
- highline (~> 1.6.0)
14
- quickl (~> 0.2.0)
15
- wlang (~> 0.10.1)
16
- quickl (0.2.2)
17
6
  rake (0.9.2)
18
7
  rspec (2.6.0)
19
8
  rspec-core (~> 2.6.0)
@@ -32,9 +21,6 @@ PLATFORMS
32
21
 
33
22
  DEPENDENCIES
34
23
  bluecloth (~> 2.1.0)
35
- bundler (~> 1.0)
36
- myrrha!
37
- noe (~> 1.3.0)
38
24
  rake (~> 0.9.2)
39
25
  rspec (~> 2.6.0)
40
26
  wlang (~> 0.10.1)
data/README.md CHANGED
@@ -17,7 +17,7 @@ a numeric, a boolean, a date, a time, an URI, and so on.
17
17
  # Bug fixes (tiny) do not even add new default rules to coerce and
18
18
  # to\_ruby\_literal. Minor version can, which could break your code.
19
19
  # Therefore, please always use:
20
- gem "myrrha", "~> 1.0.0"
20
+ gem "myrrha", "~> 1.1.0"
21
21
 
22
22
  ## Links
23
23
 
@@ -456,6 +456,15 @@ reasoning on types and value:
456
456
  # and correctly fails in each case!
457
457
  rules.coerce("-12", Integer) # => -12
458
458
  rules.coerce("-12", PosInt) # => ArgumentError, "Invalid value -12 for PosInt"
459
-
460
-
461
-
459
+
460
+ Note that if you want to provide additional tooling to your factored domain,
461
+ the following way of creating them also works:
462
+
463
+ class PosInt < Integer
464
+ extend Myrrha::Domain
465
+
466
+ def self.predicate
467
+ @predicate ||= lambda{|i| i > 0}
468
+ end
469
+
470
+ end
data/lib/myrrha.rb CHANGED
@@ -18,8 +18,8 @@ module Myrrha
18
18
  def self.domain(superdom = Object, subdoms=nil, &pred)
19
19
  dom = Class.new(superdom).extend(Domain)
20
20
  dom.instance_eval {
21
- @sub_domains = subdoms
22
- @super_domain = superdom
21
+ @subdomains = subdoms
22
+ @superdomain = superdom
23
23
  @predicate = pred
24
24
  }
25
25
  dom
@@ -66,14 +66,14 @@ module Myrrha
66
66
 
67
67
  # (see Class.superclass)
68
68
  def superclass
69
- @super_domain
69
+ superdomain || super
70
70
  end
71
71
 
72
72
  #
73
- # Checks if `value` belongs to this domain
74
- #
75
- def ===(value)
76
- (superclass === value) && @predicate.call(value)
73
+ # Returns the super domain if installed
74
+ #
75
+ def superdomain
76
+ @superdomain
77
77
  end
78
78
 
79
79
  #
@@ -81,7 +81,14 @@ module Myrrha
81
81
  # case in Ruby.
82
82
  #
83
83
  def superdomain_of?(child)
84
- Array(@sub_domains).include?(child)
84
+ Array(@subdomains).include?(child)
85
+ end
86
+
87
+ #
88
+ # Checks if `value` belongs to this domain
89
+ #
90
+ def ===(value)
91
+ (superclass === value) && predicate.call(value)
85
92
  end
86
93
 
87
94
  #
@@ -2,7 +2,7 @@ module Myrrha
2
2
  module Version
3
3
 
4
4
  MAJOR = 1
5
- MINOR = 1
5
+ MINOR = 2
6
6
  TINY = 0
7
7
 
8
8
  def self.to_s
data/myrrha.gemspec CHANGED
@@ -21,13 +21,13 @@ Gem::Specification.new do |s|
21
21
  # A short summary of this gem
22
22
  #
23
23
  # This is displayed in `gem list -d`.
24
- s.summary = "Myrrha provides the coercion framework which is missing to Ruby, IMHO."
24
+ s.summary = "Myrrha provides the coercion framework which is missing to Ruby."
25
25
 
26
26
  # A long description of this gem (required)
27
27
  #
28
28
  # The description should be more detailed than the summary. For example,
29
29
  # you might wish to copy the entire README into the description.
30
- s.description = "Myrrha provides the coercion framework which is missing to Ruby, IMHO. Coercions\nare simply defined as a set of rules for converting values from source to target\ndomains (in an abstract sense). As a typical and useful example, it comes bundled\nwith a coerce() method providing a unique entry point for converting a string to \na numeric, a boolean, a date, a time, an URI, and so on. "
30
+ s.description = "Myrrha provides the coercion framework which is missing to Ruby. Coercions\nare simply defined as a set of rules for converting values from source to target\ndomains (in an abstract sense). As a typical and useful example, it comes with \na coerce() method providing a unique entry point for converting a string to \na numeric, a boolean, a date, a time, an URI, and so on. "
31
31
 
32
32
  # The URL of this gem home page (optional)
33
33
  s.homepage = "http://rubydoc.info/github/blambeau/myrrha/master/frames"
@@ -124,12 +124,10 @@ Gem::Specification.new do |s|
124
124
  # for each development dependency. These gems are required for developers
125
125
  #
126
126
  s.add_development_dependency("rake", "~> 0.9.2")
127
- s.add_development_dependency("bundler", "~> 1.0")
128
127
  s.add_development_dependency("rspec", "~> 2.6.0")
129
128
  s.add_development_dependency("yard", "~> 0.7.2")
130
129
  s.add_development_dependency("bluecloth", "~> 2.1.0")
131
130
  s.add_development_dependency("wlang", "~> 0.10.1")
132
- s.add_development_dependency("noe", "~> 1.3.0")
133
131
 
134
132
 
135
133
  # The version of ruby required by this gem
data/myrrha.noespec CHANGED
@@ -3,20 +3,23 @@
3
3
  template-info:
4
4
  name: "ruby"
5
5
  version: 1.3.0
6
+ manifest:
7
+ tasks/debug_mail.txt:
8
+ safe-override: false
6
9
  variables:
7
10
  lower:
8
11
  myrrha
9
12
  upper:
10
13
  Myrrha
11
14
  version:
12
- 1.1.0
15
+ 1.2.0
13
16
  summary: |-
14
- Myrrha provides the coercion framework which is missing to Ruby, IMHO.
17
+ Myrrha provides the coercion framework which is missing to Ruby.
15
18
  description: |-
16
- Myrrha provides the coercion framework which is missing to Ruby, IMHO. Coercions
19
+ Myrrha provides the coercion framework which is missing to Ruby. Coercions
17
20
  are simply defined as a set of rules for converting values from source to target
18
- domains (in an abstract sense). As a typical and useful example, it comes bundled
19
- with a coerce() method providing a unique entry point for converting a string to
21
+ domains (in an abstract sense). As a typical and useful example, it comes with
22
+ a coerce() method providing a unique entry point for converting a string to
20
23
  a numeric, a boolean, a date, a time, an URI, and so on.
21
24
  authors:
22
25
  - {name: Bernard Lambeau, email: blambeau@gmail.com}
@@ -25,13 +28,13 @@ variables:
25
28
  - http://github.com/blambeau/myrrha
26
29
  - http://rubygems.org/gems/myrrha
27
30
  dependencies:
28
- - {name: rake, version: "~> 0.9.2", groups: [development]}
29
- - {name: bundler, version: "~> 1.0", groups: [development]}
30
- - {name: rspec, version: "~> 2.6.0", groups: [development]}
31
- - {name: yard, version: "~> 0.7.2", groups: [development]}
32
- - {name: bluecloth, version: "~> 2.1.0", groups: [development]}
33
- - {name: wlang, version: "~> 0.10.1", groups: [development]}
34
- - {name: noe, version: "~> 1.3.0", groups: [development]}
31
+ - {name: rake, version: "~> 0.9.2", groups: [test, release]}
32
+ - {name: rspec, version: "~> 2.6.0", groups: [test, release]}
33
+ - {name: yard, version: "~> 0.7.2", groups: [doc ]}
34
+ - {name: bluecloth, version: "~> 2.1.0", groups: [doc ]}
35
+ - {name: wlang, version: "~> 0.10.1", groups: [release ]}
35
36
  rake_tasks:
37
+ debug_mail:
38
+ rx_changelog_sections: /^# /
36
39
  spec_test:
37
- pattern: spec/**/test_*.rb
40
+ pattern: spec/**/test_*.rb
@@ -48,6 +48,43 @@ module Myrrha
48
48
  end
49
49
  end
50
50
 
51
+ describe "A factored domain by module inclusion" do
52
+ class NegInt < Integer
53
+ extend Myrrha::Domain
54
+
55
+ def self.predicate
56
+ @predicate ||= lambda{|i| i<0}
57
+ end
58
+
59
+ end
60
+ specify("#name") {
61
+ NegInt.name.should eq("Myrrha::NegInt")
62
+ }
63
+ specify("#new") {
64
+ NegInt.new(-12).should eq(-12)
65
+ lambda {
66
+ NegInt.new(12)
67
+ }.should raise_error(ArgumentError)
68
+ }
69
+ specify("#superclass"){
70
+ NegInt.superclass.should eql(Integer)
71
+ }
72
+ specify("#superdomain_of?"){
73
+ NegInt.superdomain_of?(Object).should be_false
74
+ NegInt.superdomain_of?(Integer).should be_false
75
+ }
76
+ it "should be usable in a case" do
77
+ [-12, 12].collect{|i|
78
+ case i
79
+ when NegInt
80
+ :negint
81
+ when Integer
82
+ :integer
83
+ end
84
+ }.should eq([:negint, :integer])
85
+ end
86
+ end
87
+
51
88
  describe "A factored sub domain of a user-defined Class" do
52
89
  class Color
53
90
  attr_reader :r
data/spec/spec_helper.rb CHANGED
@@ -5,29 +5,28 @@ require 'myrrha/to_ruby_literal'
5
5
  require 'date'
6
6
  require 'shared/a_value'
7
7
 
8
- unless defined?(SAFE_VALUES)
9
- SAFE_VALUES = {
10
- NilClass => [ nil ],
11
- TrueClass => [ true ],
12
- FalseClass => [ false ],
13
- Fixnum => [ -(2**(0.size * 8 - 2)), -1, 0, 1, 10, (2**(0.size * 8 - 2) - 1)],
14
- Bignum => [ -(2**(0.size * 8 - 2)) - 1, (2**(0.size * 8 - 2)) ],
15
- Float => [ -0.10, 0.0, 0.10 ],
16
- String => ['', 'hello'],
17
- Symbol => [ :hello, :"s-b-y-c", :"12" ],
18
- Class => [ Integer, ::Struct::Tms ],
19
- Module => [ Kernel, Myrrha ],
20
- Regexp => [ /a-z/, /^$/, /\s*/, /[a-z]{15}/ ],
21
- Range => [ 0..10, 0...10 ],
22
- Array => [ [], [nil], [1, "hello"] ],
23
- Hash => [ {}, {1 => 2, :hello => "world"} ]
24
- }
25
- UNSAFE_VALUES = {
26
- Date => [ Date.today ],
27
- Time => [ Time.now ],
28
- Array => [ [Date.today, Time.now] ],
29
- Hash => [ {Date.today => Time.now} ],
30
- Range => [ Date.today..(Date.today+1) ]
31
- }
32
- VALUES = SAFE_VALUES.values.inject([], :+) + UNSAFE_VALUES.values.inject([], :+)
33
- end
8
+ $SAFE_VALUES = {
9
+ NilClass => [ nil ],
10
+ TrueClass => [ true ],
11
+ FalseClass => [ false ],
12
+ Fixnum => [ -(2**(0.size * 8 - 2)), -1, 0, 1, 10, (2**(0.size * 8 - 2) - 1)],
13
+ Bignum => [ -(2**(0.size * 8 - 2)) - 1, (2**(0.size * 8 - 2)) ],
14
+ Float => [ -0.10, 0.0, 0.10 ],
15
+ String => ['', 'hello'],
16
+ Symbol => [ :hello, :"s-b-y-c", :"12" ],
17
+ Class => [ Integer, ::Struct::Tms ],
18
+ Module => [ Kernel, Myrrha ],
19
+ Regexp => [ /a-z/, /^$/, /\s*/, /[a-z]{15}/ ],
20
+ Range => [ 0..10, 0...10 ],
21
+ Array => [ [], [nil], [1, "hello"] ],
22
+ Hash => [ {}, {1 => 2, :hello => "world"} ]
23
+ }
24
+ $UNSAFE_VALUES = {
25
+ Date => [ Date.today ],
26
+ Time => [ Time.now ],
27
+ Array => [ [Date.today, Time.now] ],
28
+ Hash => [ {Date.today => Time.now} ],
29
+ Range => [ Date.today..(Date.today+1) ]
30
+ }
31
+ $VALUES = $SAFE_VALUES.values.inject([], :+) +
32
+ $UNSAFE_VALUES.values.inject([], :+)
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  describe "to_ruby_literal" do
3
3
 
4
- VALUES.each do |value|
4
+ $VALUES.each do |value|
5
5
  describe "on #{value.inspect}" do
6
6
  specify{ Kernel.eval(value.to_ruby_literal).should eq(value) }
7
7
  end
data/spec/test_value.rb CHANGED
@@ -1,4 +1,5 @@
1
- VALUES.each do |value|
1
+ require 'spec_helper'
2
+ $VALUES.each do |value|
2
3
  describe "#{value} (#{value.class})" do
3
4
  subject{ value }
4
5
  it_should_behave_like "a value"
@@ -56,7 +56,7 @@ begin
56
56
  # Load interesting changesets
57
57
  changes, end_found = [], 0
58
58
  File.readlines(logs.first).select{|line|
59
- if line =~ /^#/
59
+ if line =~ /^# /
60
60
  break if end_found >= 1
61
61
  end_found += 1
62
62
  end
data/tasks/examples.rake CHANGED
@@ -1,7 +1,8 @@
1
1
  task :examples do
2
+ lib = File.expand_path('../../lib', __FILE__)
2
3
  dir = File.expand_path('../../examples', __FILE__)
3
4
  Dir["#{dir}/*.rb"].each do |file|
4
- str = `ruby #{file}`
5
+ str = `ruby -I#{lib} #{file}`
5
6
  if $?.exitstatus == 0
6
7
  print '.'
7
8
  else
data/tasks/unit_test.rake CHANGED
@@ -45,7 +45,7 @@ begin
45
45
  t.warning = false
46
46
 
47
47
  # Glob pattern to match test files. (default is 'test/test*.rb')
48
- t.pattern = "test/test*.rb"
48
+ t.pattern = "test/test_*.rb"
49
49
 
50
50
  # Style of test loader to use. Options are:
51
51
  #
@@ -68,7 +68,7 @@ begin
68
68
  end
69
69
  rescue LoadError => ex
70
70
  task :unit_test do
71
- abort 'rspec is not available. In order to run spec, you must: gem install rspec'
71
+ abort "rake/testtask does not seem available...\n #{ex.message}"
72
72
  end
73
73
  ensure
74
74
  desc "Run all tests"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myrrha
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-28 00:00:00.000000000Z
12
+ date: 2011-08-15 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &85576310 !ruby/object:Gem::Requirement
16
+ requirement: &85166390 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,21 +21,10 @@ dependencies:
21
21
  version: 0.9.2
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *85576310
25
- - !ruby/object:Gem::Dependency
26
- name: bundler
27
- requirement: &85575520 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ~>
31
- - !ruby/object:Gem::Version
32
- version: '1.0'
33
- type: :development
34
- prerelease: false
35
- version_requirements: *85575520
24
+ version_requirements: *85166390
36
25
  - !ruby/object:Gem::Dependency
37
26
  name: rspec
38
- requirement: &85574670 !ruby/object:Gem::Requirement
27
+ requirement: &85166110 !ruby/object:Gem::Requirement
39
28
  none: false
40
29
  requirements:
41
30
  - - ~>
@@ -43,10 +32,10 @@ dependencies:
43
32
  version: 2.6.0
44
33
  type: :development
45
34
  prerelease: false
46
- version_requirements: *85574670
35
+ version_requirements: *85166110
47
36
  - !ruby/object:Gem::Dependency
48
37
  name: yard
49
- requirement: &85573700 !ruby/object:Gem::Requirement
38
+ requirement: &85165560 !ruby/object:Gem::Requirement
50
39
  none: false
51
40
  requirements:
52
41
  - - ~>
@@ -54,10 +43,10 @@ dependencies:
54
43
  version: 0.7.2
55
44
  type: :development
56
45
  prerelease: false
57
- version_requirements: *85573700
46
+ version_requirements: *85165560
58
47
  - !ruby/object:Gem::Dependency
59
48
  name: bluecloth
60
- requirement: &85572820 !ruby/object:Gem::Requirement
49
+ requirement: &85165280 !ruby/object:Gem::Requirement
61
50
  none: false
62
51
  requirements:
63
52
  - - ~>
@@ -65,10 +54,10 @@ dependencies:
65
54
  version: 2.1.0
66
55
  type: :development
67
56
  prerelease: false
68
- version_requirements: *85572820
57
+ version_requirements: *85165280
69
58
  - !ruby/object:Gem::Dependency
70
59
  name: wlang
71
- requirement: &85550940 !ruby/object:Gem::Requirement
60
+ requirement: &85164980 !ruby/object:Gem::Requirement
72
61
  none: false
73
62
  requirements:
74
63
  - - ~>
@@ -76,23 +65,12 @@ dependencies:
76
65
  version: 0.10.1
77
66
  type: :development
78
67
  prerelease: false
79
- version_requirements: *85550940
80
- - !ruby/object:Gem::Dependency
81
- name: noe
82
- requirement: &85550220 !ruby/object:Gem::Requirement
83
- none: false
84
- requirements:
85
- - - ~>
86
- - !ruby/object:Gem::Version
87
- version: 1.3.0
88
- type: :development
89
- prerelease: false
90
- version_requirements: *85550220
91
- description: ! "Myrrha provides the coercion framework which is missing to Ruby, IMHO.
92
- Coercions\nare simply defined as a set of rules for converting values from source
93
- to target\ndomains (in an abstract sense). As a typical and useful example, it comes
94
- bundled\nwith a coerce() method providing a unique entry point for converting a
95
- string to \na numeric, a boolean, a date, a time, an URI, and so on. "
68
+ version_requirements: *85164980
69
+ description: ! "Myrrha provides the coercion framework which is missing to Ruby. Coercions\nare
70
+ simply defined as a set of rules for converting values from source to target\ndomains
71
+ (in an abstract sense). As a typical and useful example, it comes with \na coerce()
72
+ method providing a unique entry point for converting a string to \na numeric, a
73
+ boolean, a date, a time, an URI, and so on. "
96
74
  email:
97
75
  - blambeau@gmail.com
98
76
  executables: []
@@ -167,22 +145,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
167
145
  version: '0'
168
146
  segments:
169
147
  - 0
170
- hash: -900430961
148
+ hash: 140841041
171
149
  required_rubygems_version: !ruby/object:Gem::Requirement
172
150
  none: false
173
151
  requirements:
174
152
  - - ! '>='
175
153
  - !ruby/object:Gem::Version
176
154
  version: '0'
177
- segments:
178
- - 0
179
- hash: -900430961
180
155
  requirements: []
181
156
  rubyforge_project:
182
157
  rubygems_version: 1.8.6
183
158
  signing_key:
184
159
  specification_version: 3
185
- summary: Myrrha provides the coercion framework which is missing to Ruby, IMHO.
160
+ summary: Myrrha provides the coercion framework which is missing to Ruby.
186
161
  test_files:
187
162
  - spec/spec_helper.rb
188
163
  - spec/myrrha/test_coercions.rb