Module: Kangaroo::Util::Loader::RootNamespace

Defined in:
lib/kangaroo/util/loader/root_namespace.rb

Instance Method Summary collapse

Instance Method Details

#load_model(model_name) ⇒ Object



28
29
30
31
# File 'lib/kangaroo/util/loader/root_namespace.rb', line 28

def load_model model_name
  model_name = ruby_to_oo model_name
  Loader.new([model_name], reflection_model.database, name).load!.first
end

#model_exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
# File 'lib/kangaroo/util/loader/root_namespace.rb', line 17

def model_exists? name
  name = ruby_to_oo name
  reflection_model.where(:model => name).exists?
end

#models_in?(name) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/kangaroo/util/loader/root_namespace.rb', line 22

def models_in? name
  name = ruby_to_oo name
  
  reflection_model.where("model like #{name}.%").exists?
end

#oo_to_ruby(oo_name) ⇒ Object



5
6
7
# File 'lib/kangaroo/util/loader/root_namespace.rb', line 5

def oo_to_ruby oo_name
  name + "::" + oo_name.gsub('.','/').camelize
end

#reflection_modelObject



13
14
15
# File 'lib/kangaroo/util/loader/root_namespace.rb', line 13

def reflection_model
  const_get('Ir').const_get('Model')
end

#ruby_to_oo(ruby_name) ⇒ Object



9
10
11
# File 'lib/kangaroo/util/loader/root_namespace.rb', line 9

def ruby_to_oo ruby_name
   ruby_name.sub(name + "::",'').underscore.gsub '/', '.'
end