Class: Rea::Application

Inherits:
Object
  • Object
show all
Includes:
Settings
Defined in:
lib/rea/application.rb

Defined Under Namespace

Classes: Rails32Reloader

Instance Method Summary collapse

Methods included from Settings

#read_default_setting

Instance Method Details

#files_in_load_pathObject



32
33
34
35
# File 'lib/rea/application.rb', line 32

def files_in_load_path
  paths = load_paths+%W{rea models}.collect{|dir|File.expand_path("app/#{dir}", Rails.root)}
  paths.flatten.compact.uniq.collect{|path| Dir["#{path}/**/*.rb"] }.flatten
end

#load!Object



20
21
22
23
24
25
26
# File 'lib/rea/application.rb', line 20

def load!
  return if loaded?
  # Load files
  files_in_load_path.each{|file| load file }
  
  @@loaded = true
end

#loaded?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/rea/application.rb', line 16

def loaded?
  @@loaded ||= false
end

#metadataObject



37
38
39
# File 'lib/rea/application.rb', line 37

def 
  @metadata ||= ActiveSupport::HashWithIndifferentAccess.new
end

#prepare!Object



10
11
12
13
14
# File 'lib/rea/application.rb', line 10

def prepare!
  remove_active_admin_load_paths_from_rails_autoload_and_eager_load
  attach_reloader
  load!
end

#set_metadataObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rea/application.rb', line 41

def 
  groupings = ::Rea.['grouping_class_names'] || []
  members = ::Rea.['member_class_names'] || []
  puts "[Rea]setting metadata...Groups: %s, Members: %s" % [groupings.inspect, members.inspect]
  groupings.each do |name|
	begin
	  name.constantize.grouping_options[:group_class_name].constantize.
 find_or_create_by_name_and_type_name! name.underscore, name
	rescue Exception=>e
	  puts e
	end
  end

  members.each do |name|
	begin
	  klass = name.constantize
	  klass.members.each_pair do |key, value|
 classification_object = ::Rea::Classification.find_or_create_by_name_and_type_name! key.to_s.underscore, name
 if (categories = value[:categories])
   categories.each do |category_name|
		classification_object.categories.find_or_create_by_name category_name, :group_ids=>[klass.default_group.id]
   end
 end
	  end
	rescue Exception=>e
	  puts e
	end
  end

end

#setup!Object



7
8
# File 'lib/rea/application.rb', line 7

def setup!
end

#unload!Object



28
29
30
# File 'lib/rea/application.rb', line 28

def unload!
  @@loaded = false
end