Skip to content

Commit

Permalink
Fix class_reference bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmoud Said committed Oct 13, 2014
1 parent 4b26c8c commit 0f18939
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 17 deletions.
2 changes: 1 addition & 1 deletion citier.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |s|
s.name = %q{citier}
s.version = "0.1.15"
s.version = "0.1.16"

s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Peter Hamilton, Originally from Laurent Buffat, Pierre-Emmanuel Jouve"]
Expand Down
4 changes: 2 additions & 2 deletions lib/citier/class_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def acts_as_citier(options = {})

# The the Writable. References the write-able table for the class because
# save operations etc can't take place on the views
self.const_set("Writable", create_class_writable(self))
self.const_set("Writable", create_class_writable(self)) unless self.const_defined?(:Writable)

after_initialize do
if self.new_record?
Expand All @@ -43,7 +43,7 @@ def acts_as_citier(options = {})
# Add the functions required for children only
send :include, Citier::ChildInstanceMethods
else
# Root class
# Root class

citier_debug("Root Class")

Expand Down
13 changes: 2 additions & 11 deletions lib/citier/core_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,10 @@ def is_new_record(state)
def self.create_class_writable(class_reference) #creation of a new class which inherits from ActiveRecord::Base
Class.new(ActiveRecord::Base) do
include Citier::InstanceMethods::ForcedWriters

t_name = class_reference.table_name

# set the name of the table associated to this class
# this class will be associated to the writable table of the class_reference class
self.table_name = t_name.gsub(/^view_/, '')

class_attribute :view_class, :writable_serialized_attributes
self.view_class = class_reference

def self.serialized_attributes
self.writable_serialized_attributes ||= class_reference.serialized_attributes.reject { |key, value| class_reference.superclass.column_names.include?(key) }
end
self.table_name = class_reference.table_name.gsub(/^view_/, '')
self.serialized_attributes ||= self.class_reference.serialized_attributes.reject { |key, value| self.class_reference.superclass.column_names.include?(key) }
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/citier/instance_methods.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Citier
module InstanceMethods
module InstanceMethods
def self.included(base)
base.send :include, ForcedWriters
ActiveRecord::Base.send :include, ForcedWriters
end

module ForcedWriters
Expand Down Expand Up @@ -32,7 +32,7 @@ class CitierUniquenessValidator < ActiveModel::EachValidator
def validate_each(object, attribute, value)
existing_record = object.class.where(attribute.to_sym => value).limit(1).first
if existing_record && existing_record.as_root != object.as_root #if prev record exist and it isn't our current obj
object.errors[attribute] << (options[:message] || "has already been taken.")
object.errors[attribute] << (options[:message] || "has already been taken.")
end
end
end
Expand Down

0 comments on commit 0f18939

Please sign in to comment.