Class: PageBuilder
- Inherits:
-
Object
- Object
- PageBuilder
- Defined in:
- app/models/page_builder.rb
Overview
Instance Attribute Summary collapse
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(user, locale: nil, parent: nil) ⇒ PageBuilder
constructor
A new instance of PageBuilder.
- #page(name, options = {}, &block) ⇒ Object
- #run(&block) ⇒ Object
Constructor Details
#initialize(user, locale: nil, parent: nil) ⇒ PageBuilder
Returns a new instance of PageBuilder.
25 26 27 28 29 |
# File 'app/models/page_builder.rb', line 25 def initialize(user, locale: nil, parent: nil) @user = user @locale = locale || I18n.default_locale @parent = parent end |
Instance Attribute Details
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
16 17 18 |
# File 'app/models/page_builder.rb', line 16 def locale @locale end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
16 17 18 |
# File 'app/models/page_builder.rb', line 16 def parent @parent end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
16 17 18 |
# File 'app/models/page_builder.rb', line 16 def user @user end |
Class Method Details
.build(user, locale: nil, parent: nil, &block) ⇒ Object
19 20 21 22 |
# File 'app/models/page_builder.rb', line 19 def build(user, locale: nil, parent: nil, &block) new(user, locale: locale, parent: parent) .run(&block) end |
Instance Method Details
#page(name, options = {}, &block) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/page_builder.rb', line 31 def page(name, = {}, &block) page = Page.create( { name: name }.merge().merge() ) if block_given? self.class .new(user, locale: locale, parent: page) .run(&block) end page end |
#run(&block) ⇒ Object
43 44 45 |
# File 'app/models/page_builder.rb', line 43 def run(&block) instance_eval(&block) end |