katuv 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTE0MjU5ZjdmNDg3YmU1MjExNDE4MGIzMDYzMWQ1YzIwZDUzYmM2Mg==
5
+ data.tar.gz: !binary |-
6
+ MTE3OTJhZTc1Y2E5NWE0ZDdiNGU3YmQxMzI4NThmOWZhY2NjOTkwZA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZDU1NGE2NWQ5NzM5ZTBkNDliNzM3MGU5MjdjMjY1ZWQwOWQ2MTZhMDZkNzdm
10
+ YmJlYjM3Y2QzOWJlNGIwYTIwZTIwNDhjNjZhNTI4MmY4MzExZjM3M2ZmYmYx
11
+ MThhOTZmYWJhMWI2MDIyNjhmNWMzMzJiYjZkMTUyYzM0ZWQzOWY=
12
+ data.tar.gz: !binary |-
13
+ MGExNzFkZWRiNmQ2YjVhMmIyNzZhMWE3NjE0MjZhMDYxNGE3OTM4OWZhNzk2
14
+ NzI2ZWFlMmI5NDVkMTkyNDk0NzcyMDBhNDQ5Y2Y4YzNjNDIyYjc4MDgyZjZk
15
+ MGIzNTEyZGFkY2MzOTVjMjI2Mjg1NGUxMzMwYjg5NjViNTAxMDA=
@@ -0,0 +1 @@
1
+ katuv
@@ -0,0 +1 @@
1
+ rbx-head
data/Gemfile CHANGED
@@ -1,16 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rake'
4
-
5
- gem 'rspec'
6
- gem 'rspec-spies'
7
- gem 'coveralls', require: false
8
- gem 'flay'
9
- gem 'flog'
10
- gem 'mutant'
11
-
12
- gem 'pry'
13
-
3
+ gem 'crystalline'
4
+ gem 'rspec', '2.13.0'
14
5
 
15
6
  # Specify your gem's dependencies in katuv.gemspec
16
7
  gemspec
data/Rakefile CHANGED
@@ -24,6 +24,8 @@ task :flay do
24
24
  end
25
25
 
26
26
  task :mutant, [:klass] do |_, args|
27
+ ENV['NO_COVERAGE'] = 'true'
28
+
27
29
  puts "#### MUTANT TESTING ####"
28
30
  system "mutant -I lib -r katuv --rspec-full #{args[:name] || '::Katuv'}"
29
31
  puts "########################"
@@ -1,7 +1,7 @@
1
1
  module Katuv
2
2
  module DSL
3
3
  def nonterminal(type)
4
- raise "NonterminalInTerminalError" if terminal?
4
+ raise NonterminalInTerminalError if terminal?
5
5
  define_method(_type_to_method_name(type)) do |name=nil, opts={}, &block|
6
6
  if children.has_key?(type) and children[type]
7
7
  children[type].run!(&block)
@@ -14,9 +14,9 @@ module Katuv
14
14
 
15
15
  def terminal(type)
16
16
  #should only allow one.
17
- raise "InvalidNodeTypeError" unless type.terminal?
17
+ raise InvalidNodeTypeError unless type.terminal?
18
18
  define_method(_type_to_method_name(type)) do |name=nil, opts={}, &block|
19
- raise "TerminalAlreadySetError" if children.has_key?(type)
19
+ raise TerminalAlreadySetError if children.has_key?(type)
20
20
  children[type] = type.new(name, opts.merge(parent: self), &block)
21
21
  end
22
22
  end
@@ -28,7 +28,7 @@ module Katuv
28
28
  def multiple(type)
29
29
  #should store an entry in #children that is a list of all the instances
30
30
  #it sees of this type. eg, `file 'x'; file 'y' #=> children[File] = [File<@name=x>, File<@name=y>]
31
- raise "InvalidNodeTypeError" unless type.terminal?
31
+ raise InvalidNodeTypeError unless type.terminal?
32
32
  define_method(_type_to_method_name(type)) do |name, opts={}, &block|
33
33
  children[type] ||= ObjectSet.new
34
34
  children[type] << type.new(name, opts.merge(parent: self), &block)
@@ -42,5 +42,9 @@ module Katuv
42
42
  type.to_s
43
43
  end.split('::').last.downcase
44
44
  end
45
+
46
+ class InvalidNodeTypeError < ArgumentError ; end
47
+ class TerminalAlreadySetError < ArgumentError ; end
48
+ class NonterminalInTerminalError < ArgumentError ; end
45
49
  end
46
50
  end
@@ -2,12 +2,15 @@ module Katuv
2
2
  module Node
3
3
  def self.included(base)
4
4
  base.send(:include, VisitorBehavior)
5
- base.send(:include, Enumerable)
6
5
 
7
6
  base.send(:include, NamingBehavior)
8
7
  base.send(:include, NodeBehavior)
9
8
 
10
9
  base.send(:extend, DSL)
11
10
  end
11
+
12
+ def inspect
13
+ method_name
14
+ end
12
15
  end
13
16
  end
@@ -4,7 +4,8 @@ module Katuv
4
4
  @parent = opts[:parent]
5
5
  @name = name
6
6
  @opts = opts
7
- instance_eval &block if block_given?
7
+ @block = block
8
+ run! &block unless terminal?
8
9
  end
9
10
  attr_reader :parent, :name
10
11
 
@@ -12,12 +13,26 @@ module Katuv
12
13
  self.class.terminal?
13
14
  end
14
15
 
16
+ def block
17
+ # pretend there's no method if we're not a terminal class.
18
+ raise NoMethodError unless terminal?
19
+ @block
20
+ end
21
+
22
+ def arity
23
+ @block.arity
24
+ end
25
+
26
+ def parameters
27
+ @block.parameters
28
+ end
29
+
15
30
  def each(&block)
16
31
  children.values.each(&block)
17
32
  end
18
33
 
19
- def run!
20
- #this sucks
34
+ def run!(&block)
35
+ instance_eval &block if block_given?
21
36
  end
22
37
 
23
38
  def children
@@ -1,3 +1,3 @@
1
1
  module Katuv
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -1,5 +1,9 @@
1
1
  module Katuv
2
2
  module VisitorBehavior
3
+ def self.included(base)
4
+ base.send(:include, Enumerable)
5
+ end
6
+
3
7
  def visit(visitor)
4
8
  visitor.before(self) if visitor.respond_to? :before
5
9
 
@@ -9,6 +13,10 @@ module Katuv
9
13
  visitor.unknown(self)
10
14
  end
11
15
 
16
+ each do |c|
17
+ c.visit(visitor)
18
+ end
19
+
12
20
  visitor.after(self) if visitor.respond_to? :after
13
21
  nil
14
22
  end
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+ describe 'a dsl defined directly with katuv classes' do
3
+ before :all do
4
+ class Bar
5
+ include Katuv::Node
6
+ terminal!
7
+ end
8
+
9
+ class Baz
10
+ include Katuv::Node
11
+
12
+ terminal!
13
+
14
+ def self.name
15
+ 'Quux'
16
+ end
17
+ end
18
+
19
+ class Foo
20
+ include Katuv::Node
21
+ multiple Bar
22
+ terminal Baz
23
+ nonterminal Foo
24
+ end
25
+ end
26
+
27
+ # A necessary bit of boilerplate required to start a script. you could,
28
+ # in theory, just do "Foo.new" to start the script, but you'd have to
29
+ # explicitly pass the parent.
30
+ #
31
+ # In needs to be in the outer scope (ie, not in the before block) so tests can
32
+ # get at it.
33
+ def foo(name = nil, opts={}, &block)
34
+ Foo.new(name, opts.merge(parent: nil), &block)
35
+ end
36
+
37
+ after :all do
38
+ Object.send(:remove_const, :Bar)
39
+ Object.send(:remove_const, :Baz)
40
+ Object.send(:remove_const, :Foo)
41
+ end
42
+
43
+ describe 'a correctly written script' do
44
+ subject :example_dsl_script do
45
+ foo do
46
+ bar '1'
47
+ bar '2'
48
+ quux 'bingle'
49
+
50
+ foo do
51
+ bar '3'
52
+ bar '4'
53
+
54
+ quux 'bangle'
55
+ end
56
+ end
57
+ end
58
+
59
+ it "parses the example script cleanly, raising no errors" do
60
+ expect { example_dsl_script }.to_not raise_error Katuv::DSL::NonterminalInTerminalError
61
+ expect { example_dsl_script }.to_not raise_error Katuv::DSL::TerminalAlreadySetError
62
+ expect { example_dsl_script }.to_not raise_error Katuv::DSL::InvalidNodeTypeError
63
+ end
64
+
65
+ context 'setting a terminal twice' do
66
+ subject :example_dsl_script do
67
+ foo do
68
+ bar '1'
69
+
70
+ quux '2'
71
+ quux 'bingle'
72
+ end
73
+ end
74
+
75
+ it 'raises a TerminalAlreadySetError' do
76
+ expect { example_dsl_script }.to raise_error Katuv::DSL::TerminalAlreadySetError
77
+ end
78
+ end
79
+ end
80
+ end
81
+
@@ -7,6 +7,10 @@ shared_examples_for 'a class with the visitable behavior' do
7
7
  let(:visitor) { double('visitor') }
8
8
  before { visitor.stub(:unknown) }
9
9
 
10
+ # this by virtue of the fact that it is visitable and defines #each,
11
+ # VisitorBehavior includes Enumerable for us.
12
+ it { should be_an Enumerable }
13
+
10
14
  context 'with before hook' do
11
15
  before { visitor.stub(:before) }
12
16
 
@@ -6,8 +6,10 @@ require 'katuv'
6
6
 
7
7
  require 'rspec-spies'
8
8
 
9
- require 'coveralls'
10
- Coveralls.wear!
9
+ unless ENV['NO_COVERAGE']
10
+ require 'coveralls'
11
+ Coveralls.wear!
12
+ end
11
13
 
12
14
  #include helpers
13
15
  Dir["./spec/helpers/*.rb"].each { |file| require file }
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'The Katuv DSL' do
4
+ before :all do
5
+ class Example
6
+ end
7
+ end
8
+ subject(:example) { Example }
9
+
10
+ context 'before inclusion' do
11
+ describe 'api' do
12
+ it { should_not respond_to :terminal }
13
+ it { should_not respond_to :terminal! }
14
+ it { should_not respond_to :terminal? }
15
+ it { should_not respond_to :nonterminal }
16
+ it { should_not respond_to :multiple }
17
+
18
+ #technically private, but we need to test it... badly.
19
+ it { should_not respond_to :_type_to_method_name }
20
+ end
21
+ end
22
+
23
+ context 'after inclusion' do
24
+ before :all do
25
+ class Example
26
+ include Katuv::Node
27
+ end
28
+ end
29
+
30
+ describe 'api' do
31
+ it { should respond_to :terminal }
32
+ it { should respond_to :terminal! }
33
+ it { should respond_to :terminal? }
34
+
35
+ it { should respond_to :nonterminal }
36
+ it { should respond_to :multiple }
37
+
38
+ #technically private, but we need to test it... badly.
39
+ it { should respond_to :_type_to_method_name }
40
+ end
41
+
42
+ context do
43
+ describe '#_type_to_method_name' do
44
+ # this is kind of lousy
45
+ subject { example._type_to_method_name(example) }
46
+
47
+ it { should == 'example' }
48
+ end
49
+ end
50
+ end
51
+ end
@@ -4,6 +4,7 @@ describe Katuv::Node do
4
4
  before :all do
5
5
  class ExampleTerminal
6
6
  include Katuv::Node
7
+
7
8
  terminal!
8
9
  end
9
10
 
@@ -16,6 +17,7 @@ describe Katuv::Node do
16
17
 
17
18
  class Example
18
19
  include Katuv::Node
20
+
19
21
  terminal ExampleTerminal
20
22
  nonterminal ExampleNonterminal
21
23
  end
@@ -33,6 +35,8 @@ describe Katuv::Node do
33
35
  it_should_behave_like 'a visitable class'
34
36
  it_should_behave_like 'a class with the visitable behavior'
35
37
 
38
+ it { should be_an Enumerable }
39
+
36
40
  its(:method_name) { should == "example" }
37
41
  end
38
42
 
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: katuv
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.4
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Joe Fredette
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-10 00:00:00.000000000 Z
11
+ date: 2013-08-05 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: A tool for parsing and transforming internal Ruby DSLs
15
14
  email:
@@ -18,94 +17,62 @@ executables: []
18
17
  extensions: []
19
18
  extra_rdoc_files: []
20
19
  files:
21
- - !binary |-
22
- LmdpdGlnbm9yZQ==
23
- - !binary |-
24
- LnJ2bXJj
25
- - !binary |-
26
- LnRyYXZpcy55bWw=
27
- - !binary |-
28
- Q0hBTkdFTE9H
29
- - !binary |-
30
- R2VtZmlsZQ==
31
- - !binary |-
32
- TElDRU5TRS50eHQ=
33
- - !binary |-
34
- Tk9URVMubWQ=
35
- - !binary |-
36
- UkVBRE1FLm1k
37
- - !binary |-
38
- UmFrZWZpbGU=
39
- - !binary |-
40
- a2F0dXYuZ2Vtc3BlYw==
41
- - !binary |-
42
- bGliL2thdHV2LnJi
43
- - !binary |-
44
- bGliL2thdHV2L2RzbC5yYg==
45
- - !binary |-
46
- bGliL2thdHV2L25hbWluZ19iZWhhdmlvci5yYg==
47
- - !binary |-
48
- bGliL2thdHV2L25vZGUucmI=
49
- - !binary |-
50
- bGliL2thdHV2L25vZGVfYmVoYXZpb3IucmI=
51
- - !binary |-
52
- bGliL2thdHV2L29iamVjdF9zZXQucmI=
53
- - !binary |-
54
- bGliL2thdHV2L3ZlcnNpb24ucmI=
55
- - !binary |-
56
- bGliL2thdHV2L3Zpc2l0b3JfYmVoYXZpb3IucmI=
57
- - !binary |-
58
- c3BlYy9kc2xfc3BlYy5yYg==
59
- - !binary |-
60
- c3BlYy9ub2RlX3NwZWMucmI=
61
- - !binary |-
62
- c3BlYy9vYmplY3Rfc2V0X3NwZWMucmI=
63
- - !binary |-
64
- c3BlYy9zaGFyZWQvbmFtaW5nX2JlaGF2aW9yX2V4YW1wbGVzLnJi
65
- - !binary |-
66
- c3BlYy9zaGFyZWQvdmlzaXRvcl9iZWhhdmlvcl9leGFtcGxlcy5yYg==
67
- - !binary |-
68
- c3BlYy9zcGVjX2hlbHBlci5yYg==
20
+ - .gitignore
21
+ - .ruby-gemset
22
+ - .ruby-version
23
+ - .travis.yml
24
+ - CHANGELOG
25
+ - Gemfile
26
+ - LICENSE.txt
27
+ - NOTES.md
28
+ - README.md
29
+ - Rakefile
30
+ - katuv.gemspec
31
+ - lib/katuv.rb
32
+ - lib/katuv/dsl.rb
33
+ - lib/katuv/naming_behavior.rb
34
+ - lib/katuv/node.rb
35
+ - lib/katuv/node_behavior.rb
36
+ - lib/katuv/object_set.rb
37
+ - lib/katuv/version.rb
38
+ - lib/katuv/visitor_behavior.rb
39
+ - spec/integration/dsl_integration_spec.rb
40
+ - spec/shared/naming_behavior_examples.rb
41
+ - spec/shared/visitor_behavior_examples.rb
42
+ - spec/spec_helper.rb
43
+ - spec/unit/dsl_spec.rb
44
+ - spec/unit/node_spec.rb
45
+ - spec/unit/object_set_spec.rb
69
46
  homepage: ''
70
47
  licenses: []
48
+ metadata: {}
71
49
  post_install_message:
72
50
  rdoc_options: []
73
51
  require_paths:
74
52
  - lib
75
53
  required_ruby_version: !ruby/object:Gem::Requirement
76
- none: false
77
54
  requirements:
78
55
  - - ! '>='
79
56
  - !ruby/object:Gem::Version
80
- segments:
81
- - 0
82
- hash: 2002549777813010636
83
- version: '0'
57
+ version: !binary |-
58
+ MA==
84
59
  required_rubygems_version: !ruby/object:Gem::Requirement
85
- none: false
86
60
  requirements:
87
61
  - - ! '>='
88
62
  - !ruby/object:Gem::Version
89
- segments:
90
- - 0
91
- hash: 2002549777813010636
92
- version: '0'
63
+ version: !binary |-
64
+ MA==
93
65
  requirements: []
94
66
  rubyforge_project:
95
- rubygems_version: 1.8.25
67
+ rubygems_version: 2.0.6
96
68
  signing_key:
97
- specification_version: 3
69
+ specification_version: 4
98
70
  summary: A tool for parsing and transforming internal Ruby DSLs
99
71
  test_files:
100
- - !binary |-
101
- c3BlYy9kc2xfc3BlYy5yYg==
102
- - !binary |-
103
- c3BlYy9ub2RlX3NwZWMucmI=
104
- - !binary |-
105
- c3BlYy9vYmplY3Rfc2V0X3NwZWMucmI=
106
- - !binary |-
107
- c3BlYy9zaGFyZWQvbmFtaW5nX2JlaGF2aW9yX2V4YW1wbGVzLnJi
108
- - !binary |-
109
- c3BlYy9zaGFyZWQvdmlzaXRvcl9iZWhhdmlvcl9leGFtcGxlcy5yYg==
110
- - !binary |-
111
- c3BlYy9zcGVjX2hlbHBlci5yYg==
72
+ - spec/integration/dsl_integration_spec.rb
73
+ - spec/shared/naming_behavior_examples.rb
74
+ - spec/shared/visitor_behavior_examples.rb
75
+ - spec/spec_helper.rb
76
+ - spec/unit/dsl_spec.rb
77
+ - spec/unit/node_spec.rb
78
+ - spec/unit/object_set_spec.rb
data/.rvmrc DELETED
@@ -1,2 +0,0 @@
1
- RVM_STRING="rvm use rbx-head@katuv --create --verbose"
2
- [ -e './.rvmrc_local' ] && source './.rvmrc_local' || $RVM_STRING
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'The Katuv DSL' do
4
- before :all do
5
- class Example
6
- end
7
- end
8
- subject { Example }
9
-
10
- context 'before inclusion' do
11
- describe 'api' do
12
- it { should_not respond_to :terminal }
13
- it { should_not respond_to :nonterminal }
14
- it { should_not respond_to :multiple }
15
- end
16
- end
17
-
18
- context 'after inclusion' do
19
- before do
20
- class Example
21
- include Katuv::Node
22
- end
23
- end
24
-
25
- describe 'api' do
26
- it { should respond_to :terminal }
27
- it { should respond_to :nonterminal }
28
- it { should respond_to :multiple }
29
- end
30
- end
31
- end