Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

belongs_to_ninsho method is working

  • Loading branch information...
commit 443edcb249020b862fc7885aa86fca608c644751 1 parent 8a1881d
@kurenn kurenn authored
View
17 lib/generators/active_record/ninsho_generator.rb
@@ -21,6 +21,23 @@ def generate_model
invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke
end
+ def inject_ninsho_content
+ content = <<CONTENT
+ attr_accessible :provider, :uid
+ # belongs_to_ninsho :user
+CONTENT
+
+ class_path = if namespaced?
+ class_name.to_s.split("::")
+ else
+ [class_name]
+ end
+
+ indent_depth = class_path.size - 1
+ content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
+ inject_into_class(model_path, class_path.last, content) if model_exists?
+ end
+
def migration_data
<<RUBY
## Database authentications
View
1  lib/generators/ninsho/ninsho_generator.rb
@@ -17,6 +17,7 @@ def add_ninsho_routes
ninsho_routes << %Q(, :skip => :all) unless options.routes?
route ninsho_routes
end
+
end
end
end
View
1  lib/generators/ninsho/orm_helpers.rb
@@ -1,6 +1,7 @@
module Ninsho
module Generators
module OrmHelpers
+
def model_exists?
File.exists?(File.join(destination_root, model_path))
end
View
2  lib/ninsho.rb
@@ -48,3 +48,5 @@ def self.ref(arg)
require 'ninsho/routes_drawer'
require 'ninsho/rails'
+require 'ninsho/interface'
+require 'ninsho/railtie'
View
22 lib/ninsho/interface.rb
@@ -0,0 +1,22 @@
+module Ninsho
+ module Interface
+ def self.included(base)
+ base.extend(ClassMethods)
+ end
+
+ module ClassMethods
+
+ def belongs_to_ninsho(*args)
+ options = args.extract_options!
+
+ associations = args.collect(&:to_s).collect(&:downcase)
+ association_keys = associations.collect { |association| "#{association}_id" }
+
+ #Set the belongs_to association by ActiveRecord
+ associations.each do |associated_model|
+ belongs_to associated_model.to_sym
+ end
+ end
+ end
+ end
+end
View
7 lib/ninsho/railtie.rb
@@ -0,0 +1,7 @@
+module Ninsho
+ class Railtie < Rails::Railtie
+ ActiveSupport.on_load :active_record do
+ ActiveRecord::Base.send :include, Ninsho::Interface
+ end
+ end
+end
View
1  ninsho.gemspec
@@ -22,4 +22,5 @@ Gem::Specification.new do |gem|
gem.add_dependency("orm_adapter", "~> 0.1")
gem.add_dependency "railties", "~> 3.1"
+ gem.add_dependency "activerecord", ">= 3.0"
end
Please sign in to comment.
Something went wrong with that request. Please try again.