reactive 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/History.txt +3 -0
  2. data/MIT-LICENSE +21 -0
  3. data/Manifest.txt +60 -0
  4. data/README.txt +130 -0
  5. data/Rakefile +14 -0
  6. data/app_generators/reactive/USAGE +11 -0
  7. data/app_generators/reactive/reactive_generator.rb +160 -0
  8. data/app_generators/reactive/templates/README +130 -0
  9. data/app_generators/reactive/templates/Rakefile +10 -0
  10. data/app_generators/reactive/templates/app/controllers/application_controller.rb +2 -0
  11. data/app_generators/reactive/templates/app/helpers/application_helper.rb +2 -0
  12. data/app_generators/reactive/templates/config/boot.rb +94 -0
  13. data/app_generators/reactive/templates/config/databases/frontbase.yml +28 -0
  14. data/app_generators/reactive/templates/config/databases/mysql.yml +54 -0
  15. data/app_generators/reactive/templates/config/databases/oracle.yml +39 -0
  16. data/app_generators/reactive/templates/config/databases/postgresql.yml +48 -0
  17. data/app_generators/reactive/templates/config/databases/sqlite2.yml +16 -0
  18. data/app_generators/reactive/templates/config/databases/sqlite3.yml +19 -0
  19. data/app_generators/reactive/templates/config/empty.log +0 -0
  20. data/app_generators/reactive/templates/config/environment.rb +11 -0
  21. data/app_generators/reactive/templates/script/destroy +12 -0
  22. data/app_generators/reactive/templates/script/generate +12 -0
  23. data/app_generators/reactive/templates/script/run +5 -0
  24. data/app_generators/reactive/templates/script/win_script.cmd +1 -0
  25. data/bin/reactive +16 -0
  26. data/lib/code_statistics.rb +107 -0
  27. data/lib/controller.rb +23 -0
  28. data/lib/controller/base.rb +442 -0
  29. data/lib/controller/filters.rb +767 -0
  30. data/lib/controller/flash.rb +161 -0
  31. data/lib/controller/helpers.rb +204 -0
  32. data/lib/controller/layout.rb +326 -0
  33. data/lib/dispatcher.rb +46 -0
  34. data/lib/generated_attribute.rb +40 -0
  35. data/lib/initializer.rb +425 -0
  36. data/lib/named_base_generator.rb +92 -0
  37. data/lib/reactive.rb +6 -0
  38. data/lib/request.rb +17 -0
  39. data/lib/source_annotation_extractor.rb +62 -0
  40. data/lib/tasks/annotations.rake +23 -0
  41. data/lib/tasks/databases.rake +347 -0
  42. data/lib/tasks/log.rake +9 -0
  43. data/lib/tasks/misc.rake +5 -0
  44. data/lib/tasks/reactive.rb +16 -0
  45. data/lib/tasks/statistics.rake +17 -0
  46. data/lib/tasks/testing.rake +118 -0
  47. data/lib/version.rb +9 -0
  48. data/lib/view.rb +1 -0
  49. data/lib/view/base.rb +33 -0
  50. data/reactive_generators/model/USAGE +27 -0
  51. data/reactive_generators/model/model_generator.rb +52 -0
  52. data/reactive_generators/model/templates/fixtures.yml +19 -0
  53. data/reactive_generators/model/templates/migration.rb +16 -0
  54. data/reactive_generators/model/templates/model.rb +2 -0
  55. data/reactive_generators/model/templates/unit_test.rb +8 -0
  56. data/reactive_generators/scaffold/USAGE +26 -0
  57. data/reactive_generators/scaffold/scaffold_generator.rb +75 -0
  58. data/reactive_generators/scaffold/templates/controller.rb +51 -0
  59. data/reactive_generators/scaffold/templates/functional_test.rb +49 -0
  60. data/reactive_generators/scaffold/templates/helper.rb +2 -0
  61. metadata +142 -0
@@ -0,0 +1,10 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # and they will automatically be available to Rake.
3
+
4
+ require(File.join(File.dirname(__FILE__), 'config', 'boot'))
5
+
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+ require 'rake/rdoctask'
9
+
10
+ require 'tasks/reactive'
@@ -0,0 +1,2 @@
1
+ class ApplicationController < Reactive::Controller::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,94 @@
1
+
2
+ REACTIVE_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(REACTIVE_ROOT)
3
+
4
+ module Reactive
5
+ class << self
6
+ def boot
7
+ Boot.new.boot unless booted?
8
+ end
9
+
10
+ def booted?
11
+ defined? Reactive::Initializer
12
+ end
13
+
14
+ def run
15
+ Boot.new.run
16
+ end
17
+ end
18
+
19
+ class Boot
20
+ def initialize
21
+ load_initializer
22
+ end
23
+
24
+ def boot
25
+ Reactive::Initializer.run
26
+ end
27
+
28
+ def run
29
+ boot
30
+ Dispatcher.dispatch(:init)
31
+ end
32
+
33
+ def load_initializer
34
+ self.class.load_rubygems
35
+
36
+ # add apps gem directory to load path
37
+ Gem.clear_paths
38
+ Gem.path.unshift("#{REACTIVE_ROOT}/gems")
39
+
40
+ load_reactive_gem
41
+ require 'initializer'
42
+ end
43
+
44
+ def load_reactive_gem
45
+ if version = self.class.gem_version
46
+ gem 'reactive', version
47
+ else
48
+ gem 'reactive'
49
+ end
50
+ rescue Gem::LoadError => load_error
51
+ $stderr.puts %(Missing the Reactive #{version} gem. Please `gem install -v=#{version} reactive`, update your REACTIVE_GEM_VERSION setting in config/environment.rb for the Reactive version you do have installed, or comment out REACTIVE_GEM_VERSION to use the latest version installed.)
52
+ exit 1
53
+ end
54
+
55
+ class << self
56
+ def rubygems_version
57
+ Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
58
+ end
59
+
60
+ def gem_version
61
+ if defined? REACTIVE_GEM_VERSION
62
+ REACTIVE_GEM_VERSION
63
+ elsif ENV.include?('REACTIVE_GEM_VERSION')
64
+ ENV['REACTIVE_GEM_VERSION']
65
+ else
66
+ parse_gem_version(read_environment_rb)
67
+ end
68
+ end
69
+
70
+ def load_rubygems
71
+ require 'rubygems'
72
+
73
+ unless rubygems_version >= '0.9.4'
74
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
75
+ exit 1
76
+ end
77
+
78
+ rescue LoadError
79
+ $stderr.puts %(Reactive requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
80
+ exit 1
81
+ end
82
+
83
+ def parse_gem_version(text)
84
+ $1 if text =~ /^[^#]*REACTIVE_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
85
+ end
86
+
87
+ private
88
+ def read_environment_rb
89
+ File.read("#{REACTIVE_ROOT}/config/environment.rb")
90
+ end
91
+ end
92
+ end
93
+
94
+ end
@@ -0,0 +1,28 @@
1
+ # FrontBase versions 4.x
2
+ #
3
+ # Get the bindings:
4
+ # gem install ruby-frontbase
5
+
6
+ development:
7
+ adapter: frontbase
8
+ host: localhost
9
+ database: <%= app_name %>_development
10
+ username: <%= app_name %>
11
+ password: ''
12
+
13
+ # Warning: The database defined as 'test' will be erased and
14
+ # re-generated from your development database when you run 'rake'.
15
+ # Do not set this db to the same as development or production.
16
+ test:
17
+ adapter: frontbase
18
+ host: localhost
19
+ database: <%= app_name %>_test
20
+ username: <%= app_name %>
21
+ password: ''
22
+
23
+ production:
24
+ adapter: frontbase
25
+ host: localhost
26
+ database: <%= app_name %>_production
27
+ username: <%= app_name %>
28
+ password: ''
@@ -0,0 +1,54 @@
1
+ # MySQL. Versions 4.1 and 5.0 are recommended.
2
+ #
3
+ # Install the MySQL driver:
4
+ # gem install mysql
5
+ # On Mac OS X:
6
+ # sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
7
+ # On Mac OS X Leopard:
8
+ # sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
9
+ # This sets the ARCHFLAGS environment variable to your native architecture
10
+ # On Windows:
11
+ # gem install mysql
12
+ # Choose the win32 build.
13
+ # Install MySQL and put its /bin directory on your path.
14
+ #
15
+ # And be sure to use new-style password hashing:
16
+ # http://dev.mysql.com/doc/refman/5.0/en/old-client.html
17
+ development:
18
+ adapter: mysql
19
+ encoding: utf8
20
+ database: <%= app_name %>_development
21
+ username: root
22
+ password:
23
+ <% if socket -%>
24
+ socket: <%= socket %>
25
+ <% else -%>
26
+ host: localhost
27
+ <% end -%>
28
+
29
+ # Warning: The database defined as 'test' will be erased and
30
+ # re-generated from your development database when you run 'rake'.
31
+ # Do not set this db to the same as development or production.
32
+ test:
33
+ adapter: mysql
34
+ encoding: utf8
35
+ database: <%= app_name %>_test
36
+ username: root
37
+ password:
38
+ <% if socket -%>
39
+ socket: <%= socket %>
40
+ <% else -%>
41
+ host: localhost
42
+ <% end -%>
43
+
44
+ production:
45
+ adapter: mysql
46
+ encoding: utf8
47
+ database: <%= app_name %>_production
48
+ username: root
49
+ password:
50
+ <% if socket -%>
51
+ socket: <%= socket %>
52
+ <% else -%>
53
+ host: localhost
54
+ <% end -%>
@@ -0,0 +1,39 @@
1
+ # Oracle/OCI 8i, 9, 10g
2
+ #
3
+ # Requires Ruby/OCI8:
4
+ # http://rubyforge.org/projects/ruby-oci8/
5
+ #
6
+ # Specify your database using any valid connection syntax, such as a
7
+ # tnsnames.ora service name, or a sql connect url string of the form:
8
+ #
9
+ # //host:[port][/service name]
10
+ #
11
+ # By default prefetch_rows (OCI_ATTR_PREFETCH_ROWS) is set to 100. And
12
+ # until true bind variables are supported, cursor_sharing is set by default
13
+ # to 'similar'. Both can be changed in the configation below; the defaults
14
+ # are equivalent to specifying:
15
+ #
16
+ # prefetch_rows: 100
17
+ # cursor_sharing: similar
18
+ #
19
+
20
+ development:
21
+ adapter: oracle
22
+ database: <%= app_name %>_development
23
+ username: <%= app_name %>
24
+ password:
25
+
26
+ # Warning: The database defined as 'test' will be erased and
27
+ # re-generated from your development database when you run 'rake'.
28
+ # Do not set this db to the same as development or production.
29
+ test:
30
+ adapter: oracle
31
+ database: <%= app_name %>_test
32
+ username: <%= app_name %>
33
+ password:
34
+
35
+ production:
36
+ adapter: oracle
37
+ database: <%= app_name %>_production
38
+ username: <%= app_name %>
39
+ password:
@@ -0,0 +1,48 @@
1
+ # PostgreSQL. Versions 7.4 and 8.x are supported.
2
+ #
3
+ # Install the ruby-postgres driver:
4
+ # gem install ruby-postgres
5
+ # On Mac OS X:
6
+ # gem install ruby-postgres -- --include=/usr/local/pgsql
7
+ # On Windows:
8
+ # gem install ruby-postgres
9
+ # Choose the win32 build.
10
+ # Install PostgreSQL and put its /bin directory on your path.
11
+ development:
12
+ adapter: postgresql
13
+ encoding: unicode
14
+ database: <%= app_name %>_development
15
+ username: <%= app_name %>
16
+ password:
17
+
18
+ # Connect on a TCP socket. Omitted by default since the client uses a
19
+ # domain socket that doesn't need configuration. Windows does not have
20
+ # domain sockets, so uncomment these lines.
21
+ #host: localhost
22
+ #port: 5432
23
+
24
+ # Schema search path. The server defaults to $user,public
25
+ #schema_search_path: myapp,sharedapp,public
26
+
27
+ # Minimum log levels, in increasing order:
28
+ # debug5, debug4, debug3, debug2, debug1,
29
+ # log, notice, warning, error, fatal, and panic
30
+ # The server defaults to notice.
31
+ #min_messages: warning
32
+
33
+ # Warning: The database defined as 'test' will be erased and
34
+ # re-generated from your development database when you run 'rake'.
35
+ # Do not set this db to the same as development or production.
36
+ test:
37
+ adapter: postgresql
38
+ encoding: unicode
39
+ database: <%= app_name %>_test
40
+ username: <%= app_name %>
41
+ password:
42
+
43
+ production:
44
+ adapter: postgresql
45
+ encoding: unicode
46
+ database: <%= app_name %>_production
47
+ username: <%= app_name %>
48
+ password:
@@ -0,0 +1,16 @@
1
+ # SQLite version 2.x
2
+ # gem install sqlite-ruby
3
+ development:
4
+ adapter: sqlite
5
+ database: db/development.sqlite2
6
+
7
+ # Warning: The database defined as 'test' will be erased and
8
+ # re-generated from your development database when you run 'rake'.
9
+ # Do not set this db to the same as development or production.
10
+ test:
11
+ adapter: sqlite
12
+ database: db/test.sqlite2
13
+
14
+ production:
15
+ adapter: sqlite
16
+ database: db/production.sqlite2
@@ -0,0 +1,19 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
+ development:
4
+ adapter: sqlite3
5
+ database: db/development.sqlite3
6
+ timeout: 5000
7
+
8
+ # Warning: The database defined as 'test' will be erased and
9
+ # re-generated from your development database when you run 'rake'.
10
+ # Do not set this db to the same as development or production.
11
+ test:
12
+ adapter: sqlite3
13
+ database: db/test.sqlite3
14
+ timeout: 5000
15
+
16
+ production:
17
+ adapter: sqlite3
18
+ database: db/production.sqlite3
19
+ timeout: 5000
@@ -0,0 +1,11 @@
1
+ # Choose the view provider
2
+ <% if view_provider -%>
3
+ config.view_provider = :<%= view_provider %>
4
+ <% else -%>
5
+ # config.view_provider = :wx
6
+ <% end -%>
7
+
8
+ <% unless database -%>
9
+ # We don't want ActiveRecord for the ORM, remove it from the default frameworks
10
+ config.frameworks.delete :active_record
11
+ <% end -%>
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ require "#{File.dirname(__FILE__)}/../config/boot.rb"
5
+ Reactive.boot
6
+
7
+ require 'rubigen'
8
+ require 'rubigen/scripts/destroy'
9
+
10
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
11
+ RubiGen::Base.prepend_sources(Gem.loaded_specs.values.collect{|spec| RubiGen::PathFilteredSource.new(:GemPlugins, spec.full_gem_path, [:reactive, :test_unit]) })
12
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ require "#{File.dirname(__FILE__)}/../config/boot.rb"
5
+ Reactive.boot
6
+
7
+ require 'rubigen'
8
+ require 'rubigen/scripts/generate'
9
+
10
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
11
+ RubiGen::Base.prepend_sources(Gem.loaded_specs.values.collect{|spec| RubiGen::PathFilteredSource.new(:GemPlugins, spec.full_gem_path, [:reactive, :test_unit]) })
12
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "#{File.dirname(__FILE__)}/../config/boot.rb"
4
+
5
+ Reactive.run
@@ -0,0 +1 @@
1
+ @ruby <%= File.join("script", filename) %> %*
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../lib/version'
4
+ if %w(--version -v).include? ARGV.first
5
+ puts "Reactive #{Reactive::VERSION::STRING}"
6
+ exit(0)
7
+ end
8
+
9
+ require 'rubygems'
10
+ require 'rubigen'
11
+
12
+ require 'rubigen/scripts/generate'
13
+ source = RubiGen::PathSource.new(:application, File.join(File.dirname(__FILE__), "../app_generators"))
14
+ RubiGen::Base.reset_sources
15
+ RubiGen::Base.append_sources(source)
16
+ RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'reactive')
@@ -0,0 +1,107 @@
1
+ class CodeStatistics #:nodoc:
2
+
3
+ TEST_TYPES = %w(Units Functionals Unit\ tests Functional\ tests Integration\ tests)
4
+
5
+ def initialize(*pairs)
6
+ @pairs = pairs
7
+ @statistics = calculate_statistics
8
+ @total = calculate_total if pairs.length > 1
9
+ end
10
+
11
+ def to_s
12
+ print_header
13
+ @pairs.each { |pair| print_line(pair.first, @statistics[pair.first]) }
14
+ print_splitter
15
+
16
+ if @total
17
+ print_line("Total", @total)
18
+ print_splitter
19
+ end
20
+
21
+ print_code_test_stats
22
+ end
23
+
24
+ private
25
+ def calculate_statistics
26
+ @pairs.inject({}) { |stats, pair| stats[pair.first] = calculate_directory_statistics(pair.last); stats }
27
+ end
28
+
29
+ def calculate_directory_statistics(directory, pattern = /.*\.rb$/)
30
+ stats = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0 }
31
+
32
+ Dir.foreach(directory) do |file_name|
33
+ if File.stat(directory + "/" + file_name).directory? and (/^\./ !~ file_name)
34
+ newstats = calculate_directory_statistics(directory + "/" + file_name, pattern)
35
+ stats.each { |k, v| stats[k] += newstats[k] }
36
+ end
37
+
38
+ next unless file_name =~ pattern
39
+
40
+ f = File.open(directory + "/" + file_name)
41
+
42
+ while line = f.gets
43
+ stats["lines"] += 1
44
+ stats["classes"] += 1 if line =~ /class [A-Z]/
45
+ stats["methods"] += 1 if line =~ /def [a-z]/
46
+ stats["codelines"] += 1 unless line =~ /^\s*$/ || line =~ /^\s*#/
47
+ end
48
+ end
49
+
50
+ stats
51
+ end
52
+
53
+ def calculate_total
54
+ total = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0 }
55
+ @statistics.each_value { |pair| pair.each { |k, v| total[k] += v } }
56
+ total
57
+ end
58
+
59
+ def calculate_code
60
+ code_loc = 0
61
+ @statistics.each { |k, v| code_loc += v['codelines'] unless TEST_TYPES.include? k }
62
+ code_loc
63
+ end
64
+
65
+ def calculate_tests
66
+ test_loc = 0
67
+ @statistics.each { |k, v| test_loc += v['codelines'] if TEST_TYPES.include? k }
68
+ test_loc
69
+ end
70
+
71
+ def print_header
72
+ print_splitter
73
+ puts "| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |"
74
+ print_splitter
75
+ end
76
+
77
+ def print_splitter
78
+ puts "+----------------------+-------+-------+---------+---------+-----+-------+"
79
+ end
80
+
81
+ def print_line(name, statistics)
82
+ m_over_c = (statistics["methods"] / statistics["classes"]) rescue m_over_c = 0
83
+ loc_over_m = (statistics["codelines"] / statistics["methods"]) - 2 rescue loc_over_m = 0
84
+
85
+ start = if TEST_TYPES.include? name
86
+ "| #{name.ljust(20)} "
87
+ else
88
+ "| #{name.ljust(20)} "
89
+ end
90
+
91
+ puts start +
92
+ "| #{statistics["lines"].to_s.rjust(5)} " +
93
+ "| #{statistics["codelines"].to_s.rjust(5)} " +
94
+ "| #{statistics["classes"].to_s.rjust(7)} " +
95
+ "| #{statistics["methods"].to_s.rjust(7)} " +
96
+ "| #{m_over_c.to_s.rjust(3)} " +
97
+ "| #{loc_over_m.to_s.rjust(5)} |"
98
+ end
99
+
100
+ def print_code_test_stats
101
+ code = calculate_code
102
+ tests = calculate_tests
103
+
104
+ puts " Code LOC: #{code} Test LOC: #{tests} Code to Test Ratio: 1:#{sprintf("%.1f", tests.to_f/code)}"
105
+ puts ""
106
+ end
107
+ end