Class: Lolita::Configuration::Core

Inherits:
Object
  • Object
show all
Defined in:
lib/lolita/configuration/core.rb

Overview

This is class of lolita instance. Main block can hold these methods: list - List definition, see Lolitia::Configuration::List tab - Tab definition, see Lolita::Configuration::Tab tabs - Tabs definition, see Lolita::Configuration::Tabs

Constant Summary collapse

@@generators =
[:tabs,:list]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(orm_class, &block) ⇒ Core

When configuration is defined in class than you don’t need to worry about creating new object, because Lolita itself create it for that class. New object is created like when you define it in class, but parent_class must be given.

Example

class Person < ActiveRecord::Base
   include Lolita::Configuration
   lolita
end
Person.lolita.klass #=> Person
# Init Lolita by youself

class Person < ActiveRecord::Base
  include Lolita::Configuration
end
Person.lolita=Lolita::Configuration::Base.new(Person)
Person.lolita.klass #=> Person


30
31
32
33
34
35
# File 'lib/lolita/configuration/core.rb', line 30

def initialize(orm_class,&block)
  @klass = orm_class
  @dbp = Lolita::DBI::Base.create(orm_class)
  @dbi = @dbp
  block_given? ? self.instance_eval(&block) : self.generate!
end

Instance Attribute Details

#dbiObject (readonly)

Returns the value of attribute dbi.



10
11
12
# File 'lib/lolita/configuration/core.rb', line 10

def dbi
  @dbi
end

#klassObject (readonly)

Returns the value of attribute klass.



10
11
12
# File 'lib/lolita/configuration/core.rb', line 10

def klass
  @klass
end

Instance Method Details

#generate!Object

Call all supported instance metods to set needed variables and initialize object with them.



62
63
64
65
66
# File 'lib/lolita/configuration/core.rb', line 62

def generate!
  generators.each{|generator|
    self.send(generator)
  }
end

#list(&block) ⇒ Object

Create list variable for ::Base class and create lazy object of Lolita::LazyLoader. See Lolita::Configuration::List for more information.



40
41
42
# File 'lib/lolita/configuration/core.rb', line 40

def list &block
  Lolita::LazyLoader.lazy_load(self,:@list,Lolita::Configuration::List,@dbp,&block)
end

#list=(new_list) ⇒ Object



44
45
46
# File 'lib/lolita/configuration/core.rb', line 44

def list=(new_list)
  @list = new_list if new_list.is_a?(Lolita::Configuration::List)
end

#tab(*args, &block) ⇒ Object

Shortcut for Lolita::Configuration::Tabs <<. Tabs should not be defined in lolita block to create onew or more Lolita::Configuration::Tab See Lolita::Configuration::Tab for details of defination.



57
58
59
# File 'lib/lolita/configuration/core.rb', line 57

def tab *args, &block
  self.tabs << Lolita::Configuration::Factory::Tab.add(@dbp,*args,&block)
end

#tabs(&block) ⇒ Object

Create collection of Lolita::Configuration::Tab, loading lazy. See Lolita::Configuration::Tabs for details.



50
51
52
# File 'lib/lolita/configuration/core.rb', line 50

def tabs &block
  Lolita::LazyLoader.lazy_load(self, :@tabs,Lolita::Configuration::Tabs,@dbp,&block)
end