Skip to content
Browse files

first version

  • Loading branch information...
1 parent 66bcabb commit 43de2f22ea1b578d9857975495e30ba0bde51b2c @siegfried committed
View
9 Gemfile
@@ -0,0 +1,9 @@
+source "http://rubygems.org"
+
+gem "parse_resource"
+gem "rails"
+
+group :test do
+ gem "rspec"
+ gem "generator_spec"
+end
View
111 Gemfile.lock
@@ -0,0 +1,111 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionmailer (3.2.2)
+ actionpack (= 3.2.2)
+ mail (~> 2.4.0)
+ actionpack (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ journey (~> 1.0.1)
+ rack (~> 1.4.0)
+ rack-cache (~> 1.1)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.1.2)
+ activemodel (3.2.2)
+ activesupport (= 3.2.2)
+ builder (~> 3.0.0)
+ activerecord (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
+ arel (~> 3.0.2)
+ tzinfo (~> 0.3.29)
+ activeresource (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
+ activesupport (3.2.2)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ arel (3.0.2)
+ builder (3.0.0)
+ diff-lcs (1.1.3)
+ erubis (2.7.0)
+ generator_spec (0.8.5)
+ rails (>= 3.0, < 4.0)
+ rspec-rails
+ hike (1.2.1)
+ i18n (0.6.0)
+ journey (1.0.3)
+ json (1.6.6)
+ mail (2.4.4)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.18)
+ multi_json (1.3.2)
+ parse_resource (1.7.1)
+ activemodel
+ activesupport
+ rest-client
+ polyglot (0.3.3)
+ rack (1.4.1)
+ rack-cache (1.2)
+ rack (>= 0.4)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.2.2)
+ actionmailer (= 3.2.2)
+ actionpack (= 3.2.2)
+ activerecord (= 3.2.2)
+ activeresource (= 3.2.2)
+ activesupport (= 3.2.2)
+ bundler (~> 1.0)
+ railties (= 3.2.2)
+ railties (3.2.2)
+ actionpack (= 3.2.2)
+ activesupport (= 3.2.2)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ rest-client (1.6.7)
+ mime-types (>= 1.16)
+ rspec (2.9.0)
+ rspec-core (~> 2.9.0)
+ rspec-expectations (~> 2.9.0)
+ rspec-mocks (~> 2.9.0)
+ rspec-core (2.9.0)
+ rspec-expectations (2.9.1)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.9.0)
+ rspec-rails (2.9.0)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec (~> 2.9.0)
+ sprockets (2.1.2)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.33)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ generator_spec
+ parse_resource
+ rails
+ rspec
View
7 LICENSE
@@ -0,0 +1,7 @@
+Copyright (c) 2012 Zhi-Qiang Lei
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
8 lib/generators/parse_resource/config/USAGE
@@ -0,0 +1,8 @@
+Description:
+ Generate a configuration of parse_resource
+
+Example:
+ rails generate parse_resource:config
+
+ This will create:
+ config/parse_resource.yml
View
13 lib/generators/parse_resource/config/config_generator.rb
@@ -0,0 +1,13 @@
+module ParseResource
+ module Generators
+ class ConfigGenerator < ::Rails::Generators::Base
+ argument :database_name, type: :string, optional: true
+
+ source_root File.expand_path('../templates', __FILE__)
+
+ def create_config_file
+ copy_file 'parse_resource.yml', File.join('config', 'parse_resource.yml')
+ end
+ end
+ end
+end
View
11 lib/generators/parse_resource/config/templates/parse_resource.yml
@@ -0,0 +1,11 @@
+development:
+ app_id: 1234567890
+ master_key: abcdefgh
+
+test:
+ app_id: 1234567890
+ master_key: abcdefgh
+
+production:
+ app_id: 1234567890
+ master_key: abcdefgh
View
8 lib/generators/parse_resource/model/USAGE
@@ -0,0 +1,8 @@
+Description:
+ Generate a model of parse_resource
+
+Example:
+ rails generate model Thing
+
+ This will create:
+ app/models/thing.rb
View
18 lib/generators/parse_resource/model/model_generator.rb
@@ -0,0 +1,18 @@
+module ParseResource
+ module Generators
+ class ModelGenerator < ::Rails::Generators::NamedBase
+
+ argument :attributes, type: :array, default: [], banner: "field field"
+
+ check_class_collision
+
+ source_root File.expand_path('../templates', __FILE__)
+
+ def create_model_file
+ template "model.rb", File.join("app", "models", "#{file_name}.rb")
+ end
+
+ hook_for :test_framework
+ end
+ end
+end
View
10 lib/generators/parse_resource/model/templates/model.rb
@@ -0,0 +1,10 @@
+<% module_namespacing do -%>
+class <%= class_name %> < ParseResource::Base
+<% attributes.reject{ |attr| attr.reference? }.each do |attribute| -%>
+ field :<%= attribute.name %>
+<% end -%>
+<% attributes.select{ |attr| attr.reference? }.each do |attribute| -%>
+ belongs_to :<%= attribute.name%>
+<% end -%>
+end
+<% end -%>
View
8 lib/parse_resource_rails.rb
@@ -0,0 +1,8 @@
+require "rubygems"
+require "bundler"
+Bundler.setup(:default)
+
+require "rails/generators"
+require "parse_resource"
+require "generators/parse_resource/config/config_generator"
+require "generators/parse_resource/model/model_generator"
View
28 spec/generators/config_generator_spec.rb
@@ -0,0 +1,28 @@
+require "spec_helper"
+
+describe ::ParseResource::Generators::ConfigGenerator do
+ include GeneratorSpec::TestCase
+
+ destination File.expand_path("../../tmp", __FILE__)
+
+ before(:all) do
+ prepare_destination
+ run_generator
+ end
+
+ it "creates a configuration" do
+ assert_file "config/parse_resource.yml", <<-EOT
+development:
+ app_id: 1234567890
+ master_key: abcdefgh
+
+test:
+ app_id: 1234567890
+ master_key: abcdefgh
+
+production:
+ app_id: 1234567890
+ master_key: abcdefgh
+ EOT
+ end
+end
View
23 spec/generators/model_generator_spec.rb
@@ -0,0 +1,23 @@
+require "spec_helper"
+
+describe ::ParseResource::Generators::ModelGenerator do
+ include GeneratorSpec::TestCase
+
+ destination File.expand_path("../../tmp", __FILE__)
+
+ arguments %w{Post title:string body:text}
+
+ before(:all) do
+ prepare_destination
+ run_generator
+ end
+
+ it "creates a model" do
+ assert_file "app/models/post.rb", <<-EOT
+class Post < ParseResource::Base
+ field :title
+ field :body
+end
+ EOT
+ end
+end
View
16 spec/spec_helper.rb
@@ -0,0 +1,16 @@
+$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
+
+require "bundler/setup"
+require "rails/all"
+require "parse_resource_rails"
+require "generator_spec/test_case"
+require "fileutils"
+
+RSpec.configure do |config|
+ config.before(:all) do
+ ::FileUtils.rm_rf ::File.join(::File.dirname(__FILE__), "tmp")
+ end
+ config.after(:each) do
+ ::FileUtils.rm_rf ::File.join(::File.dirname(__FILE__), "tmp")
+ end
+end

0 comments on commit 43de2f2

Please sign in to comment.
Something went wrong with that request. Please try again.