enterprise 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,23 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'autotest/restart'
4
+
5
+ # Autotest.add_hook :initialize do |at|
6
+ # at.extra_files << "../some/external/dependency.rb"
7
+ #
8
+ # at.libs << ":../some/external"
9
+ #
10
+ # at.add_exception 'vendor'
11
+ #
12
+ # at.add_mapping(/dependency.rb/) do |f, _|
13
+ # at.files_matching(/test_.*rb$/)
14
+ # end
15
+ #
16
+ # %w(TestA TestB).each do |klass|
17
+ # at.extra_class_map[klass] = "test/test_misc.rb"
18
+ # end
19
+ # end
20
+
21
+ # Autotest.add_hook :run_command do |at|
22
+ # system "rake build"
23
+ # end
@@ -0,0 +1,7 @@
1
+ === 1.0.0 / 2009-06-17
2
+
3
+ * 1 major enhancement
4
+
5
+ * Entering in to the enterprise
6
+ * Bringing ruby in the back door
7
+
@@ -0,0 +1,14 @@
1
+ .autotest
2
+ CHANGELOG.rdoc
3
+ Manifest.txt
4
+ README.rdoc
5
+ Rakefile
6
+ bin/enterprise
7
+ bin/enterprise_ruby
8
+ lib/enterprise.rb
9
+ lib/enterprise/file_loader.rb
10
+ lib/enterprise/sexml.rb
11
+ lib/enterprise/sexp_hacks.rb
12
+ test/assets/hello_world.xml
13
+ test/assets/reference.rb
14
+ test/test_enterprise.rb
@@ -0,0 +1,167 @@
1
+ = enterprise
2
+
3
+ * http://github.com/tenderlove/enterprise/
4
+
5
+ == DESCRIPTION:
6
+
7
+ Wish you could write your Ruby in XML? Has the fact that Ruby is not
8
+ "enterprise" got you down? Do you feel like your Ruby code could be made to
9
+ be more "scalable"? Well look no further my friend. You've found the
10
+ enterprise gem. Once you install this gem, you too can make Rails scale, Ruby
11
+ faster, your code more attractive, *and* have more XML in your life.
12
+
13
+ I'm sure you're asking yourself, "how can the enterprise gem promise so
14
+ much?". Well the answer is easy, through the magic of XML! The enterprise
15
+ gem allows you to write your Ruby code in XML, therefore making your Ruby and
16
+ Rails code scale. Benefits of writing your code in XML include:
17
+
18
+ * It's easy to read!
19
+ * It scales!
20
+ * Cross platform
21
+ * TRANSFORM! your code using XSLT!
22
+ * Search your AST with XPath *or* CSS!
23
+
24
+ The enterprise gem even comes with a handy "enterprise" binary to help you
25
+ start converting your existing *legacy* Ruby code in to scaleable, easy to
26
+ read XML files. Let's start getting rid of that nasty Ruby code and replacing
27
+ it with XML today!
28
+
29
+ == FEATURES/PROBLEMS:
30
+
31
+ * require files completely written in XML
32
+ * convert existing legacy ruby code to XML
33
+
34
+ == SYNOPSIS:
35
+
36
+ Let's say you have some legacy Ruby code that looks like this:
37
+
38
+ class Foo
39
+ def hello_world
40
+ "bar"
41
+ end
42
+ end
43
+
44
+ puts Foo.new.hello_world
45
+
46
+ Let's convert that crappy ruby code to XML:
47
+
48
+ <?xml version="1.0"?>
49
+ <s>
50
+ <block type="Symbol" value="block"/>
51
+ <s>
52
+ <class type="Symbol" value="class"/>
53
+ <Foo type="Symbol" value="Foo"/>
54
+ <special type="NilClass" value=""/>
55
+ <s>
56
+ <scope type="Symbol" value="scope"/>
57
+ <s>
58
+ <defn type="Symbol" value="defn"/>
59
+ <special type="Symbol" value="hello_world"/>
60
+ <s>
61
+ <args type="Symbol" value="args"/>
62
+ </s>
63
+ <s>
64
+ <scope type="Symbol" value="scope"/>
65
+ <s>
66
+ <block type="Symbol" value="block"/>
67
+ <s>
68
+ <str type="Symbol" value="str"/>
69
+ <bar type="String" value="bar"/>
70
+ </s>
71
+ </s>
72
+ </s>
73
+ </s>
74
+ </s>
75
+ </s>
76
+ <s>
77
+ <call type="Symbol" value="call"/>
78
+ <special type="NilClass" value=""/>
79
+ <puts type="Symbol" value="puts"/>
80
+ <s>
81
+ <arglist type="Symbol" value="arglist"/>
82
+ <s>
83
+ <call type="Symbol" value="call"/>
84
+ <s>
85
+ <call type="Symbol" value="call"/>
86
+ <s>
87
+ <const type="Symbol" value="const"/>
88
+ <Foo type="Symbol" value="Foo"/>
89
+ </s>
90
+ <new type="Symbol" value="new"/>
91
+ <s>
92
+ <arglist type="Symbol" value="arglist"/>
93
+ </s>
94
+ </s>
95
+ <special type="Symbol" value="hello_world"/>
96
+ <s>
97
+ <arglist type="Symbol" value="arglist"/>
98
+ </s>
99
+ </s>
100
+ </s>
101
+ </s>
102
+ </s>
103
+
104
+ Now, simply save that XML file out to "test.xml". With the enterprise gem,
105
+ to execute this xml file, we just do:
106
+
107
+ $ enterprise_ruby test.xml
108
+
109
+ enterprise lets you do a require on pure xml files too. We can load the
110
+ test.xml file like so:
111
+
112
+ require 'rubygems'
113
+ require 'enterprise'
114
+ require 'test'
115
+
116
+ The final feature is an enterprise migration assistant. To migrate an entire
117
+ project to be enterprise, just do this:
118
+
119
+ $ enterprise some_directory
120
+
121
+ To make a single file enterprise, just give it the filename:
122
+
123
+ $ enterprise some_file.rb
124
+
125
+ I'm sure you're asking yourself, "how much does this enterprise solution cost
126
+ me?". Well, like any good enterprise system, it is insanely expensive. This
127
+ gem will cost you eleventy billion dollars payable to me, now.
128
+
129
+ == REQUIREMENTS:
130
+
131
+ Like all good enterprise solutions, we do our best to get you stuck in a web
132
+ of dependencies. We are working hard to increase the number of dependencies,
133
+ but here is the current list
134
+
135
+ * ruby2ruby
136
+ * ruby_parser
137
+ * nokogiri
138
+ * polyglot
139
+
140
+ == INSTALL:
141
+
142
+ * sudo gem install enterprise
143
+
144
+ == LICENSE:
145
+
146
+ (The MIT License)
147
+
148
+ Copyright (c) 2009 Aaron Patterson
149
+
150
+ Permission is hereby granted, free of charge, to any person obtaining
151
+ a copy of this software and associated documentation files (the
152
+ 'Software'), to deal in the Software without restriction, including
153
+ without limitation the rights to use, copy, modify, merge, publish,
154
+ distribute, sublicense, and/or sell copies of the Software, and to
155
+ permit persons to whom the Software is furnished to do so, subject to
156
+ the following conditions:
157
+
158
+ The above copyright notice and this permission notice shall be
159
+ included in all copies or substantial portions of the Software.
160
+
161
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
162
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
163
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
164
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
165
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
166
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
167
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,15 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.spec 'enterprise' do
7
+ developer('Aaron Patterson', 'aaronp@rubyforge.org')
8
+ self.readme_file = 'README.rdoc'
9
+ self.history_file = 'CHANGELOG.rdoc'
10
+ self.extra_rdoc_files = FileList['*.rdoc']
11
+ self.extra_deps = ['ruby2ruby', 'ruby_parser', 'nokogiri', 'polyglot']
12
+ self.rubyforge_name = 'seattlerb'
13
+ end
14
+
15
+ # vim: syntax=ruby
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'enterprise'
5
+ require 'find'
6
+
7
+ if File.directory? ARGV[0]
8
+ Find.find ARGV[0] do |file|
9
+ next if File.directory? file
10
+ next unless File.extname(file) == '.rb'
11
+ sexml = Enterprise::SEXML File.read(file), file
12
+ File.open(file.sub(/\.rb/, '.xml'), 'wb') { |f|
13
+ sexml.write_to f
14
+ }
15
+ end
16
+ else
17
+ sexml = Enterprise::SEXML File.read(ARGV[0]), ARGV[0]
18
+ File.open(ARGV[0].sub(/\.rb/, '.xml'), 'wb') { |f|
19
+ sexml.write_to f
20
+ }
21
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'enterprise'
5
+
6
+ Enterprise::FileLoader.load ARGV[0]
@@ -0,0 +1,12 @@
1
+ require 'nokogiri'
2
+ require 'ruby_parser'
3
+ require 'ruby2ruby'
4
+ require 'polyglot'
5
+
6
+ require 'enterprise/sexml'
7
+ require 'enterprise/file_loader'
8
+ require 'enterprise/sexp_hacks'
9
+
10
+ module Enterprise
11
+ VERSION = '1.0.0'
12
+ end
@@ -0,0 +1,10 @@
1
+ module Enterprise
2
+ module FileLoader
3
+ def self.load filename, options = nil, &block
4
+ sexml = Nokogiri::XML(File.read(filename)) { |cmd| cmd.noblanks }
5
+ Kernel.eval sexml.to_ruby, TOPLEVEL_BINDING
6
+ end
7
+ end
8
+ end
9
+
10
+ Polyglot.register 'xml', Enterprise::FileLoader
@@ -0,0 +1,48 @@
1
+ require 'nokogiri'
2
+ require 'ruby2ruby'
3
+
4
+ module Enterprise
5
+ def self.SEXML codes, filename = nil
6
+ sexp = RubyParser.new.parse codes, filename
7
+ sexp.to_xml
8
+ end
9
+
10
+ class XMLToSexp
11
+ def visit node
12
+ if ! node['value']
13
+ return s(*node.children.map { |child| child.accept self })
14
+ else
15
+ case node['type']
16
+ when 'Symbol'
17
+ node['value'].to_sym
18
+ when 'Regexp'
19
+ Marshal.load node['value'].unpack('m').first
20
+ when 'NilClass'
21
+ nil
22
+ when 'Fixnum', 'Bignum'
23
+ Integer(node['value'])
24
+ when 'Float'
25
+ Float(node['value'])
26
+ else
27
+ node['value']
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ class Nokogiri::XML::Node
35
+ def to_sexp
36
+ accept Enterprise::XMLToSexp.new
37
+ end
38
+
39
+ def to_ruby
40
+ Ruby2Ruby.new.process(to_sexp)
41
+ end
42
+ end
43
+
44
+ class Nokogiri::XML::Document
45
+ def to_ruby
46
+ Ruby2Ruby.new.process(root.to_sexp)
47
+ end
48
+ end
@@ -0,0 +1,31 @@
1
+ class Sexp
2
+ include Nokogiri::XML
3
+
4
+ def to_xml doc = Document.new, parent = doc.root = Node.new('s', doc)
5
+ each do |node|
6
+ case node
7
+ when Sexp
8
+ new_parent = Node.new('s', parent.document)
9
+ parent.add_child new_parent
10
+ node.to_xml doc, new_parent
11
+ else
12
+ name = node.to_s
13
+ if node.to_s.empty? || node.to_s !~ /^[A-Za-z]+$/
14
+ name = 'special'
15
+ end
16
+
17
+ n = Node.new(name, parent.document)
18
+ n['type'] = node.class.name
19
+
20
+ if Regexp === node
21
+ n['value'] = [Marshal.dump(node)].pack('m')
22
+ else
23
+ n['value'] = node.to_s
24
+ end
25
+
26
+ parent << n
27
+ end
28
+ end
29
+ doc
30
+ end
31
+ end
@@ -0,0 +1,41 @@
1
+ <?xml version="1.0"?>
2
+ <s>
3
+ <class type="Symbol" value="class"/>
4
+ <HelloWorld type="Symbol" value="HelloWorld"/>
5
+ <special type="NilClass" value=""/>
6
+ <s>
7
+ <scope type="Symbol" value="scope"/>
8
+ <s>
9
+ <defn type="Symbol" value="defn"/>
10
+ <innernet type="Symbol" value="innernet"/>
11
+ <s>
12
+ <args type="Symbol" value="args"/>
13
+ </s>
14
+ <s>
15
+ <scope type="Symbol" value="scope"/>
16
+ <s>
17
+ <block type="Symbol" value="block"/>
18
+ <s>
19
+ <call type="Symbol" value="call"/>
20
+ <s>
21
+ <str type="Symbol" value="str"/>
22
+ <special type="String" value="the innernet is awesome"/>
23
+ </s>
24
+ <sub type="Symbol" value="sub"/>
25
+ <s>
26
+ <arglist type="Symbol" value="arglist"/>
27
+ <s>
28
+ <lit type="Symbol" value="lit"/>
29
+ <special type="Regexp" value="BAgvB25uAA==&#10;"/>
30
+ </s>
31
+ <s>
32
+ <str type="Symbol" value="str"/>
33
+ <bar type="String" value="bar"/>
34
+ </s>
35
+ </s>
36
+ </s>
37
+ </s>
38
+ </s>
39
+ </s>
40
+ </s>
41
+ </s>
@@ -0,0 +1,5 @@
1
+ class HelloWorld
2
+ def innernet
3
+ "the innernet is awesome".sub(/nn/, 'bar')
4
+ end
5
+ end
@@ -0,0 +1,39 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'enterprise'
4
+
5
+ class TestEnterprise < Test::Unit::TestCase
6
+ def setup
7
+ @filename = File.join(File.dirname(__FILE__), 'assets', 'reference.rb')
8
+ @codes = File.read(@filename)
9
+ end
10
+
11
+ def teardown
12
+ Object.send(:remove_const, :HelloWorld) if defined? HelloWorld
13
+ end
14
+
15
+ def test_sexp_parse
16
+ sexml = Enterprise::SEXML @codes, @filename
17
+ assert sexml
18
+ assert_equal 11, sexml.css('s').length
19
+ end
20
+
21
+ def test_sexml_can_be_converted_to_sexp
22
+ sexml = Enterprise::SEXML @codes, @filename
23
+ ruby_codes = sexml.to_sexp
24
+ assert_instance_of Sexp, ruby_codes
25
+ end
26
+
27
+ def test_sexml_can_be_converted_to_ruby
28
+ sexml = Enterprise::SEXML @codes, @filename
29
+ ruby_codes = sexml.to_ruby
30
+ m = Module.new
31
+ m.module_eval ruby_codes
32
+ assert m::HelloWorld.new.innernet
33
+ end
34
+
35
+ def test_require_some_xml
36
+ require 'assets/hello_world'
37
+ assert_equal 'the ibarernet is awesome', ::HelloWorld.new.innernet
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: enterprise
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Patterson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-17 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ruby2ruby
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: ruby_parser
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: nokogiri
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: polyglot
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: hoe
57
+ type: :development
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.2.0
64
+ version:
65
+ description: |-
66
+ Wish you could write your Ruby in XML? Has the fact that Ruby is not
67
+ "enterprise" got you down? Do you feel like your Ruby code could be made to
68
+ be more "scalable"? Well look no further my friend. You've found the
69
+ enterprise gem. Once you install this gem, you too can make Rails scale, Ruby
70
+ faster, your code more attractive, *and* have more XML in your life.
71
+
72
+ I'm sure you're asking yourself, "how can the enterprise gem promise so
73
+ much?". Well the answer is easy, through the magic of XML! The enterprise
74
+ gem allows you to write your Ruby code in XML, therefore making your Ruby and
75
+ Rails code scale. Benefits of writing your code in XML include:
76
+
77
+ * It's easy to read!
78
+ * It scales!
79
+ * Cross platform
80
+ * TRANSFORM! your code using XSLT!
81
+ * Search your AST with XPath *or* CSS!
82
+
83
+ The enterprise gem even comes with a handy "enterprise" binary to help you
84
+ start converting your existing *legacy* Ruby code in to scaleable, easy to
85
+ read XML files. Let's start getting rid of that nasty Ruby code and replacing
86
+ it with XML today!
87
+ email:
88
+ - aaronp@rubyforge.org
89
+ executables:
90
+ - enterprise
91
+ - enterprise_ruby
92
+ extensions: []
93
+
94
+ extra_rdoc_files:
95
+ - Manifest.txt
96
+ - CHANGELOG.rdoc
97
+ - README.rdoc
98
+ files:
99
+ - .autotest
100
+ - CHANGELOG.rdoc
101
+ - Manifest.txt
102
+ - README.rdoc
103
+ - Rakefile
104
+ - bin/enterprise
105
+ - bin/enterprise_ruby
106
+ - lib/enterprise.rb
107
+ - lib/enterprise/file_loader.rb
108
+ - lib/enterprise/sexml.rb
109
+ - lib/enterprise/sexp_hacks.rb
110
+ - test/assets/hello_world.xml
111
+ - test/assets/reference.rb
112
+ - test/test_enterprise.rb
113
+ has_rdoc: true
114
+ homepage: http://github.com/tenderlove/enterprise/
115
+ licenses: []
116
+
117
+ post_install_message:
118
+ rdoc_options:
119
+ - --main
120
+ - README.rdoc
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: "0"
128
+ version:
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: "0"
134
+ version:
135
+ requirements: []
136
+
137
+ rubyforge_project: seattlerb
138
+ rubygems_version: 1.3.4
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: Wish you could write your Ruby in XML? Has the fact that Ruby is not "enterprise" got you down? Do you feel like your Ruby code could be made to be more "scalable"? Well look no further my friend
142
+ test_files:
143
+ - test/test_enterprise.rb