dsl_helper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,27 @@
1
+ = Dsl Helper
2
+
3
+ == Usage
4
+
5
+ require 'dsl_helper'
6
+
7
+ class MyDSLConfig
8
+
9
+ include DslHelper
10
+
11
+ dsl_attr :host, :port, :name
12
+ end
13
+
14
+ config = MyDSLConfig.new.instance_eval do
15
+ host 'localhost'
16
+ port 11345
17
+ name 'my_network_thingy'
18
+ end
19
+
20
+ Then calls to the underscore versions of the attribute accessors work normally
21
+
22
+ config._host
23
+
24
+ Returns
25
+
26
+ >> 'localhost'
27
+
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |s|
4
+ s.name = "dsl_helper"
5
+ s.description = s.summary = "Helpers for creating internal DSLs"
6
+ s.email = "joshbuddy@gmail.com"
7
+ s.homepage = "http://github.com/joshbuddy/dsl_helper"
8
+ s.authors = ["Joshua Hull"]
9
+ s.files = FileList["[A-Z]*", "{lib,spec}/**/*"]
10
+ end
11
+ Jeweler::GemcutterTasks.new
12
+ rescue LoadError
13
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
14
+ end
15
+
16
+ require 'spec'
17
+ require 'spec/rake/spectask'
18
+ task :spec => 'spec:all'
19
+ namespace(:spec) do
20
+ Spec::Rake::SpecTask.new(:all) do |t|
21
+ t.spec_opts ||= []
22
+ t.spec_opts << "-rubygems"
23
+ t.spec_opts << "--options" << "spec/spec.opts"
24
+ t.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ end
28
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/lib/dsl_helper.rb ADDED
@@ -0,0 +1,26 @@
1
+ module DslHelper
2
+ module ClassMethods
3
+ def dsl_attr(*attrs)
4
+ attrs.each do |attr|
5
+ self.module_eval "
6
+ def #{attr}(val)
7
+ @#{attr} = val
8
+ end
9
+
10
+ def _#{attr}
11
+ @#{attr}
12
+ end
13
+
14
+ def _#{attr}=(val)
15
+ @#{attr} = val
16
+ end
17
+ "
18
+ end
19
+ end
20
+ end
21
+
22
+ def self.included(cls)
23
+ cls.extend(ClassMethods)
24
+ end
25
+
26
+ end
@@ -0,0 +1,31 @@
1
+ require 'dirge'
2
+ require ~'spec_helper'
3
+
4
+ class Testing
5
+ include DslHelper
6
+
7
+ dsl_attr :test
8
+
9
+ end
10
+
11
+ describe "DslHelper" do
12
+ it "should provide useful helper methods" do
13
+ t = Testing.new
14
+ t.respond_to?(:_test).should be_true
15
+ t.respond_to?(:_test=).should be_true
16
+ t.respond_to?(:test).should be_true
17
+ end
18
+
19
+ it "should store the value in the instance var of its name" do
20
+ t = Testing.new
21
+ t.test 'something'
22
+ t._test.should == 'something'
23
+ end
24
+
25
+ it "should assign normally though the underscore writer" do
26
+ t = Testing.new
27
+ t._test = 'something'
28
+ t._test.should == 'something'
29
+ end
30
+
31
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,7 @@
1
+ --colour
2
+ --format
3
+ specdoc
4
+ --loadby
5
+ mtime
6
+ --reverse
7
+ --backtrace
@@ -0,0 +1 @@
1
+ require ~'../lib/dsl_helper'
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dsl_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Joshua Hull
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-03-15 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Helpers for creating internal DSLs
17
+ email: joshbuddy@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - README.rdoc
26
+ - Rakefile
27
+ - VERSION
28
+ - lib/dsl_helper.rb
29
+ - spec/dsl_helper_spec.rb
30
+ - spec/spec.opts
31
+ - spec/spec_helper.rb
32
+ has_rdoc: true
33
+ homepage: http://github.com/joshbuddy/dsl_helper
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options:
38
+ - --charset=UTF-8
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ requirements: []
54
+
55
+ rubyforge_project:
56
+ rubygems_version: 1.3.5
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: Helpers for creating internal DSLs
60
+ test_files:
61
+ - spec/dsl_helper_spec.rb
62
+ - spec/spec_helper.rb