Browse Source

tree tweak, data upgrade kikstart

pull/1/head
Nicolae Claudius 13 years ago
parent
commit
b29e0c0f53
  1. 9
      Gemfile
  2. 71
      Gemfile.lock
  3. 18
      app/models/domain/tree_structure.rb
  4. 20
      db/migrate/20120302172252_add_nested_interval_to_domains.rb

9
Gemfile

@ -1,6 +1,6 @@
source 'http://rubygems.org' source 'http://rubygems.org'
gem 'rails', '3.2.1' gem 'rails', '3.2.2'
# Bundle edge Rails instead: # Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git' # gem 'rails', :git => 'git://github.com/rails/rails.git'
@ -12,9 +12,8 @@ gem 'cancan', '~> 1.6.7'
gem 'squeel', '~> 0.9.3' gem 'squeel', '~> 0.9.3'
gem 'sentient_user', '~> 0.3.2' gem 'sentient_user', '~> 0.3.2'
gem 'userstamp_basic', '~> 0.1.0' gem 'userstamp_basic', '~> 0.1.0'
gem 'active_scaffold', path: '/home/clyfe/dev/active_scaffold' gem 'active_scaffold', '~> 3.2.0', path: '/home/clyfe/dev/active_scaffold'
# git: 'https://github.com/activescaffold/active_scaffold.git' # git: 'https://github.com/activescaffold/active_scaffold.git'
# '~> 3.2.0'
gem 'pjax_rails', '~> 0.1.7', git: 'https://github.com/rails/pjax_rails.git' gem 'pjax_rails', '~> 0.1.7', git: 'https://github.com/rails/pjax_rails.git'
gem 'validates_hostname', '~> 1.0.0', git: 'https://github.com/KimNorgaard/validates_hostname.git' gem 'validates_hostname', '~> 1.0.0', git: 'https://github.com/KimNorgaard/validates_hostname.git'
gem 'nilify_blanks', '~> 1.0.0' gem 'nilify_blanks', '~> 1.0.0'
@ -27,8 +26,8 @@ gem 'simple_form', '~> 2.0.0'
gem 'concerned_with', '~> 0.1.0' gem 'concerned_with', '~> 0.1.0'
gem 'navigasmic', '~> 0.5.6', git: 'https://github.com/jejacks0n/navigasmic.git' gem 'navigasmic', '~> 0.5.6', git: 'https://github.com/jejacks0n/navigasmic.git'
gem 'rails-backbone', '~> 0.7.0' gem 'rails-backbone', '~> 0.7.0'
gem 'acts_as_nested_interval', '~> 0.0.1', git: 'https://github.com/clyfe/acts_as_nested_interval.git' gem 'acts_as_nested_interval', '~> 0.0.1', path: '/home/clyfe/dev/acts_as_nested_interval'
# path: '/home/clyfe/dev/acts_as_nested_interval' # git: 'https://github.com/clyfe/acts_as_nested_interval.git'
# Gems used only for assets and not required # Gems used only for assets and not required
# in production environments by default. # in production environments by default.

71
Gemfile.lock

@ -4,13 +4,6 @@ GIT
specs: specs:
validates_hostname (1.0.0) validates_hostname (1.0.0)
GIT
remote: https://github.com/clyfe/acts_as_nested_interval.git
revision: f40731785fd3a0d11e89ce6212db751105b7b086
specs:
acts_as_nested_interval (0.0.1)
rails (~> 3.2.1)
GIT GIT
remote: https://github.com/jejacks0n/navigasmic.git remote: https://github.com/jejacks0n/navigasmic.git
revision: 6108afe7930fd4b3282cbe8942240bf4f70e2f74 revision: 6108afe7930fd4b3282cbe8942240bf4f70e2f74
@ -30,15 +23,21 @@ PATH
active_scaffold (3.2.0) active_scaffold (3.2.0)
rails (>= 3.1.3) rails (>= 3.1.3)
PATH
remote: /home/clyfe/dev/acts_as_nested_interval
specs:
acts_as_nested_interval (0.0.1)
rails (~> 3.2.1)
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
actionmailer (3.2.1) actionmailer (3.2.2)
actionpack (= 3.2.1) actionpack (= 3.2.2)
mail (~> 2.4.0) mail (~> 2.4.0)
actionpack (3.2.1) actionpack (3.2.2)
activemodel (= 3.2.1) activemodel (= 3.2.2)
activesupport (= 3.2.1) activesupport (= 3.2.2)
builder (~> 3.0.0) builder (~> 3.0.0)
erubis (~> 2.7.0) erubis (~> 2.7.0)
journey (~> 1.0.1) journey (~> 1.0.1)
@ -49,18 +48,18 @@ GEM
active-model-email-validator (1.0.2) active-model-email-validator (1.0.2)
activemodel activemodel
mail mail
activemodel (3.2.1) activemodel (3.2.2)
activesupport (= 3.2.1) activesupport (= 3.2.2)
builder (~> 3.0.0) builder (~> 3.0.0)
activerecord (3.2.1) activerecord (3.2.2)
activemodel (= 3.2.1) activemodel (= 3.2.2)
activesupport (= 3.2.1) activesupport (= 3.2.2)
arel (~> 3.0.0) arel (~> 3.0.2)
tzinfo (~> 0.3.29) tzinfo (~> 0.3.29)
activeresource (3.2.1) activeresource (3.2.2)
activemodel (= 3.2.1) activemodel (= 3.2.2)
activesupport (= 3.2.1) activesupport (= 3.2.2)
activesupport (3.2.1) activesupport (3.2.2)
i18n (~> 0.6) i18n (~> 0.6)
multi_json (~> 1.0) multi_json (~> 1.0)
arel (3.0.2) arel (3.0.2)
@ -172,29 +171,29 @@ GEM
activerecord (~> 3.0) activerecord (~> 3.0)
polyglot (0.3.3) polyglot (0.3.3)
rack (1.4.1) rack (1.4.1)
rack-cache (1.1) rack-cache (1.2)
rack (>= 0.4) rack (>= 0.4)
rack-ssl (1.3.2) rack-ssl (1.3.2)
rack rack
rack-test (0.6.1) rack-test (0.6.1)
rack (>= 1.0) rack (>= 1.0)
rails (3.2.1) rails (3.2.2)
actionmailer (= 3.2.1) actionmailer (= 3.2.2)
actionpack (= 3.2.1) actionpack (= 3.2.2)
activerecord (= 3.2.1) activerecord (= 3.2.2)
activeresource (= 3.2.1) activeresource (= 3.2.2)
activesupport (= 3.2.1) activesupport (= 3.2.2)
bundler (~> 1.0) bundler (~> 1.0)
railties (= 3.2.1) railties (= 3.2.2)
rails-backbone (0.7.0) rails-backbone (0.7.0)
coffee-script (~> 2.2.0) coffee-script (~> 2.2.0)
ejs (~> 1.0.0) ejs (~> 1.0.0)
railties (>= 3.1.0) railties (>= 3.1.0)
rails_config (0.2.5) rails_config (0.2.5)
activesupport (>= 3.0) activesupport (>= 3.0)
railties (3.2.1) railties (3.2.2)
actionpack (= 3.2.1) actionpack (= 3.2.2)
activesupport (= 3.2.1) activesupport (= 3.2.2)
rack-ssl (~> 1.3.2) rack-ssl (~> 1.3.2)
rake (>= 0.8.7) rake (>= 0.8.7)
rdoc (~> 3.4) rdoc (~> 3.4)
@ -265,7 +264,7 @@ GEM
treetop (1.4.10) treetop (1.4.10)
polyglot polyglot
polyglot (>= 0.3.1) polyglot (>= 0.3.1)
tzinfo (0.3.31) tzinfo (0.3.32)
uglifier (1.2.3) uglifier (1.2.3)
execjs (>= 0.3.0) execjs (>= 0.3.0)
multi_json (>= 1.0.2) multi_json (>= 1.0.2)
@ -281,7 +280,7 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
active-model-email-validator (~> 1.0.2) active-model-email-validator (~> 1.0.2)
active_scaffold! active_scaffold (~> 3.2.0)!
acts_as_nested_interval (~> 0.0.1)! acts_as_nested_interval (~> 0.0.1)!
bootstrap-sass-rails (~> 2.0.0.2) bootstrap-sass-rails (~> 2.0.0.2)
cancan (~> 1.6.7) cancan (~> 1.6.7)
@ -306,7 +305,7 @@ DEPENDENCIES
navigasmic (~> 0.5.6)! navigasmic (~> 0.5.6)!
nilify_blanks (~> 1.0.0) nilify_blanks (~> 1.0.0)
pjax_rails (~> 0.1.7)! pjax_rails (~> 0.1.7)!
rails (= 3.2.1) rails (= 3.2.2)
rails-backbone (~> 0.7.0) rails-backbone (~> 0.7.0)
rails_config (~> 0.2.4) rails_config (~> 0.2.4)
rb-inotify (~> 0.8.8) rb-inotify (~> 0.8.8)

18
app/models/domain/tree_structure.rb

@ -1,5 +1,13 @@
class Domain < ActiveRecord::Base class Domain < ActiveRecord::Base
attr_accessor :parent_synced attr_accessor :parent_synced
# this goes before acts_as_nested_interval call
before_save do
self.name_reversed = name.reverse if name_changed?
sync_parent
end
# this goes after sync_parent, to order callbacks correctly
acts_as_nested_interval virtual_root: true acts_as_nested_interval virtual_root: true
validate :domain_ownership validate :domain_ownership
@ -22,11 +30,6 @@ class Domain < ActiveRecord::Base
Ability::CRUD.all?{|operation| User.current.can?(operation, self)} Ability::CRUD.all?{|operation| User.current.can?(operation, self)}
end end
before_save do
self.name_reversed = name.reverse if name_changed?
sync_parent
end
after_save :sync_children after_save :sync_children
# Returns the first immediate parent, if exists (and caches the search) # Returns the first immediate parent, if exists (and caches the search)
@ -44,6 +47,11 @@ class Domain < ActiveRecord::Base
name.end_with?('.' + domain.name) name.end_with?('.' + domain.name)
end end
# Overrides acts_as_nested_interval#ancestor_of?
def ancestor_of?(domain)
domain.subdomain_of?(self)
end
protected protected
# Returns the first immediate parent, if exists (does not cache the search) # Returns the first immediate parent, if exists (does not cache the search)

20
db/migrate/20120302172252_add_nested_interval_to_domains.rb

@ -1,8 +1,3 @@
Domain.class_exec do
def ancestor_of?(node); false end
def descendants; subdomains end
end
class AddNestedIntervalToDomains < ActiveRecord::Migration class AddNestedIntervalToDomains < ActiveRecord::Migration
def change def change
add_column :domains, :parent_id, :integer add_column :domains, :parent_id, :integer
@ -19,8 +14,17 @@ class AddNestedIntervalToDomains < ActiveRecord::Migration
add_index :domains, :lft add_index :domains, :lft
add_index :domains, :rgt add_index :domains, :rgt
Domain.reset_column_information Domain.class_exec do
Domain.inheritance_column = "sti_disabled" reset_column_information
Domain.scoped.each &:save self.inheritance_column = "sti_disabled"
acts_as_nested_interval virtual_root: true
skip_callback :update, :before, :update_nested_interval
skip_callback :update, :before, :sync_children
end
Domain.scoped.each do |d|
d.create_nested_interval
d.save!
end
end end
end end

Loading…
Cancel
Save