katuv 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1,2 @@
1
+ RVM_STRING="rvm use rbx-head@katuv --create --verbose"
2
+ [ -e './.rvmrc_local' ] && source './.rvmrc_local' || $RVM_STRING
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rspec'
4
+ gem 'rspec-spies'
5
+
6
+ gem 'pry'
7
+
8
+ # Specify your gem's dependencies in katuv.gemspec
9
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Joe Fredette
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Katuv
2
+
3
+ Katuv is a tool for defining and transforming Embedded Ruby DSLs (EDSLs). It
4
+ provides a simple facility to define DSL components and their connections.
5
+
6
+ ## Naming
7
+
8
+ The word [katúv](http://en.wiktionary.org/wiki/%D7%A0%D7%9B%D7%AA%D7%91#Hebrew)
9
+ (Hebrew: 'כָּתוּב') means 'written.' I chose the name as it seemed appropriate with
10
+ this tools purpose (parsing and transforming embedded Ruby DSLs) and as it also
11
+ fit with it's parent project, Exegesis, in terms of tone and subject matter. I
12
+ had thought to use `Mikra` -- but decided that would be inappropriate as it is
13
+ used to [refer](http://en.wikipedia.org/wiki/Mikra) to the Jewish Bible,
14
+ commonly known as the Tanakh. I like interesting names, as they give me an
15
+ opportunity to tell people about interesting things, so I hope you found this
16
+ interesting.
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ gem 'katuv'
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install katuv
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/katuv.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'katuv/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "katuv"
8
+ gem.version = Katuv::VERSION
9
+ gem.authors = ["Joe Fredette"]
10
+ gem.email = ["jfredett@gmail.com"]
11
+ gem.description = %q{A tool for parsing and transforming internal Ruby DSLs}
12
+ gem.summary = %q{A tool for parsing and transforming internal Ruby DSLs}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
data/lib/katuv.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "katuv/version"
2
+
3
+ module Katuv
4
+ # Your code goes here...
5
+ end
data/lib/katuv/node.rb ADDED
@@ -0,0 +1,114 @@
1
+ # Represents a single node in the AST of a project structure
2
+ module Katuv
3
+ module Node
4
+ def self.included(base)
5
+ base.send(:include, InstanceMethods)
6
+ base.send(:extend, ClassMethods)
7
+ base.send(:include, Enumerable)
8
+ end
9
+
10
+ module InstanceMethods
11
+ #this is terrible
12
+ def method_name
13
+ #get the classname
14
+ self.class.name.
15
+ #remove the module
16
+ to_s.split('::').last.
17
+ #convert FooBar -> _Foo_Bar
18
+ gsub(/[A-Z]/, '_\&').
19
+ #drop the leading _
20
+ gsub(/^_/, '').
21
+ #downcase everything to get foo_bar
22
+ downcase.to_sym
23
+ end
24
+
25
+ def visit(visitor)
26
+ visitor.before_visit!(self)
27
+ visitor.call(self)
28
+
29
+ each do |c|
30
+ c.visit(visitor)
31
+ end
32
+
33
+ visitor.after_visit!(self)
34
+ nil
35
+ end
36
+
37
+ def run
38
+ end
39
+
40
+ def each(&block)
41
+ children.values.each(&block)
42
+ end
43
+
44
+ def children
45
+ @children ||= {}
46
+ end
47
+
48
+ def name
49
+ @name || self.class.name
50
+ end
51
+
52
+ def initialize(name = nil, opts = {}, &block)
53
+ @parent = opts[:parent]
54
+ @name = name
55
+ @opts = opts
56
+ instance_eval &block if block_given?
57
+ end
58
+ attr_reader :parent, :name
59
+
60
+ def terminal?
61
+ self.class.terminal?
62
+ end
63
+
64
+ def has_children?
65
+ children.any?
66
+ end
67
+ end
68
+
69
+ module ClassMethods
70
+ def nonterminal(type)
71
+ raise "NonterminalInTerminalError" if terminal?
72
+ define_method(_type_to_method_name(type)) do |name=nil, opts={}, &block|
73
+ if children.has_key?(type) and children[type]
74
+ children[type].run(&block)
75
+ else
76
+ children[type] = type.new(name, opts.merge({parent: self}), &block)
77
+ end
78
+ children[type]
79
+ end
80
+ end
81
+
82
+ def terminal(type)
83
+ #should only allow one.
84
+ raise "InvalidNodeTypeError" unless type.terminal?
85
+ define_method(_type_to_method_name(type)) do |name=nil, opts={}, &block|
86
+ raise "TerminalAlreadySetError" if children.has_key?(type)
87
+ children[type] = type.new(name, opts.merge({parent: self}), &block)
88
+ end
89
+ end
90
+ def terminal!
91
+ define_singleton_method(:terminal?) { true }
92
+ end
93
+ def terminal?; false end
94
+
95
+ def multiple(type)
96
+ #should store an entry in #children that is a list of all the instances
97
+ #it sees of this type. eg, `file 'x'; file 'y' #=> children[File] = [File<@name=x>, File<@name=y>]
98
+ raise "InvalidNodeTypeError" unless type.terminal?
99
+ define_method(_type_to_method_name(type)) do |name, opts={}, &block|
100
+ children[type] ||= ObjectSet.new
101
+ children[type] << type.new(name, opts.merge({parent: self}), &block)
102
+ end
103
+ end
104
+
105
+ def _type_to_method_name(type)
106
+ if type.respond_to?(:name)
107
+ type.name
108
+ else
109
+ type.to_s
110
+ end.split('::').last.downcase
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,3 @@
1
+ module Katuv
2
+ VERSION = "0.0.1"
3
+ end
data/spec/node_spec.rb ADDED
@@ -0,0 +1 @@
1
+ require 'spec_helper'
@@ -0,0 +1,27 @@
1
+ require 'bundler/setup'
2
+
3
+ require 'pry'
4
+
5
+ require 'katuv'
6
+
7
+ require 'rspec-spies'
8
+
9
+ #include helpers
10
+ Dir["./spec/helpers/*.rb"].each { |file| require file }
11
+
12
+ #include shared examples
13
+ Dir["./spec/shared/*_examples.rb"].each { |file| require file }
14
+
15
+ RSpec.configure do |config|
16
+ config.before do
17
+ allow_message_expectations_on_nil
18
+ end
19
+
20
+ config.treat_symbols_as_metadata_keys_with_true_values = true
21
+ end
22
+
23
+ class RSpec::Mocks::Mock
24
+ def inspect
25
+ "double(#{@name.inspect})"
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: katuv
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Joe Fredette
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-24 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A tool for parsing and transforming internal Ruby DSLs
15
+ email:
16
+ - jfredett@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - !binary |-
22
+ LmdpdGlnbm9yZQ==
23
+ - !binary |-
24
+ LnJ2bXJj
25
+ - !binary |-
26
+ R2VtZmlsZQ==
27
+ - !binary |-
28
+ TElDRU5TRS50eHQ=
29
+ - !binary |-
30
+ UkVBRE1FLm1k
31
+ - !binary |-
32
+ UmFrZWZpbGU=
33
+ - !binary |-
34
+ a2F0dXYuZ2Vtc3BlYw==
35
+ - !binary |-
36
+ bGliL2thdHV2LnJi
37
+ - !binary |-
38
+ bGliL2thdHV2L25vZGUucmI=
39
+ - !binary |-
40
+ bGliL2thdHV2L3ZlcnNpb24ucmI=
41
+ - !binary |-
42
+ c3BlYy9ub2RlX3NwZWMucmI=
43
+ - !binary |-
44
+ c3BlYy9zcGVjX2hlbHBlci5yYg==
45
+ homepage: ''
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ none: false
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ none: false
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.25
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: A tool for parsing and transforming internal Ruby DSLs
69
+ test_files:
70
+ - !binary |-
71
+ c3BlYy9ub2RlX3NwZWMucmI=
72
+ - !binary |-
73
+ c3BlYy9zcGVjX2hlbHBlci5yYg==