james-bond 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.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [maiha@wota.jp]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,35 @@
1
+ JamesBond
2
+ =========
3
+
4
+ James is a bond framework for web development that offers
5
+ MVC framework and Ruby friendly method based actions to Sinatra.
6
+
7
+ Yep, of course this is inspired by monk-glue, and implemented as a wrapper to it.
8
+
9
+
10
+ Features
11
+ ========
12
+
13
+ JamesBond is developed as the successor of MonkGlue on the following purposes.
14
+
15
+ * cool initializer by config block like Rails
16
+ * port option to the monk:start
17
+ * monk:console for irb based operation
18
+ * better reloader that reloads only modified files
19
+ * [TODO] better syntax for defining actions about namespaces and exceptions
20
+ * [TODO] supporting Ajax in default
21
+ * [TODO] supporting EDD(Error Driven Development) via Rack
22
+
23
+
24
+ Usage
25
+ =====
26
+
27
+ See a sample application that uses james-bond.
28
+
29
+ http://github.com/maiha/007
30
+
31
+
32
+ Author
33
+ ======
34
+
35
+ maiha@wota.jp
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+
4
+ GEM_NAME = "james-bond"
5
+ AUTHOR = "maiha"
6
+ EMAIL = "maiha@wota.jp"
7
+ HOMEPAGE = "http://github.com/maiha/james-bond"
8
+ SUMMARY = "James is a bond framework for web development"
9
+ GEM_VERSION = "0.0.1"
10
+
11
+ spec = Gem::Specification.new do |s|
12
+ s.rubyforge_project = 'asakusarb'
13
+ s.executables = []
14
+ s.name = GEM_NAME
15
+ s.version = GEM_VERSION
16
+ s.platform = Gem::Platform::RUBY
17
+ s.has_rdoc = true
18
+ s.extra_rdoc_files = ["README", "MIT-LICENSE"]
19
+ s.summary = SUMMARY
20
+ s.description = "James is a bond framework for web development that offers MVC framework and Ruby friendly method based actions to Sinatra. Yep, of course this is inspired by monk-glue, and implemented as a wrapper to it."
21
+ s.author = AUTHOR
22
+ s.email = EMAIL
23
+ s.homepage = HOMEPAGE
24
+ s.require_path = 'lib'
25
+ s.add_dependency('sinatra', '>= 0.9.4')
26
+ s.add_dependency('monk-glue', '>= 0.0.1')
27
+ s.add_dependency('extlib', '>= 0.9.14')
28
+ s.files = %w(MIT-LICENSE README Rakefile Thorfile) + Dir.glob("{lib,spec,gen}/**/*")
29
+ end
30
+
31
+ Rake::GemPackageTask.new(spec) do |pkg|
32
+ pkg.gem_spec = spec
33
+ end
34
+
35
+ desc "Install the gem"
36
+ task :install do
37
+ Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
38
+ end
39
+
40
+ desc "Uninstall the gem"
41
+ task :uninstall do
42
+ Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
43
+ end
44
+
45
+ desc "Create a gemspec file"
46
+ task :gemspec do
47
+ File.open("#{GEM_NAME}.gemspec", "w") do |file|
48
+ file.puts spec.to_ruby
49
+ end
50
+ end
51
+
52
+ require 'spec/rake/spectask'
53
+ desc 'Default: run spec examples'
54
+ task :default => 'spec'
@@ -0,0 +1,61 @@
1
+ class Benchmark < Thor
2
+ class Activate
3
+ Library = Struct.new(:name, :time, :error)
4
+ class Library
5
+ def activate
6
+ time = Time.now
7
+ require name
8
+ self.time = Time.now - time
9
+ rescue Exception => e
10
+ self.error = e.to_s
11
+ end
12
+ end
13
+
14
+ def initialize(*names)
15
+ # normalize
16
+ names = names.map{|i| i.sub(%r{-\d+(\.\d+)*$}, '')}
17
+ names.delete 'rubygems'
18
+ names.unshift 'rubygems'
19
+ @libs = names.map{|name| Library.new(name)}
20
+ end
21
+
22
+ def execute
23
+ activate
24
+ dump
25
+ end
26
+
27
+ private
28
+ def activate
29
+ @libs.each(&:activate)
30
+ end
31
+
32
+ def colorize(text, ansi); "#{ansi}#{text}\e[0m"; end
33
+ def green (text); colorize(text, "\e[32m"); end
34
+ def red (text); colorize(text, "\e[31m"); end
35
+ def yellow(text); colorize(text, "\e[33m"); end
36
+ def blue (text); colorize(text, "\e[34m"); end
37
+
38
+ def dump(output = $stdout)
39
+ sum = @libs.inject(0){|v,l| v+l.time.to_f}
40
+ @libs.each do |lib|
41
+ if sum == 0
42
+ per = yellow('[-----]')
43
+ elsif lib.time.to_f == 0
44
+ per = red('[-----]')
45
+ else
46
+ per = green('[%4.1f%%]' % (lib.time.to_f*100/sum))
47
+ end
48
+
49
+ error = lib.error ? red("[#{lib.error}]") : ''
50
+ time = lib.time ? green("%.7f" % lib.time.to_f) : red("%7s" % '---------')
51
+ output.puts "#{per} #{time} #{lib.name} #{error}"
52
+ end
53
+ output.puts yellow("[total] %.7f" % sum)
54
+ end
55
+ end
56
+
57
+ desc "rubygems", "Benchmark for loading gems"
58
+ def rubygems(*gems)
59
+ Activate.new(*gems).execute
60
+ end
61
+ end
@@ -0,0 +1,74 @@
1
+ class Monk < Thor
2
+ include Thor::Actions
3
+
4
+ desc "test", "Run all tests"
5
+ def test
6
+ # system("redis-server spec/redis.conf")
7
+
8
+ verify_config(:test)
9
+
10
+ $:.unshift File.join(File.dirname(__FILE__), "test")
11
+
12
+ Dir['test/**/*_test.rb'].each do |file|
13
+ load file unless file =~ /^-/
14
+ end
15
+ end
16
+
17
+ desc "stories", "Run user stories."
18
+ method_option :pdf, :type => :boolean
19
+ def stories
20
+ $:.unshift(Dir.pwd, "test")
21
+
22
+ ARGV << "-r"
23
+ ARGV << (options[:pdf] ? "stories-pdf" : "stories")
24
+ ARGV.delete("--pdf")
25
+
26
+ Dir["test/stories/*_test.rb"].each do |file|
27
+ load file
28
+ end
29
+ end
30
+
31
+ desc "start ENV", "Start Monk in the supplied environment"
32
+ method_option :port
33
+ def start(env = ENV["RACK_ENV"] || "development")
34
+ verify_config(env)
35
+ exec "env RACK_ENV=#{env} RACK_PORT=#{options[:port]} ruby init.rb"
36
+ end
37
+
38
+ desc "console ENV", "Start Monk console in the supplied environment"
39
+ def console(env = ENV["RACK_ENV"] || "development")
40
+ verify_config(env)
41
+ exec "env RACK_ENV=#{env} irb -r init -Ku"
42
+ end
43
+
44
+ desc "copy_example EXAMPLE, TARGET", "Copies an example file to its destination"
45
+ def copy_example(example, target = target_file_for(example))
46
+ File.exists?(target) ? return : say_status(:missing, target)
47
+ File.exists?(example) ? copy_file(example, target) : say_status(:missing, example)
48
+ end
49
+
50
+ # desc "start background job worker"
51
+ # def job
52
+ # exec "ruby script/daemons/background.rb > background.log"
53
+ # end
54
+
55
+ private
56
+
57
+ def self.source_root
58
+ File.dirname(__FILE__)
59
+ end
60
+
61
+ def target_file_for(example_file)
62
+ example_file.sub(".example", "")
63
+ end
64
+
65
+ def verify_config(env)
66
+ verify "config/settings.example.yml"
67
+ verify "config/redis/#{env}.example.conf"
68
+ end
69
+
70
+ def verify(example)
71
+ copy_example(example) unless File.exists?(target_file_for(example))
72
+ end
73
+
74
+ end
@@ -0,0 +1,6 @@
1
+ require "init"
2
+
3
+ Main.set :run, false
4
+ Main.set :environment, :production
5
+
6
+ run Main
File without changes
@@ -0,0 +1,25 @@
1
+ $KCODE = 'u'
2
+
3
+ require "rubygems"
4
+
5
+ begin
6
+ require "vendor/dependencies/lib/dependencies"
7
+ rescue LoadError
8
+ require "dependencies"
9
+ end
10
+
11
+ #ROOT_DIR = File.expand_path(File.dirname(__FILE__)) unless defined? ROOT_DIR
12
+
13
+ require '/git/plugins/james-bond/lib/james-bond'
14
+
15
+ James.config do
16
+ # Specify files to load, and give :reload for reloading in deveopment.
17
+ # When a directory is given, sub directory is automatically loaded.
18
+ # In default, following code is internally defined.
19
+ #
20
+ # require "lib"
21
+ # require "app", :reload
22
+ # require "config/local", :reload
23
+ end
24
+
25
+ James.run(__FILE__)
@@ -0,0 +1,48 @@
1
+ ROOT_DIR = Dir.pwd unless defined?(ROOT_DIR)
2
+
3
+ require "monk/glue"
4
+ require "pathname"
5
+ require "dsl_accessor"
6
+ require "extlib"
7
+ require "extlib/dictionary"
8
+ require "thread"
9
+ require "thor"
10
+
11
+ module James
12
+ dsl_accessor :root, Pathname(Dir.pwd)
13
+ dsl_accessor :init, root + "init.rb"
14
+ dsl_accessor :libs, proc { Dictionary.new }
15
+ dsl_accessor :shell, proc { Thor::Shell::Color.new }
16
+
17
+ def run(file)
18
+ Main.app_file = file
19
+ Reloader.reload!
20
+ Main.run! if Main.run?
21
+ end
22
+
23
+ def config(&block)
24
+ @config ||= Config.new
25
+ @config.instance_eval(&block) if block
26
+ return @config
27
+ end
28
+
29
+ def say(*args) shell.say(*args) end
30
+ def say_status(*args) shell.say_status(*args) end
31
+
32
+ extend self
33
+ end
34
+
35
+ require File.dirname(__FILE__) + "/james/config"
36
+ require File.dirname(__FILE__) + "/james/reloader"
37
+ require File.dirname(__FILE__) + "/james/bond"
38
+
39
+ class Main < James::Bond
40
+ end
41
+
42
+ James.config do
43
+ require "lib"
44
+ require "app", :reload
45
+ require "config/local", :reload
46
+
47
+ port ENV["RACK_PORT"]
48
+ end
@@ -0,0 +1,65 @@
1
+ # This file contains the bootstraping code for a Monk application.
2
+ RACK_ENV = ENV["RACK_ENV"] ||= "development" unless defined? RACK_ENV
3
+
4
+ require "sinatra/base"
5
+ require "haml"
6
+
7
+ class James::Bond < Sinatra::Base
8
+ # Helper method for file references.
9
+ #
10
+ # @param args [Array] Path components relative to ROOT_DIR.
11
+ # @example Referencing a file in config called settings.yml:
12
+ # root_path("config", "settings.yml")
13
+ def self.root_path(*args)
14
+ File.join(James.root, *args)
15
+ end
16
+
17
+ # @see James::Bond.root_path
18
+ def root_path(*args)
19
+ self.class.root_path(*args)
20
+ end
21
+
22
+ set :dump_errors, true
23
+ set :logging, true
24
+ set :methodoverride, true
25
+ set :raise_errors, Proc.new { test? }
26
+ set :root, root_path
27
+ set :run, Proc.new { $0 == app_file }
28
+ set :show_exceptions, Proc.new { development? }
29
+ set :static, true
30
+ set :views, root_path("app", "views")
31
+
32
+ use Rack::Session::Cookie
33
+
34
+ configure :development do
35
+ use James::Reloader
36
+ end
37
+
38
+ configure :development, :test do
39
+ begin
40
+ require "ruby-debug"
41
+ rescue LoadError
42
+ end
43
+ end
44
+
45
+ helpers do
46
+ # TODO Add documentation.
47
+ def haml(template, options = {}, locals = {})
48
+ options[:escape_html] = true unless options.include?(:escape_html)
49
+ super(template, options, locals)
50
+ end
51
+
52
+ # TODO Add documentation.
53
+ def partial(template, locals = {})
54
+ haml(template, {:layout => false}, locals)
55
+ end
56
+
57
+ %w[environment production? development? test?].each do |meth|
58
+ define_method(meth) { |*a| Main.send(meth, *a) }
59
+ end
60
+
61
+ end
62
+ end
63
+
64
+ require "monk/glue/logger"
65
+ #require File.dirname(__FILE__) + "/bond/settings"
@@ -0,0 +1,22 @@
1
+ require 'yaml'
2
+
3
+ class James::Bond < Sinatra::Base
4
+
5
+ # TODO Add documentation.
6
+ def self.settings(key)
7
+ @settings ||= YAML.load_file(root_path("config", "settings.yml"))[RACK_ENV.to_sym]
8
+
9
+ unless @settings.include?(key)
10
+ message = "No setting defined for #{key.inspect}."
11
+ defined?(logger) ? logger.warn(message) : $stderr.puts(message)
12
+ end
13
+
14
+ @settings[key]
15
+ end
16
+
17
+ def settings(key)
18
+ self.class.settings(key)
19
+ end
20
+
21
+ end
22
+
@@ -0,0 +1,13 @@
1
+ module James
2
+ class Config
3
+ def require(file, reload = false)
4
+ James.libs[file.to_s] = reload
5
+ end
6
+
7
+ def port(value)
8
+ port = value.to_i rescue 0
9
+ Main.port = port if port > 0
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,56 @@
1
+ require 'monk/glue/reloader'
2
+
3
+ module James
4
+ class Reloader < Monk::Glue::Reloader
5
+ def reload!
6
+ self.class.reload!
7
+ end
8
+
9
+ def files
10
+ self.class.files
11
+ end
12
+
13
+ class << self
14
+ def reload!
15
+ updated_files = []
16
+ @timestamps ||= {}
17
+ routing_changed = false
18
+
19
+ files.each do |file|
20
+ begin
21
+ now = File.mtime(file).to_i
22
+ old = @timestamps[file].to_i
23
+ routing = file =~ %r{(^|/)app/routes/}o
24
+ if routing or now > old
25
+ updated_files << file
26
+ routing_changed = true if routing and now > old
27
+ James.say_status(:updated, file) if now > old and old > 0
28
+ end
29
+ @timestamps[file] = now
30
+ rescue Exception
31
+ updated_files << file
32
+ end
33
+ end
34
+
35
+ if routing_changed
36
+ Main.reset!
37
+ end
38
+
39
+ updated_files.each do |file|
40
+ next if !routing_changed and file =~ %r{(^|/)app/routes/}o
41
+ load file
42
+ end
43
+ end
44
+
45
+ def files
46
+ array = []
47
+ James.libs.each do |dir, reload|
48
+ file = dir.sub(/(\.rb)?$/, '') + '.rb'
49
+ array << file if File.exist?(file)
50
+ array.concat(Dir.glob("#{dir}/**/*.rb").sort) if File.directory?(dir)
51
+ end
52
+ return array
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,15 @@
1
+ module Spec
2
+ module Example
3
+ module Subject
4
+ module ExampleGroupMethods
5
+ def its(*args, &block)
6
+ describe(args.first) do
7
+ define_method(:subject) { super().send(*args) }
8
+ it(&block)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,36 @@
1
+ ######################################################################
2
+ ### provide matcher
3
+ Spec::Matchers.define :provide do |expected|
4
+ match do |obj|
5
+ (obj.public_methods + obj.protected_methods + obj.private_methods).include?(expected.to_s)
6
+ end
7
+ end
8
+
9
+ module Spec
10
+ module Example
11
+ module Subject
12
+ module ExampleGroupMethods
13
+ # == Examples
14
+ #
15
+ # describe User do
16
+ # subject { User.new }
17
+ # provide :name
18
+ #
19
+ # [intead of]
20
+ #
21
+ # it "should provide #name" do
22
+ # methods = subject.public_methods + subject.protected_methods + subject.private_methods
23
+ # methods.should include("name")
24
+ # end
25
+ # end
26
+ #
27
+ def provide(name)
28
+ it "should provide ##{name}" do
29
+ subject.should provide(name)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,20 @@
1
+
2
+ require 'spec'
3
+ require 'rr'
4
+
5
+ Spec::Runner.configure do |config|
6
+ config.mock_with RR::Adapters::Rspec
7
+ end
8
+
9
+ Dir.glob(File.join(File.dirname(__FILE__), '/../lib/*.rb')).each{|lib| require lib}
10
+ require File.join(File.dirname(__FILE__), '/its_helper')
11
+ require File.join(File.dirname(__FILE__), '/provide_helper')
12
+
13
+
14
+ def path(key)
15
+ Pathname(File.join(File.dirname(__FILE__) + "/fixtures/#{key}"))
16
+ end
17
+
18
+ def data(key)
19
+ (@__fixture_data_cache__ ||= {})[key] ||= path(key).read{}
20
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: james-bond
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - maiha
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-11 00:00:00 +09:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: sinatra
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 9
30
+ - 4
31
+ version: 0.9.4
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: monk-glue
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 0
44
+ - 1
45
+ version: 0.0.1
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: extlib
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ - 9
58
+ - 14
59
+ version: 0.9.14
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ description: James is a bond framework for web development that offers MVC framework and Ruby friendly method based actions to Sinatra. Yep, of course this is inspired by monk-glue, and implemented as a wrapper to it.
63
+ email: maiha@wota.jp
64
+ executables: []
65
+
66
+ extensions: []
67
+
68
+ extra_rdoc_files:
69
+ - README
70
+ - MIT-LICENSE
71
+ files:
72
+ - MIT-LICENSE
73
+ - README
74
+ - Rakefile
75
+ - Thorfile
76
+ - lib/james-bond.rb
77
+ - lib/james/bond.rb
78
+ - lib/james/reloader.rb
79
+ - lib/james/bond/settings.rb
80
+ - lib/james/config.rb
81
+ - spec/provide_helper.rb
82
+ - spec/its_helper.rb
83
+ - spec/spec_helper.rb
84
+ - gen/templates/init.rb
85
+ - gen/templates/Thorfile
86
+ - gen/templates/config.ru
87
+ - gen/templates/dependencies
88
+ has_rdoc: true
89
+ homepage: http://github.com/maiha/james-bond
90
+ licenses: []
91
+
92
+ post_install_message:
93
+ rdoc_options: []
94
+
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ requirements: []
112
+
113
+ rubyforge_project: asakusarb
114
+ rubygems_version: 1.3.6
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: James is a bond framework for web development
118
+ test_files: []
119
+