rulebook 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (9) hide show
  1. data/Gemfile.lock +14 -12
  2. data/Rakefile +0 -23
  3. data/VERSION +1 -1
  4. data/examples/simple.rb +14 -3
  5. data/rulebook.gemspec +47 -76
  6. metadata +30 -106
  7. data/.document +0 -5
  8. data/Gemfile +0 -7
  9. data/README.md +0 -152
data/Gemfile.lock CHANGED
@@ -1,21 +1,23 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rulebook (0.4.1)
5
+ meta_tools (= 0.2.1)
6
+
1
7
  GEM
8
+ remote: http://rubygems.org/
2
9
  specs:
3
- git (1.2.5)
4
- jeweler (1.5.2)
5
- bundler (~> 1.0.0)
6
- git (>= 1.2.5)
7
- rake
8
- meta_tools (0.1.0)
9
- rake (0.8.7)
10
- riot (0.12.3)
10
+ meta_tools (0.2.1)
11
+ rake (0.9.2)
12
+ riot (0.12.4)
11
13
  rr
12
14
  rr (1.0.2)
13
15
 
14
16
  PLATFORMS
17
+ ruby
15
18
  x86-mingw32
16
19
 
17
20
  DEPENDENCIES
18
- jeweler
19
- meta_tools
20
- rake
21
- riot
21
+ rake (= 0.9.2)
22
+ riot (= 0.12.4)
23
+ rulebook!
data/Rakefile CHANGED
@@ -1,10 +1,5 @@
1
1
  require 'rubygems'
2
2
 
3
- # Gay as hell jeweler workaround
4
-
5
- require 'psych'
6
- YAML::ENGINE.yamler = 'psych'
7
-
8
3
  require 'bundler'
9
4
  begin
10
5
  Bundler.setup(:default, :development)
@@ -15,24 +10,6 @@ rescue Bundler::BundlerError => e
15
10
  end
16
11
  require 'rake'
17
12
 
18
- require 'jeweler'
19
- Jeweler::Tasks.new do |gem|
20
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
21
- gem.name = "rulebook"
22
- gem.homepage = "http://github.com/c00lryguy/rulebook"
23
- gem.license = "MIT"
24
- gem.summary = %Q{Define methods with regex for dynamic methods.}
25
- gem.description = %Q{Allows you to define a set of 'rules' or dynamic methods to apply to a class.}
26
- gem.email = "c00lryguy@gmail.com"
27
- gem.authors = ["Ryan Lewis"]
28
- # Include your dependencies below. Runtime dependencies are required when using your gem,
29
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
30
- gem.add_runtime_dependency 'meta_tools', '> 0.1'
31
- gem.add_development_dependency 'rake', '> 0.0.0'
32
- gem.add_development_dependency 'riot', '> 0.0.0'
33
- end
34
- Jeweler::RubygemsDotOrgTasks.new
35
-
36
13
  require 'rake/testtask'
37
14
 
38
15
  Rake::TestTask.new(:test) do |t|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
data/examples/simple.rb CHANGED
@@ -20,8 +20,8 @@ class User
20
20
  end
21
21
 
22
22
  class << self
23
- metaclass.follows_the_rules!
24
- metaclass.rulebook.add /^new_(admin|user)$/ do |title|
23
+ follows_the_rules!
24
+ rulebook.add /^new_(admin|user)$/ do |title|
25
25
  instance = new
26
26
  instance.instance_eval { @title = title.to_sym }
27
27
  instance
@@ -40,4 +40,15 @@ p u.is_user? # => false
40
40
  p u.is_admin? # => true
41
41
 
42
42
  u = User.new_admin
43
- p u.is_admin? # => true
43
+ p u.is_admin? # => true
44
+
45
+
46
+ # DEV: TODO CLASS RULES O_O
47
+ Integer.follows_the_rules!
48
+ Integer.rulebook.add /to_base_(\d+)/ do |base|
49
+ p base
50
+ p "OMG"
51
+ to_s(base)
52
+ end
53
+
54
+ p 10.to_base_16
data/rulebook.gemspec CHANGED
@@ -1,81 +1,52 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
1
  Gem::Specification.new do |s|
7
- s.name = %q{rulebook}
8
- s.version = "0.4.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Ryan Lewis"]
12
- s.date = %q{2011-04-30}
13
- s.description = %q{Allows you to define a set of 'rules' or dynamic methods to apply to a class.}
14
- s.email = %q{c00lryguy@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.md"
18
- ]
19
- s.files = [
20
- ".document",
21
- "Gemfile",
22
- "Gemfile.lock",
23
- "LICENSE",
24
- "README.md",
25
- "Rakefile",
26
- "VERSION",
27
- "examples/simple.rb",
28
- "lib/rulebook.rb",
29
- "lib/rulebook/class_methods.rb",
30
- "lib/rulebook/core_ext/module.rb",
31
- "lib/rulebook/instance_methods.rb",
32
- "lib/rulebook/rule.rb",
33
- "rulebook.gemspec",
34
- "test/helper.rb",
35
- "test/test_chevy.rb",
36
- "test/test_rule.rb"
37
- ]
38
- s.homepage = %q{http://github.com/c00lryguy/rulebook}
39
- s.licenses = ["MIT"]
2
+ s.author = "Ryan Scott Lewis"
3
+ s.email = "c00lryguy@gmail.com"
4
+ s.homepage = "http://github.com/c00lryguy/rulebook"
5
+
6
+ s.description = "Allows you to define a set of 'rules' or dynamic methods to apply to a class."
7
+ s.summary = "Define methods with regex for dynamic methods."
8
+
40
9
  s.require_paths = ["lib"]
41
- s.rubygems_version = %q{1.3.7}
42
- s.summary = %q{Define methods with regex for dynamic methods.}
43
- s.test_files = [
44
- "examples/simple.rb",
45
- "test/helper.rb",
46
- "test/test_chevy.rb",
47
- "test/test_rule.rb"
48
- ]
49
-
50
- if s.respond_to? :specification_version then
51
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
- s.specification_version = 3
53
-
54
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
- s.add_runtime_dependency(%q<meta_tools>, [">= 0"])
56
- s.add_development_dependency(%q<rake>, [">= 0"])
57
- s.add_development_dependency(%q<riot>, [">= 0"])
58
- s.add_development_dependency(%q<jeweler>, [">= 0"])
59
- s.add_runtime_dependency(%q<meta_tools>, ["> 0.1"])
60
- s.add_development_dependency(%q<rake>, ["> 0.0.0"])
61
- s.add_development_dependency(%q<riot>, ["> 0.0.0"])
10
+
11
+ s.name = File.basename(__FILE__, ".gemspec")
12
+ s.version = File.read("VERSION")
13
+ # VERSIONING
14
+ # Some people like to use a YAML file to display the version, some like CSV,
15
+ # others might just add a constant set to a version string, some (Rack) might
16
+ # even have an array splitting the version into parts.
17
+ # Just edit the above line appropriately.
18
+ # An easy thing to do is set a constant within your app to a version string
19
+ # and use it in here
20
+
21
+ # Add directories you *might* use in ALL projects.
22
+ s.files = [File.basename(__FILE__)] + Dir['lib/**/*'] + Dir['bin/**/*'] + Dir['test/**/*'] + Dir['examples/**/*']
23
+
24
+ # Add files you *might* use in ALL projects!
25
+ %W{Gemfile.lock README.* README Rakefile VERSION LICENSE}.each do |file|
26
+ s.files.unshift(file) if File.exists?(file)
27
+ end
28
+
29
+ # Add files you *might* use in ALL projects!
30
+ %W{README.* README VERSION LICENSE LICENSE.*}.each do |file|
31
+ (s.extra_rdoc_files ||= []).unshift(file) if File.exists?(file)
32
+ end
33
+
34
+ # s.executables = ["bin/myapp.rb"]
35
+
36
+ # If you only specify one application file in executables, that file becomes
37
+ # the default executable. Therefore, you only need to specify this value if you
38
+ # have more than one application file.
39
+ if s.executables.length > 1
40
+ if exe = s.executables.find { |e| e.include?(File.basename(__FILE__, ".gemspec")) }
41
+ s.default_executable = exe
62
42
  else
63
- s.add_dependency(%q<meta_tools>, [">= 0"])
64
- s.add_dependency(%q<rake>, [">= 0"])
65
- s.add_dependency(%q<riot>, [">= 0"])
66
- s.add_dependency(%q<jeweler>, [">= 0"])
67
- s.add_dependency(%q<meta_tools>, ["> 0.1"])
68
- s.add_dependency(%q<rake>, ["> 0.0.0"])
69
- s.add_dependency(%q<riot>, ["> 0.0.0"])
43
+ raise(Exception, "Couldn't automatically figure out the default_executable")
70
44
  end
71
- else
72
- s.add_dependency(%q<meta_tools>, [">= 0"])
73
- s.add_dependency(%q<rake>, [">= 0"])
74
- s.add_dependency(%q<riot>, [">= 0"])
75
- s.add_dependency(%q<jeweler>, [">= 0"])
76
- s.add_dependency(%q<meta_tools>, ["> 0.1"])
77
- s.add_dependency(%q<rake>, ["> 0.0.0"])
78
- s.add_dependency(%q<riot>, ["> 0.0.0"])
79
45
  end
80
- end
81
-
46
+
47
+ s.test_files = Dir['test/**/*'] + Dir['examples/**/*']
48
+
49
+ s.add_dependency("meta_tools", "0.2.1")
50
+ s.add_development_dependency("rake", "0.9.2")
51
+ s.add_development_dependency("riot", "0.12.4")
52
+ end
metadata CHANGED
@@ -1,117 +1,50 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rulebook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
5
- segments:
6
- - 0
7
- - 4
8
- - 0
9
- prerelease: false
4
+ version: 0.4.1
5
+ prerelease:
10
6
  platform: ruby
11
7
  authors:
12
- - Ryan Lewis
13
- autorequire: !!null
8
+ - Ryan Scott Lewis
9
+ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
- date: 2011-04-30 00:00:00.000000000 -04:00
17
- default_executable: !!null
12
+ date: 2011-06-26 00:00:00.000000000 -04:00
13
+ default_executable:
18
14
  dependencies:
19
15
  - !ruby/object:Gem::Dependency
20
16
  name: meta_tools
21
- requirement: &31472964 !ruby/object:Gem::Requirement
17
+ requirement: &2164532960 !ruby/object:Gem::Requirement
22
18
  none: false
23
19
  requirements:
24
- - - ! '>='
20
+ - - =
25
21
  - !ruby/object:Gem::Version
26
- version: '0'
27
- segments:
28
- - 0
22
+ version: 0.2.1
29
23
  type: :runtime
30
24
  prerelease: false
31
- version_requirements: *31472964
25
+ version_requirements: *2164532960
32
26
  - !ruby/object:Gem::Dependency
33
27
  name: rake
34
- requirement: &31472496 !ruby/object:Gem::Requirement
28
+ requirement: &2168595200 !ruby/object:Gem::Requirement
35
29
  none: false
36
30
  requirements:
37
- - - ! '>='
31
+ - - =
38
32
  - !ruby/object:Gem::Version
39
- version: '0'
40
- segments:
41
- - 0
33
+ version: 0.9.2
42
34
  type: :development
43
35
  prerelease: false
44
- version_requirements: *31472496
36
+ version_requirements: *2168595200
45
37
  - !ruby/object:Gem::Dependency
46
38
  name: riot
47
- requirement: &31472040 !ruby/object:Gem::Requirement
48
- none: false
49
- requirements:
50
- - - ! '>='
51
- - !ruby/object:Gem::Version
52
- version: '0'
53
- segments:
54
- - 0
55
- type: :development
56
- prerelease: false
57
- version_requirements: *31472040
58
- - !ruby/object:Gem::Dependency
59
- name: jeweler
60
- requirement: &31471572 !ruby/object:Gem::Requirement
61
- none: false
62
- requirements:
63
- - - ! '>='
64
- - !ruby/object:Gem::Version
65
- version: '0'
66
- segments:
67
- - 0
68
- type: :development
69
- prerelease: false
70
- version_requirements: *31471572
71
- - !ruby/object:Gem::Dependency
72
- name: meta_tools
73
- requirement: &31471092 !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ! '>'
77
- - !ruby/object:Gem::Version
78
- version: '0.1'
79
- segments:
80
- - 0
81
- - 1
82
- type: :runtime
83
- prerelease: false
84
- version_requirements: *31471092
85
- - !ruby/object:Gem::Dependency
86
- name: rake
87
- requirement: &31470552 !ruby/object:Gem::Requirement
39
+ requirement: &2169056920 !ruby/object:Gem::Requirement
88
40
  none: false
89
41
  requirements:
90
- - - ! '>'
42
+ - - =
91
43
  - !ruby/object:Gem::Version
92
- version: 0.0.0
93
- segments:
94
- - 0
95
- - 0
96
- - 0
44
+ version: 0.12.4
97
45
  type: :development
98
46
  prerelease: false
99
- version_requirements: *31470552
100
- - !ruby/object:Gem::Dependency
101
- name: riot
102
- requirement: &31470000 !ruby/object:Gem::Requirement
103
- none: false
104
- requirements:
105
- - - ! '>'
106
- - !ruby/object:Gem::Version
107
- version: 0.0.0
108
- segments:
109
- - 0
110
- - 0
111
- - 0
112
- type: :development
113
- prerelease: false
114
- version_requirements: *31470000
47
+ version_requirements: *2169056920
115
48
  description: Allows you to define a set of 'rules' or dynamic methods to apply to
116
49
  a class.
117
50
  email: c00lryguy@gmail.com
@@ -119,30 +52,26 @@ executables: []
119
52
  extensions: []
120
53
  extra_rdoc_files:
121
54
  - LICENSE
122
- - README.md
55
+ - VERSION
123
56
  files:
124
- - .document
125
- - Gemfile
126
- - Gemfile.lock
127
57
  - LICENSE
128
- - README.md
129
- - Rakefile
130
58
  - VERSION
131
- - examples/simple.rb
132
- - lib/rulebook.rb
59
+ - Rakefile
60
+ - Gemfile.lock
61
+ - rulebook.gemspec
133
62
  - lib/rulebook/class_methods.rb
134
63
  - lib/rulebook/core_ext/module.rb
135
64
  - lib/rulebook/instance_methods.rb
136
65
  - lib/rulebook/rule.rb
137
- - rulebook.gemspec
66
+ - lib/rulebook.rb
138
67
  - test/helper.rb
139
68
  - test/test_chevy.rb
140
69
  - test/test_rule.rb
70
+ - examples/simple.rb
141
71
  has_rdoc: true
142
72
  homepage: http://github.com/c00lryguy/rulebook
143
- licenses:
144
- - MIT
145
- post_install_message: !!null
73
+ licenses: []
74
+ post_install_message:
146
75
  rdoc_options: []
147
76
  require_paths:
148
77
  - lib
@@ -152,25 +81,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
81
  - - ! '>='
153
82
  - !ruby/object:Gem::Version
154
83
  version: '0'
155
- segments:
156
- - 0
157
- hash: 224911955
158
84
  required_rubygems_version: !ruby/object:Gem::Requirement
159
85
  none: false
160
86
  requirements:
161
87
  - - ! '>='
162
88
  - !ruby/object:Gem::Version
163
89
  version: '0'
164
- segments:
165
- - 0
166
90
  requirements: []
167
- rubyforge_project: !!null
168
- rubygems_version: 1.3.7
169
- signing_key: !!null
91
+ rubyforge_project:
92
+ rubygems_version: 1.6.2
93
+ signing_key:
170
94
  specification_version: 3
171
95
  summary: Define methods with regex for dynamic methods.
172
96
  test_files:
173
- - examples/simple.rb
174
97
  - test/helper.rb
175
98
  - test/test_chevy.rb
176
99
  - test/test_rule.rb
100
+ - examples/simple.rb
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.md
2
- lib/**/*.rb
3
- bin/*
4
- test/**/*.rb
5
- LICENSE
data/Gemfile DELETED
@@ -1,7 +0,0 @@
1
- gem 'meta_tools'
2
-
3
- group :development do
4
- gem 'rake'
5
- gem 'riot'
6
- gem 'jeweler'
7
- end
data/README.md DELETED
@@ -1,152 +0,0 @@
1
- # rulebook ![](http://stillmaintained.com/c00lryguy/rulebook.png)
2
-
3
- Allows you to define a set of 'rules' or dynamic methods to apply to a class.
4
-
5
- ## Install
6
-
7
- > gem update --system
8
- > gem install rulebook
9
-
10
- ## Simple Example
11
-
12
- require 'rulebook'
13
-
14
- class User
15
- follows_the_rules!
16
-
17
- def initialize(name)
18
- @name = name
19
- end
20
-
21
- rulebook.add /say_(.+)/ do |what_to_say|
22
- puts "#{@name} says '#{what_to_say.gsub(/_/, ' ')}'"
23
- end
24
- end
25
-
26
- User.new('Ryan').say_hello_world # => Ryan says 'hello world'
27
-
28
- ## How It Works
29
-
30
- TODO
31
-
32
- ## Better Example
33
-
34
- require 'rulebook'
35
-
36
- class User
37
- attr :name, :title
38
-
39
- def initialize(name)
40
- @name = name
41
- @title = :user
42
- end
43
-
44
- rulebook.add /is_(admin|moderator|super_user|user)/ do |title|
45
- @title = title.to_sym
46
- end
47
- end
48
-
49
- You can now do things like
50
-
51
- users = ['Ryan', 'Natale', 'Kasey', 'Jenna', 'Joe', 'Monica','Allan', 'Amanda']
52
- users.collect! { |n| User.new(n) }.shuffle!
53
-
54
- users[0].is_admin
55
- users[1].is_moderator
56
- users[2].is_super_user
57
-
58
- users.each do |user|
59
- puts "#{user.name} is a #{user.title}"
60
- end
61
-
62
- ## Class Methods Example
63
-
64
- require 'rulebook'
65
-
66
- class Car
67
- attr :make, :model
68
-
69
- def initialize(make, model)
70
- @make, @model = make.capitalize, model.capitalize
71
- end
72
-
73
- class << self
74
- follows_the_rules!
75
-
76
- rulebook.add /new_([a-z]+)_(.+)/ do |make, model|
77
- new(make, model)
78
- end
79
- end
80
- end
81
-
82
- my_cars = [
83
- Car.new_honda_accord,
84
- Car.new_dodge_neon,
85
- Car.new_volkswagen_beetle
86
- ]
87
-
88
- p my_cars.first.make # => "Honda"
89
- p my_cars.first.model # => "Accord"
90
-
91
- This works out if you already have ``
92
-
93
- ### Now lets add some instance rules
94
-
95
- class Car
96
- rule /is_(.+)\?/ do |make_or_model|
97
- make_or_model.capitalize!
98
- @make == make_or_model || @model == make_or_model
99
- end
100
- end
101
-
102
- p my_cars.first.is_honda? # => true
103
- p my_cars.first.is_beetle? # => false
104
-
105
- ## Using outside of class block
106
-
107
- Since `rule` and `class_rule` are both class methods,
108
- you can call them all outside of a class block:
109
-
110
- Car.rule(...){}
111
- Car.class_rule(...){}
112
-
113
- Since 0.2 you can call the class methods `rules` and `class_rules` to wrap your rules in a block:
114
-
115
- Car.rules do
116
- rule(...){}
117
- end
118
-
119
- Car.class_rules do
120
- rule(...){}
121
- end
122
-
123
- The result is exactly the same. These are also callable from inside the class.
124
-
125
- class Car
126
- rules do
127
- rule(...){}
128
- end
129
- class_rules do
130
- rule(...){}
131
- end
132
- end
133
-
134
- #### There are more examples in the examples and [test][1] directories and [Rubular][2] is a great place to test your Regexp.
135
-
136
- ## Note on Patches/Pull Requests
137
-
138
- * Fork the project.
139
- * Make your feature addition or bug fix.
140
- * Add tests for it. This is important so I don't break it in a
141
- future version unintentionally.
142
- * Commit, do not mess with rakefile, version, or history.
143
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
144
- * Send me a pull request. Bonus points for topic branches.
145
-
146
- ## Copyright
147
-
148
- Copyright (c) 2010 Ryan Lewis. See LICENSE for details.
149
-
150
-
151
- [1]: http://github.com/c00lryguy/rulebook/tree/master/test/
152
- [2]: http://rubular.com/