Class: Lolita::Configuration::Base
- Defined in:
- lib/lolita/configuration/base.rb
Overview
Lolita could be defined inside of any class that is supported by Lolita::Adapter, for now that is
-
ActiveRecord::Base
-
Mongoid::Document
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
-
#dbi ⇒ Object
readonly
Returns the value of attribute dbi.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Class Method Summary collapse
Instance Method Summary collapse
-
#generate! ⇒ Object
Call all supported instance metods to set needed variables and initialize object with them.
-
#initialize(orm_class, &block) ⇒ Base
constructor
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.
-
#list(&block) ⇒ Object
Create list variable for ::Base class and create lazy object of Lolita::LazyLoader.
-
#tab(*args, &block) ⇒ Object
Shortcut for Lolita::Configuration::Tabs <<.
-
#tabs(&block) ⇒ Object
Create collection of Lolita::Configuration::Tab, loading lazy.
Constructor Details
#initialize(orm_class, &block) ⇒ Base
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
40 41 42 43 44 |
# File 'lib/lolita/configuration/base.rb', line 40 def initialize(orm_class,&block) @klass=orm_class @dbi=Lolita::DBI::Base.new(orm_class) block_given? ? self.instance_eval(&block) : self.generate! end |
Instance Attribute Details
#dbi ⇒ Object (readonly)
Returns the value of attribute dbi.
16 17 18 |
# File 'lib/lolita/configuration/base.rb', line 16 def dbi @dbi end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
16 17 18 |
# File 'lib/lolita/configuration/base.rb', line 16 def klass @klass end |
Class Method Details
.add_generator(method) ⇒ Object
19 20 21 |
# File 'lib/lolita/configuration/base.rb', line 19 def add_generator(method) @@generators<<method.to_sym end |
Instance Method Details
#generate! ⇒ Object
Call all supported instance metods to set needed variables and initialize object with them.
67 68 69 70 71 |
# File 'lib/lolita/configuration/base.rb', line 67 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.
49 50 51 |
# File 'lib/lolita/configuration/base.rb', line 49 def list &block Lolita::LazyLoader.lazy_load(self,:@list,Lolita::Configuration::List,@dbi,&block) 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.
62 63 64 |
# File 'lib/lolita/configuration/base.rb', line 62 def tab *args, &block self.tabs<<Lolita::Configuration::Tab.add(@dbi,*args,&block) end |
#tabs(&block) ⇒ Object
Create collection of Lolita::Configuration::Tab, loading lazy. See Lolita::Configuration::Tabs for details.
55 56 57 |
# File 'lib/lolita/configuration/base.rb', line 55 def tabs &block Lolita::LazyLoader.lazy_load(self, :@tabs,Lolita::Configuration::Tabs,@dbi,&block) end |