Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

start working on adapter generators

  • Loading branch information...
commit 5887563bb39eca840aaa4c030acebaac649171a3 1 parent 41fd60e
@defunkt authored
View
61 Manifest
@@ -1,49 +1,54 @@
+./app_generators/ambition_adapter/ambition_adapter_generator.rb
+./app_generators/ambition_adapter/templates/lib/base.rb.erb
+./app_generators/ambition_adapter/templates/lib/init.rb.erb
+./app_generators/ambition_adapter/templates/lib/query.rb.erb
+./app_generators/ambition_adapter/templates/lib/select.rb.erb
+./app_generators/ambition_adapter/templates/lib/slice.rb.erb
+./app_generators/ambition_adapter/templates/lib/sort.rb.erb
+./app_generators/ambition_adapter/templates/Rakefile
+./app_generators/ambition_adapter/templates/README
+./app_generators/ambition_adapter/USAGE
+./bin/ambition_adapter
+./lib/ambition/adapters/active_ldap/base.rb
+./lib/ambition/adapters/active_ldap/query.rb
+./lib/ambition/adapters/active_ldap/select.rb
+./lib/ambition/adapters/active_ldap.rb
+./lib/ambition/adapters/active_record/base.rb
./lib/ambition/adapters/active_record/query.rb
./lib/ambition/adapters/active_record/select.rb
+./lib/ambition/adapters/active_record/slice.rb
+./lib/ambition/adapters/active_record/sort.rb
./lib/ambition/adapters/active_record/statements.rb
./lib/ambition/adapters/active_record.rb
./lib/ambition/api.rb
./lib/ambition/context.rb
+./lib/ambition/enumerable.rb
./lib/ambition/proc_to_ruby.rb
./lib/ambition/processors/base.rb
./lib/ambition/processors/ruby.rb
./lib/ambition/processors/select.rb
+./lib/ambition/processors/slice.rb
+./lib/ambition/processors/sort.rb
./lib/ambition.rb
+./Manifest
./Rakefile
./README
+./test/adapters/active_ldap/enumerable_test.rb
+./test/adapters/active_ldap/helper.rb
+./test/adapters/active_ldap/integration_test.rb
+./test/adapters/active_ldap/select_test.rb
+./test/adapters/active_record/benchmark.rb
./test/adapters/active_record/chaining_test.rb
./test/adapters/active_record/count_test.rb
+./test/adapters/active_record/enumerable_test.rb
./test/adapters/active_record/helper.rb
+./test/adapters/active_record/join_test.rb
+./test/adapters/active_record/profiler.rb
./test/adapters/active_record/ruby_test.rb
./test/adapters/active_record/select_test.rb
+./test/adapters/active_record/slice_test.rb
+./test/adapters/active_record/sort_test.rb
+./test/adapters/active_record/source_test.rb
./test/adapters/active_record/types_test.rb
./test/debug
./test/helper.rb
-./test/old/benchmark.rb
-./test/old/console
-./test/old/databases/boot.rb
-./test/old/databases/database.yml
-./test/old/databases/fixtures/admin.rb
-./test/old/databases/fixtures/companies.yml
-./test/old/databases/fixtures/company.rb
-./test/old/databases/fixtures/developer.rb
-./test/old/databases/fixtures/developers_projects.yml
-./test/old/databases/fixtures/project.rb
-./test/old/databases/fixtures/projects.yml
-./test/old/databases/fixtures/replies.yml
-./test/old/databases/fixtures/reply.rb
-./test/old/databases/fixtures/topic.rb
-./test/old/databases/fixtures/topics.yml
-./test/old/databases/fixtures/user.rb
-./test/old/databases/fixtures/users.yml
-./test/old/databases/lib/activerecord_test_connector.rb
-./test/old/databases/lib/load_fixtures.rb
-./test/old/databases/lib/schema.rb
-./test/old/enumerable_test.rb
-./test/old/helper.rb
-./test/old/join_test.rb
-./test/old/limit_test.rb
-./test/old/order_test.rb
-./test/old/profiler.rb
-./test/old/source_test.rb
-./Manifest
View
6 Rakefile
@@ -38,6 +38,7 @@ rescue LoadError
end
delete_task :test
+delete_task :install_gem
Rake::TestTask.new('test') do |t|
t.pattern = 'test/*_test.rb'
@@ -73,3 +74,8 @@ task :rcov do
`rcov -e gems test/*_test.rb`
puts 'Generated coverage reports.'
end
+
+desc 'Install as a gem'
+task :install_gem do
+ puts `rake package && gem install pkg/ambition-#{Version}.gem`
+end
View
1  app_generators/ambition_adapter/USAGE
@@ -0,0 +1 @@
+o.
View
55 app_generators/ambition_adapter/ambition_adapter_generator.rb
@@ -0,0 +1,55 @@
+class AmbitionAdapterGenerator < RubiGen::Base
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
+ default_options :author => nil
+
+ attr_reader :adapter_name, :adapter_module
+
+ def initialize(runtime_args, runtime_options = {})
+ super
+ usage if args.empty?
+ @destination_root = File.expand_path(args.shift)
+ @adapter_name = base_name
+ @adapter_module = base_name.split('_').map { |part| part[0] = part[0...1].upcase; part }.join
+ extract_options
+ end
+
+ def manifest
+ record do |m|
+ # Ensure appropriate folder(s) exists
+ m.directory ''
+ dirs = %W(
+ lib/ambition/adapters/#{adapter_name}
+ test
+ )
+ dirs.each { |path| m.directory path }
+
+ # Create stubs
+ adapter_path = "lib/ambition/adapters/#{adapter_name}"
+
+ %w( base query select slice sort ).each do |file|
+ m.template "lib/#{file}.rb.erb", "#{adapter_path}/#{file}.rb"
+ end
+
+ m.template 'lib/init.rb.erb', "#{adapter_path}.rb"
+
+ files = %w( README Rakefile )
+ files.each do |file|
+ m.file file, file
+ end
+ end
+ end
+
+protected
+ def banner
+ "Coming soon"
+ end
+
+ def add_options!(opts)
+ opts.separator ''
+ opts.separator 'Options:'
+ opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
+ opts.separator ''
+ end
+
+ def extract_options; end
+end
View
1  app_generators/ambition_adapter/templates/README
@@ -0,0 +1 @@
+Cools.
View
1  app_generators/ambition_adapter/templates/Rakefile
@@ -0,0 +1 @@
+rakie pankie
View
12 app_generators/ambition_adapter/templates/lib/base.rb.erb
@@ -0,0 +1,12 @@
+module Ambition
+ module Adapters
+ module <%= adapter_module %>
+ class Base
+ ##
+ # Extract common functionality into this class.
+ # All your classes, by default, inherit from this
+ # one -- Query and the Translators.
+ end
+ end
+ end
+end
View
21 app_generators/ambition_adapter/templates/lib/init.rb.erb
@@ -0,0 +1,21 @@
+require '<%= adapter_name %>'
+require 'ambition/adapters/<%= adapter_name %>/base'
+require 'ambition/adapters/<%= adapter_name %>/query'
+require 'ambition/adapters/<%= adapter_name %>/select'
+require 'ambition/adapters/<%= adapter_name %>/sort'
+require 'ambition/adapters/<%= adapter_name %>/slice'
+
+##
+# This is where you inject Ambition into your target.
+#
+# Use `extend' if you are injecting a class, `include' if you are
+# injecting instances of that class.
+#
+# You must also set the `ambition_adapter' class variable on your target
+# class, regardless of whether you are injecting instances or the class itself.
+#
+# You probably want something like this:
+#
+# <%= adapter_module %>::Base.extend Ambition::API
+# <%= adapter_module %>::Base.ambition_adapter = Ambition::Adapters::<%= adapter_module %>
+#
View
19 app_generators/ambition_adapter/templates/lib/query.rb.erb
@@ -0,0 +1,19 @@
+module Ambition
+ module Adapters
+ module <%= adapter_module %>
+ class Query < Base
+ def kick
+ end
+
+ def size
+ end
+
+ def to_hash
+ end
+
+ def to_s
+ end
+ end
+ end
+ end
+end
View
54 app_generators/ambition_adapter/templates/lib/select.rb.erb
@@ -0,0 +1,54 @@
+module Ambition
+ module Adapters
+ module <%= adapter_module %>
+ class Select < Base
+ def call(method)
+ end
+
+ def chained_call(*methods)
+ end
+
+ def both(left, right)
+ end
+
+ def either(left, right)
+ end
+
+ def ==(left, right)
+ end
+
+ # !=
+ def not_equal(left, right)
+ end
+
+ def =~(left, right)
+ end
+
+ # !~
+ def not_regexp(left, right)
+ end
+
+ def <(left, right)
+ end
+
+ def >(left, right)
+ end
+
+ def >=(left, right)
+ end
+
+ def <=(left, right)
+ end
+
+ def include?(left, right)
+ end
+
+ def downcase(column)
+ end
+
+ def upcase(column)
+ end
+ end
+ end
+ end
+end
View
10 app_generators/ambition_adapter/templates/lib/slice.rb.erb
@@ -0,0 +1,10 @@
+module Ambition
+ module Adapters
+ module <%= adapter_module %>
+ class Slice < Base
+ def slice(start, length)
+ end
+ end
+ end
+ end
+end
View
25 app_generators/ambition_adapter/templates/lib/sort.rb.erb
@@ -0,0 +1,25 @@
+module Ambition
+ module Adapters
+ module <%= adapter_module %>
+ class Sort < Base
+ def sort_by(method)
+ end
+
+ def reverse_sort_by(method)
+ end
+
+ def chained_sort_by(receiver, method)
+ end
+
+ def chained_reverse_sort_by(receiver, method)
+ end
+
+ def to_proc(symbol)
+ end
+
+ def rand
+ end
+ end
+ end
+ end
+end
View
13 bin/ambition_adapter
@@ -0,0 +1,13 @@
+#!/usr/bin/env ruby
+require 'rubygems'
+require 'rubigen'
+
+if %w(-v --version).include? ARGV.first
+ version = File.read('./Rakefile').scan(/Version = '(.+)'/).first.first
+ puts "#{File.basename($0)} #{version}"
+ exit(0)
+end
+
+require 'rubigen/scripts/generate'
+RubiGen::Base.use_application_sources! :ambition_adapter
+RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'ambition_adapter')
Please sign in to comment.
Something went wrong with that request. Please try again.