lib/lotus/configuration.rb in lotusrb-0.2.1 vs lib/lotus/configuration.rb in lotusrb-0.3.0

- old
+ new

@@ -5,10 +5,12 @@ require 'lotus/config/assets' require 'lotus/config/routes' require 'lotus/config/mapping' require 'lotus/config/sessions' require 'lotus/config/configure' +require 'lotus/config/security' +require 'lotus/config/cookies' module Lotus # Configuration for a Lotus application # # @since 0.1.0 @@ -33,11 +35,10 @@ # Set a block yield when the configuration will be loaded or # set a path for the specific environment. # # @param environment [Symbol,nil] the configuration environment name - # @param environment [String,nil] the configuration path of a specific environment # @param blk [Proc] the configuration block # # @return [self] # # @since 0.1.0 @@ -67,10 +68,48 @@ evaluate_configurations! self end + # Returns the security policy + # + # @return [Lotus::Config::Security] + # + # @since 0.3.0 + # + # @see Lotus::Config::Security + # + # @example Getting values + # require 'lotus' + # + # module Bookshelf + # class Application < Lotus::Application + # configure do + # security.x_frame_options "ALLOW ALL" + # security.content_security_policy "script-src 'self' https://apis.example.com" + # end + # end + # end + # + # Bookshelf::Application.configuration.security.x_frame_options # => "ALLOW ALL" + # Bookshelf::Application.configuration.security.content_security_policy # => "script-src 'self' https://apis.example.com" + # + # @example Setting values + # require 'lotus' + # + # module Bookshelf + # class Application < Lotus::Application + # configure do + # security.x_frame_options "ALLOW ALL" + # security.content_security_policy "script-src 'self' https://apis.example.com" + # end + # end + # end + def security + @security ||= Config::Security.new + end + # The root of the application # # By default it returns the current directory, for this reason, **all the # commands must be executed from the top level directory of the project**. # @@ -424,42 +463,43 @@ # # This is part of a DSL, for this reason when this method is called with # an argument, it will set the corresponding instance variable. When # called without, it will return the already set value, or the default. # - # @overload cookies(value) - # Sets the given value. + # @overload cookies(value, options) + # Sets the given value with their options. # @param value [TrueClass, FalseClass] + # @param options [Hash] # # @overload cookies # Gets the value. - # @return [TrueClass, FalseClass] + # @return [Lotus::Config::Cookies] # # @example Getting the value # require 'lotus' # # module Bookshelf # class Application < Lotus::Application # end # end # # Bookshelf::Application.configuration.cookies - # # => false + # # => #<Lotus::Config::Cookies:0x0000000329f880 @enabled=false, @default_options={:httponly=>true}> # # @example Setting the value # require 'lotus' # # module Bookshelf # class Application < Lotus::Application # configure do - # cookies true + # cookies true, { domain: 'lotusrb.org' } # end # end # end # # Bookshelf::Application.configuration.cookies - # # => true + # # => #<Lotus::Config::Cookies:0x0000000329f880 @enabled=true, @default_options={:domain=>'lotusrb.org', :httponly=>true}> # # @example Setting a new value after one is set. # require 'lotus' # # module Bookshelf @@ -470,17 +510,17 @@ # end # end # end # # Bookshelf::Application.configuration.cookies - # # => true + # # => #<Lotus::Config::Cookies:0x0000000329f880 @enabled=true, @default_options={:httponly=>true}> # - def cookies(value = nil) + def cookies(value = nil, options = {}) if value.nil? - @cookies || false + @cookies ||= Config::Cookies.new else - @cookies = value + @cookies = Config::Cookies.new(value, options) end end # Configure sessions # Enable sessions (disabled by default). @@ -1132,18 +1172,19 @@ # # Lotus supports multiple architectures (aka application structures), this # setting helps to understand the namespace where to find applications' # controllers and actions. # - # By default this equals to `"Controllers::%{controller}::%{action}"` + # By default this equals to <tt>"Controllers::%{controller}::%{action}"</tt> # That means controllers must be structured like this: - # `Bookshelf::Controllers::Dashboard::Index`, where `Bookshelf` is the - # application module, `Controllers` is the first value specified in the - # pattern, `Dashboard` the controller and `Index` the action. + # <tt>Bookshelf::Controllers::Dashboard::Index</tt>, where <tt>Bookshelf</tt> + # is the application module, <tt>Controllers</tt> is the first value + # specified in the pattern, <tt>Dashboard</tt> the controller and + # <tt>Index</tt> the action. # - # This pattern MUST always contain `"%{controller}"` and `%{action}`. - # This pattern SHOULD be used accordingly to `#view_pattern` value. + # This pattern MUST always contain <tt>"%{controller}"</tt> and <tt>%{action}</tt>. + # This pattern SHOULD be used accordingly to <tt>#view_pattern</tt> value. # # This is part of a DSL, for this reason when this method is called with # an argument, it will set the corresponding instance variable. When # called without, it will return the already set value, or the default. # @@ -1265,18 +1306,18 @@ # # Lotus supports multiple architectures (aka application structures), this # setting helps to understand the namespace where to find applications' # views:. # - # By default this equals to `"Views::%{controller}::%{action}"` + # By default this equals to <tt>"Views::%{controller}::%{action}"</tt> # That means views must be structured like this: - # `Bookshelf::Views::Dashboard::Index`, where `Bookshelf` is the - # application module, `Views` is the first value specified in the - # pattern, `Dashboard` a module corresponding to the controller name - # and `Index` the view, corresponding to the action name. + # <tt>Bookshelf::Views::Dashboard::Index</tt>, where <tt>Bookshelf</tt> is + # the application module, <tt>Views</tt> is the first value specified in the + # pattern, <tt>Dashboard</tt> a module corresponding to the controller name + # and <tt>Index</tt> the view, corresponding to the action name. # - # This pattern MUST always contain `"%{controller}"` and `%{action}`. - # This pattern SHOULD be used accordingly to `#controller_pattern` value. + # This pattern MUST always contain <tt>"%{controller}"</tt> and <tt>%{action}</tt>. + # This pattern SHOULD be used accordingly to <tt>#controller_pattern</tt> value. # # This is part of a DSL, for this reason when this method is called with # an argument, it will set the corresponding instance variable. When # called without, it will return the already set value, or the default. #