dsl 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ *.gemspec
2
+ package\*
3
+ .DS_Store
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use --create ruby-1.9.3@dsl
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'guard-rspec'
7
+ gem 'fuubar'
8
+ gem 'at'
9
+ end
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dsl (0.1.4)
5
+ version (~> 1.0.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ active_support (3.0.0)
11
+ activesupport (= 3.0.0)
12
+ activesupport (3.0.0)
13
+ at (0.1.2)
14
+ active_support (~> 3.0.0)
15
+ coderay (1.0.8)
16
+ diff-lcs (1.1.3)
17
+ fuubar (1.1.0)
18
+ rspec (~> 2.0)
19
+ rspec-instafail (~> 0.2.0)
20
+ ruby-progressbar (~> 1.0.0)
21
+ guard (1.5.3)
22
+ listen (>= 0.4.2)
23
+ lumberjack (>= 1.0.2)
24
+ pry (>= 0.9.10)
25
+ thor (>= 0.14.6)
26
+ guard-rspec (2.1.1)
27
+ guard (>= 1.1)
28
+ rspec (~> 2.11)
29
+ listen (0.5.3)
30
+ lumberjack (1.0.2)
31
+ method_source (0.8.1)
32
+ pry (0.9.10)
33
+ coderay (~> 1.0.5)
34
+ method_source (~> 0.8)
35
+ slop (~> 3.3.1)
36
+ rspec (2.11.0)
37
+ rspec-core (~> 2.11.0)
38
+ rspec-expectations (~> 2.11.0)
39
+ rspec-mocks (~> 2.11.0)
40
+ rspec-core (2.11.1)
41
+ rspec-expectations (2.11.3)
42
+ diff-lcs (~> 1.1.3)
43
+ rspec-instafail (0.2.4)
44
+ rspec-mocks (2.11.3)
45
+ ruby-progressbar (1.0.2)
46
+ slop (3.3.3)
47
+ thor (0.16.0)
48
+ thoughtbot-shoulda (2.11.1)
49
+ version (1.0.0)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ at
56
+ dsl!
57
+ fuubar
58
+ guard-rspec
59
+ thoughtbot-shoulda
@@ -0,0 +1,10 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', cli: '--color --format Fuubar' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ watch(%r{^spec/support/.+\.rb$}) { "spec" }
9
+ end
10
+
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 c00lryguy
1
+ Copyright (c) 2010-2012 Ryan Scott Lewis
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -2,73 +2,83 @@
2
2
 
3
3
  ## Description
4
4
 
5
- dsl.rb is a small script (26 lines) to help create domain specific languages within Ruby.
5
+ Helpers for the creation of Domain Specific Languages within your libraries and gems.
6
6
 
7
7
  ## Install
8
8
 
9
- `gem update --system`
10
- `gem update`
11
- `gem install dsl`
12
-
13
- ## Quick Example
14
-
15
- require 'dsl'
16
-
17
- class UserDSL < DSL
18
- def name(n); @name = n; end
19
- def gender(g); @gender = g; end
20
- def age(a); @age = a; end
21
- end
9
+ ### Bundler
22
10
 
23
- class User
24
- attr :name, :gender, :age
25
- dsl_method :edit => UserDSL
26
- end
27
-
28
- ryguy = User.new
29
-
30
- ryguy.edit do
31
- name 'Ryan Lewis'
32
- gender :male
33
- age 19
34
- end
11
+ `gem 'dsl'`
35
12
 
36
- p ryguy
37
- # => #<User:0x00000001b6dc78 @name="Ryan Lewis", @gender=:male, @age=19>
13
+ ### RubyGems
38
14
 
39
- As you can see, simply requiring DSL adds the Module/Class method `dsl_method`, which defines a new instance method for your class that only accepts a block.
40
-
41
- `dsl_method` only accepts a `Hash`, the key being the instance method name and the value being the DSL class the method will use.
42
-
43
- When your DSL instance method is called (with a block, of course), all of your object's instance variables are delegated into a new instance of the DSL class assigned to the called DSL instance method.
44
- The block is then `instance_eval`'d within the new DSL class instance where you can use the instance variables.
45
- When the block is closed, all of the instance variables are then transfered back to your object.
46
-
47
- Therefor, creating a Domain Specific Language is as easy as subclassing the `DSL` class. That's it!
48
-
49
- ## Use with any block:
15
+ `gem install dsl`
50
16
 
51
- To illustrate how to use with any block, The above example could be written like so:
17
+ ## Usage
52
18
 
53
- require 'dsl'
54
19
 
55
- class UserDSL < DSL
56
- def name(n); @name = n; end
57
- def gender(g); @gender = g; end
58
- def age(a); @age = a; end
59
- end
20
+ ### Simple
60
21
 
61
- class User
62
- attr :name, :gender, :age
63
- def edit(&blk)
64
- UserDSL.call(self, &blk)
22
+ ```ruby
23
+ class Character
24
+ class AttributeDSL < DSL
25
+ def_dsl :name, :age, :gender
26
+ end
27
+
28
+ attr_reader :name, :age, :gender
29
+
30
+ def initialize(&blk)
31
+ dsl = AttributeDSL.call(&blk)
32
+
33
+ @name, @age, @gender = dsl.name, dsl.age, dsl.gender
34
+
35
+ # OR:
36
+ # @name, @age, @gender = dsl.to_h.values_at(:name, :age, :gender)
37
+ end
38
+ end
39
+
40
+ Character.new do
41
+ name 'John Doe'
42
+ age 21
43
+ gender :male
44
+ end
45
+ ```
46
+
47
+ ### Advanced
48
+
49
+ ```ruby
50
+ class Character
51
+ class AttributeDSL < DSL
52
+ def_dsl :name do
53
+ get do |value|
54
+ value.split(' ').first.capitalize # Only return the first name, even if the person has a last name as well
55
+ end
56
+
57
+ set do |value| # The instance variable will be set to the result of this block
58
+ raise 'name must be a String' unless value.respond_to?(:to_s)
59
+
60
+ value.to_s
65
61
  end
66
62
  end
63
+ end
64
+
65
+ attr_reader :name
66
+
67
+ def initialize(&blk)
68
+ dsl = AttributeDSL.call(&blk)
69
+
70
+ @name = dsl.name
67
71
 
68
- The class method `call` takes a parent and a block. The parent that you give will get it's instance variables delegated to a new instance of your DSL class.
72
+ # OR:
73
+ # @name, @age, @gender = dsl.to_h.values_at(:name, :age, :gender)
74
+ end
75
+ end
69
76
 
70
- You could easily delegate instance variables from another class instance other than `self`
77
+ Character.new do
78
+ name 1234 # Error: name must be a String
79
+ end
80
+ ```
71
81
 
72
- ## Copyright
82
+ ## License
73
83
 
74
- Copyright (c) 2010 Ryan Lewis. See LICENSE for details.
84
+ Copyright (c) 2010-2012 Ryan Lewis. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,69 +1,35 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "dsl"
8
- gem.summary = "A small library for creating Domain Specific Languages (DSLs)"
9
- gem.description = gem.summary
10
- gem.email = "c00lryguy@gmail.com"
11
- gem.homepage = "http://github.com/c00lryguy/dsl"
12
- gem.authors = ["c00lryguy"]
13
- gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
- end
16
- Jeweler::GemcutterTasks.new
17
- rescue LoadError
18
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
- end
20
-
21
- require 'rake/testtask'
22
- Rake::TestTask.new(:test) do |test|
23
- test.libs << 'lib' << 'test'
24
- test.pattern = 'test/**/test_*.rb'
25
- test.verbose = true
1
+ require 'rake/version_task'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubygems/package_task'
4
+ require 'pathname'
5
+
6
+ spec = Gem::Specification.new do |s|
7
+ s.name = 'dsl'
8
+ s.version = Pathname.new(__FILE__).dirname.join('VERSION').read.strip
9
+ s.author = 'Ryan Scott Lewis'
10
+ s.email = 'ryan@rynet.us'
11
+ s.homepage = "http://github.com/c00lryguy/#{s.name}"
12
+ s.summary = 'Helpers for the creation of Domain Specific Languages within your libraries and gems.'
13
+ s.description = 'Easily create DSLs for use within your projects!'
14
+ s.require_path = 'lib'
15
+ s.files = `git ls-files`.lines.to_a.collect { |s| s.strip }
16
+ s.executables = `git ls-files -- bin/*`.lines.to_a.collect { |s| File.basename(s.strip) }
17
+
18
+ s.post_install_message = "NOTICE!\n\n DSL 2.x.x is INCOMPATIBLE with DSL 1.x.x!\n\n"
19
+
20
+ s.add_dependency 'version', '~> 1.0.0'
26
21
  end
27
22
 
28
- begin
29
- require 'rcov/rcovtask'
30
- Rcov::RcovTask.new do |test|
31
- test.libs << 'test'
32
- test.pattern = 'test/**/test_*.rb'
33
- test.verbose = true
34
- end
35
- rescue LoadError
36
- task :rcov do
37
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
- end
23
+ Rake::VersionTask.new do |t|
24
+ t.with_git_tag = true
25
+ t.with_gemspec = spec
39
26
  end
40
27
 
41
- task :test => :check_dependencies
28
+ RSpec::Core::RakeTask.new
42
29
 
43
- begin
44
- require 'reek/adapters/rake_task'
45
- Reek::RakeTask.new do |t|
46
- t.fail_on_error = true
47
- t.verbose = false
48
- t.source_files = 'lib/**/*.rb'
49
- end
50
- rescue LoadError
51
- task :reek do
52
- abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
53
- end
30
+ Gem::PackageTask.new(spec) do |t|
31
+ t.need_zip = false
32
+ t.need_tar = false
54
33
  end
55
34
 
56
- begin
57
- require 'roodi'
58
- require 'roodi_task'
59
- RoodiTask.new do |t|
60
- t.verbose = false
61
- end
62
- rescue LoadError
63
- task :roodi do
64
- abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi"
65
- end
66
- end
67
-
68
- task :default => :test
69
-
35
+ task :default => :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.2.0
@@ -1,60 +1,30 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
5
2
 
6
3
  Gem::Specification.new do |s|
7
- s.name = %q{dsl}
8
- s.version = "0.1.4"
4
+ s.name = "dsl"
5
+ s.version = "0.2.0"
9
6
 
10
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["c00lryguy"]
12
- s.date = %q{2010-08-28}
13
- s.description = %q{A small library for creating Domain Specific Languages (DSLs)}
14
- s.email = %q{c00lryguy@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.md"
18
- ]
19
- s.files = [
20
- "LICENSE",
21
- "README.md",
22
- "Rakefile",
23
- "VERSION",
24
- "dsl.gemspec",
25
- "examples/database.rb",
26
- "examples/user.rb",
27
- "examples/webapp.rb",
28
- "lib/dsl.rb",
29
- "pkg/dsl-0.1.2.gem",
30
- "pkg/dsl-0.1.3.gem",
31
- "test/helper.rb",
32
- "test/test_dsl.rb"
33
- ]
34
- s.homepage = %q{http://github.com/c00lryguy/dsl}
35
- s.rdoc_options = ["--charset=UTF-8"]
8
+ s.authors = ["Ryan Scott Lewis"]
9
+ s.date = "2012-11-04"
10
+ s.description = "Easily create DSLs for use within your projects!"
11
+ s.email = "ryan@rynet.us"
12
+ s.files = [".gitignore", ".rvmrc", "Gemfile", "Gemfile.lock", "Guardfile", "LICENSE", "README.md", "Rakefile", "VERSION", "dsl.gemspec", "lib/dsl.rb", "spec/dsl_spec.rb", "spec/spec_helper.rb", "spec/support/character_with_attr_reader.rb", "spec/support/character_with_attr_writer.rb", "spec/support/character_without_attributes.rb"]
13
+ s.homepage = "http://github.com/c00lryguy/dsl"
14
+ s.post_install_message = "NOTICE!\n\n DSL 2.x.x is INCOMPATIBLE with DSL 1.x.x!\n\n"
36
15
  s.require_paths = ["lib"]
37
- s.rubygems_version = %q{1.3.7}
38
- s.summary = %q{A small library for creating Domain Specific Languages (DSLs)}
39
- s.test_files = [
40
- "test/test_dsl.rb",
41
- "test/helper.rb",
42
- "examples/database.rb",
43
- "examples/user.rb",
44
- "examples/webapp.rb"
45
- ]
16
+ s.rubygems_version = "1.8.24"
17
+ s.summary = "Helpers for the creation of Domain Specific Languages within your libraries and gems."
46
18
 
47
19
  if s.respond_to? :specification_version then
48
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
20
  s.specification_version = 3
50
21
 
51
22
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
23
+ s.add_runtime_dependency(%q<version>, ["~> 1.0.0"])
53
24
  else
54
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
25
+ s.add_dependency(%q<version>, ["~> 1.0.0"])
55
26
  end
56
27
  else
57
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
28
+ s.add_dependency(%q<version>, ["~> 1.0.0"])
58
29
  end
59
30
  end
60
-
data/lib/dsl.rb CHANGED
@@ -1,36 +1,38 @@
1
- #!/usr/bin/env ruby
2
-
3
- class DSL
4
- def self.call(parent, &blk)
5
- instance = new
6
- # Add all of the parents instance variables to the instance
7
- parent.instance_variables.each do |instance_variable|
8
- value = parent.instance_variable_get(instance_variable)
9
- instance.instance_variable_set(instance_variable, value)
1
+ class DSL
2
+
3
+ class << self
4
+
5
+ def call(parent, &blk)
6
+ # `instance_eval` returns the last thing in the block whereas `tap` return the Object that was tapped
7
+ new(parent).tap { |instance| instance.instance_eval(&blk) }
10
8
  end
11
- # Instance eval the block in the instance
12
- instance.instance_eval(&blk)
13
- # Replace all of the parents instance variables with the instance's
14
- instance.instance_variables.each do |instance_variable|
15
- value = instance.instance_variable_get(instance_variable)
16
- parent.instance_variable_set(instance_variable, value)
17
- end
18
- # Return the parent for convenience
19
- parent
20
- end
21
- end
22
-
23
- class Module
24
- def dsl_method(opts)
25
- # Complain if the argument isn't a hash
26
- raise(TypeError) unless opts.is_a?(Hash)
27
- # For each dsl_method, define it in the class
28
- # The methods do not accept arguments, only blocks
29
- opts.each do |method, dsl_class|
30
- define_method(method) do |&blk|
31
- raise(ArgumentError, "method #{method} requires a block") unless !!blk
32
- dsl_class.call(self, &blk)
9
+
10
+ # Defines a method that accepts a variable number of arguments
11
+ # that will delegate to the parent.
12
+ # This will attempt to call the setter/getter method before attempting to
13
+ # access the instance variable. This way, any modifications you do to the
14
+ # instance variables in those methods will be used.
15
+ def def_dsl_delegator(*method_names)
16
+ method_names.each do |method_name|
17
+ raise TypeError unless method_name.respond_to?(:to_sym)
18
+ method_name = method_name.to_sym
19
+
20
+ define_method(method_name) do |*args|
21
+ unless args.empty?
22
+ args = args.first if args.length == 1
23
+ @parent.respond_to?("#{method_name}=") ? @parent.send("#{method_name}=", args) : @parent.instance_variable_set("@#{method_name}", args)
24
+ end
25
+
26
+ @parent.respond_to?(method_name) ? @parent.send(method_name) : @parent.instance_variable_get("@#{method_name}")
27
+ end
28
+
33
29
  end
34
30
  end
31
+
32
+ end
33
+
34
+ def initialize(parent)
35
+ @parent = parent
35
36
  end
37
+
36
38
  end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe CharacterWithoutAttributes do
4
+ subject do
5
+ CharacterWithoutAttributes.new do
6
+ name 'John Doe'
7
+ age 21
8
+ end
9
+ end
10
+
11
+ context "Subject" do
12
+ it "should have instance variables set correctly" do
13
+ subject.at.name.should == 'John Doe'
14
+ subject.at.age.should == 21
15
+ end
16
+ end
17
+ end
18
+
19
+ describe CharacterWithAttrReader do
20
+ subject do
21
+ CharacterWithAttrReader.new do
22
+ name 'John Doe'
23
+ age '21'
24
+ end
25
+ end
26
+
27
+ context "Subject" do
28
+ it "should have instance variables set correctly" do
29
+ subject.at.name.should == 'John Doe'
30
+ subject.at.age.should == '21'
31
+ end
32
+
33
+ it "should have attr readers set correctly" do
34
+ subject.name.should == 'JOHN'
35
+ subject.age.should == 21
36
+ end
37
+ end
38
+
39
+ context "DSL" do
40
+ it "should have attr readers set correctly" do
41
+ subject.at.dsl.name.should == 'JOHN'
42
+ subject.at.dsl.age.should == 21
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ describe CharacterWithAttrWriter do
49
+ subject do
50
+ CharacterWithAttrWriter.new do
51
+ name 'John Doe'
52
+ age '21'
53
+ end
54
+ end
55
+
56
+ context "Subject" do
57
+ it "should have instance variables set correctly" do
58
+ subject.at.name.should == 'JOHN'
59
+ subject.at.age.should == 21
60
+ end
61
+ end
62
+
63
+ context "DSL" do
64
+ it "should have attr readers set correctly" do
65
+ subject.at.dsl.name.should == 'JOHN'
66
+ subject.at.dsl.age.should == 21
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,6 @@
1
+ require 'pathname'
2
+ require 'dsl'
3
+
4
+ Bundler.require(:development)
5
+
6
+ Dir[ Pathname.new(__FILE__).join('..', 'support', '**', '*').expand_path ].each { |filename| require filename }
@@ -0,0 +1,19 @@
1
+ class CharacterWithAttrReader
2
+
3
+ class AttrDSL < DSL
4
+ def_dsl_delegator :name, :age
5
+ end
6
+
7
+ def initialize(&blk)
8
+ @dsl = AttrDSL.call(self, &blk)
9
+ end
10
+
11
+ def name
12
+ @name.split(/\s+/).first.upcase
13
+ end
14
+
15
+ def age
16
+ @age.to_i
17
+ end
18
+
19
+ end
@@ -0,0 +1,19 @@
1
+ class CharacterWithAttrWriter
2
+
3
+ class AttrDSL < DSL
4
+ def_dsl_delegator :name, :age
5
+ end
6
+
7
+ def initialize(&blk)
8
+ @dsl = AttrDSL.call(self, &blk)
9
+ end
10
+
11
+ def name=(value)
12
+ @name = value.split(/\s+/).first.upcase
13
+ end
14
+
15
+ def age=(value)
16
+ @age = value.to_i
17
+ end
18
+
19
+ end
@@ -0,0 +1,11 @@
1
+ class CharacterWithoutAttributes
2
+
3
+ class AttrDSL < DSL
4
+ def_dsl_delegator :name, :age
5
+ end
6
+
7
+ def initialize(&blk)
8
+ AttrDSL.call(self, &blk)
9
+ end
10
+
11
+ end
metadata CHANGED
@@ -1,97 +1,80 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: dsl
3
- version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 4
10
- version: 0.1.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
13
- - c00lryguy
7
+ authors:
8
+ - Ryan Scott Lewis
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2010-08-28 00:00:00 -04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: thoughtbot-shoulda
12
+ date: 2012-11-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: version
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :runtime
23
23
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
33
- type: :development
34
- version_requirements: *id001
35
- description: A small library for creating Domain Specific Languages (DSLs)
36
- email: c00lryguy@gmail.com
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ description: Easily create DSLs for use within your projects!
31
+ email: ryan@rynet.us
37
32
  executables: []
38
-
39
33
  extensions: []
40
-
41
- extra_rdoc_files:
42
- - LICENSE
43
- - README.md
44
- files:
34
+ extra_rdoc_files: []
35
+ files:
36
+ - .gitignore
37
+ - .rvmrc
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - Guardfile
45
41
  - LICENSE
46
42
  - README.md
47
43
  - Rakefile
48
44
  - VERSION
49
45
  - dsl.gemspec
50
- - examples/database.rb
51
- - examples/user.rb
52
- - examples/webapp.rb
53
46
  - lib/dsl.rb
54
- - pkg/dsl-0.1.2.gem
55
- - pkg/dsl-0.1.3.gem
56
- - test/helper.rb
57
- - test/test_dsl.rb
58
- has_rdoc: true
47
+ - spec/dsl_spec.rb
48
+ - spec/spec_helper.rb
49
+ - spec/support/character_with_attr_reader.rb
50
+ - spec/support/character_with_attr_writer.rb
51
+ - spec/support/character_without_attributes.rb
59
52
  homepage: http://github.com/c00lryguy/dsl
60
53
  licenses: []
61
-
62
- post_install_message:
63
- rdoc_options:
64
- - --charset=UTF-8
65
- require_paths:
54
+ post_install_message: ! "NOTICE!\n\n DSL 2.x.x is INCOMPATIBLE with DSL 1.x.x!\n\n"
55
+ rdoc_options: []
56
+ require_paths:
66
57
  - lib
67
- required_ruby_version: !ruby/object:Gem::Requirement
58
+ required_ruby_version: !ruby/object:Gem::Requirement
68
59
  none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- hash: 3
73
- segments:
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ segments:
74
65
  - 0
75
- version: "0"
76
- required_rubygems_version: !ruby/object:Gem::Requirement
66
+ hash: 3439450735216533917
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
68
  none: false
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- hash: 3
82
- segments:
83
- - 0
84
- version: "0"
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
85
73
  requirements: []
86
-
87
74
  rubyforge_project:
88
- rubygems_version: 1.3.7
75
+ rubygems_version: 1.8.24
89
76
  signing_key:
90
77
  specification_version: 3
91
- summary: A small library for creating Domain Specific Languages (DSLs)
92
- test_files:
93
- - test/test_dsl.rb
94
- - test/helper.rb
95
- - examples/database.rb
96
- - examples/user.rb
97
- - examples/webapp.rb
78
+ summary: Helpers for the creation of Domain Specific Languages within your libraries
79
+ and gems.
80
+ test_files: []
@@ -1,77 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require File.join(File.dirname(__FILE__), '..', 'dsl')
4
-
5
- class Database
6
- class Table
7
- def initialize
8
- @schema = {}
9
- @entries = []
10
- end
11
-
12
- def create(opts)
13
- raise(TypeError) unless opts.is_a?(Hash)
14
- opts.each do |name, v|
15
- raise("key '#{name}' not defined in schema") unless @schema.has_key?(name)
16
- if @schema[name] == :primary_key
17
- raise('You cannot set primary keys')
18
- else
19
- raise("key '#{name}' not of type #{@schema[name]}") unless v.is_a?(@schema[name])
20
- end
21
- end
22
- @schema.select { |name, v| v == :primary_key }.each do |name, v|
23
- opts[name] = @entries.count
24
- end
25
- @entries << opts
26
- end
27
-
28
- def [](id)
29
- @entries.find_all do |entry|
30
- entry[:id] == id
31
- end
32
- end
33
- end
34
-
35
- class SchemaDSL < DSL
36
- def primary_key(name); @schema[name] = :primary_key; end
37
- def String(name); @schema[name] = ::String; end
38
- def Integer(name); @schema[name] = ::Integer; end
39
- end
40
-
41
- def initialize
42
- @tables = {}
43
- end
44
-
45
- def table(name, &blk)
46
- if block_given?
47
- raise("Table '#{name}' already exists") unless @tables[name].nil?
48
- @tables[name] = Table.new
49
- SchemaDSL.call(@tables[name], &blk)
50
- else
51
- @tables[name]
52
- end
53
- end
54
- end
55
-
56
- require 'ap'
57
-
58
- db = Database.new
59
-
60
- db.table(:users) do
61
- primary_key :id
62
- String :username
63
- Integer :age
64
- end
65
-
66
- db.table(:users).create(:username => 'Foo', :age => 19)
67
- db.table(:users).create(:username => 'Bar', :age => 43)
68
-
69
- p db.table(:users)[0]
70
- # => [{:username=>"Foo", :age=>19, :id=>0}]
71
-
72
- p db.table(:users)[1]
73
- # => [{:username=>"Bar", :age=>43, :id=>1}]
74
-
75
- db.table(:users).create(:username => 'Baz', :age => 'One Hundred')
76
- # => ERROR: key 'age' not of type Integer (RuntimeError)
77
-
@@ -1,25 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require File.join(File.dirname(__FILE__), '..', 'dsl')
4
-
5
- class UserDSL < DSL
6
- def name(n); @name = n; end
7
- def gender(g); @gender = g; end
8
- def age(a); @age = a; end
9
- end
10
-
11
- class User
12
- attr :name, :gender, :age
13
- dsl_method :edit => UserDSL
14
- end
15
-
16
- ryguy = User.new
17
-
18
- ryguy.edit do
19
- name 'Ryan Lewis'
20
- gender :male
21
- age 19
22
- end
23
-
24
- p ryguy
25
- # => #<User:0x00000001b6dc78 @name="Ryan Lewis", @gender=:male, @age=19>
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require File.join(File.dirname(__FILE__), '..', 'dsl')
4
-
5
- class ConfigDSL < DSL
6
- def add_helpers(*h)
7
- @helpers.concat(h)
8
- end
9
- end
10
-
11
- class WebApp
12
- attr :helpers
13
- dsl_method :config => ConfigDSL
14
-
15
- #===--- OR:
16
- # dsl_method :config => Class.new(DSL) {
17
- # def add_helpers(*h)
18
- # @helpers.concat(h)
19
- # end
20
- # }
21
-
22
- #===--- MAYBE:
23
- # define_dsl_method :config do
24
- # def add_helpers; end
25
- # end
26
-
27
- def initialize
28
- @helpers = ['helpers/foo', 'helpers/bar']
29
- end
30
- end
31
-
32
- web_app = WebApp.new
33
-
34
- p web_app.helpers
35
- # => ["helpers/foo", "helpers/bar"]
36
-
37
- web_app.config do
38
- add_helpers 'helpers/baz', 'helpers/qux'
39
- end
40
-
41
- p web_app.helpers
42
- # => ["helpers/foo", "helpers/bar", "helpers/baz", "helpers/qux"]
43
-
Binary file
Binary file
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
-
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'dsl'
8
-
9
- class Test::Unit::TestCase
10
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestDsl < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end