Module: Ooor::OoorBehavior::ClassMethods
- Defined in:
- lib/ooor.rb
Constant Summary collapse
- IRREGULAR_CONTEXT_POSITIONS =
{ import_data: 5, fields_view_get: 2, search: 4, name_search: 3, read_group: 5, fields_get: 1, read: 2, perm_read: 1, check_recursion: 1 }
Instance Attribute Summary collapse
-
#cache_store ⇒ Object
Returns the value of attribute cache_store.
-
#default_config ⇒ Object
Returns the value of attribute default_config.
-
#default_session ⇒ Object
Returns the value of attribute default_session.
Instance Method Summary collapse
- #cache(store = nil) ⇒ Object
- #extensions ⇒ Object
-
#format_config(config) ⇒ Object
gives a hash config from a connection string or a yaml file, injects default values.
- #irregular_context_position(method) ⇒ Object
- #logger ⇒ Object
- #logger=(logger) ⇒ Object
- #model_registry ⇒ Object
- #new(config = {}) ⇒ Object
- #session_handler ⇒ Object
- #xtend(model_name, &block) ⇒ Object
Instance Attribute Details
#cache_store ⇒ Object
Returns the value of attribute cache_store.
46 47 48 |
# File 'lib/ooor.rb', line 46 def cache_store @cache_store end |
#default_config ⇒ Object
Returns the value of attribute default_config.
46 47 48 |
# File 'lib/ooor.rb', line 46 def default_config @default_config end |
#default_session ⇒ Object
Returns the value of attribute default_session.
46 47 48 |
# File 'lib/ooor.rb', line 46 def default_session @default_session end |
Instance Method Details
#cache(store = nil) ⇒ Object
71 72 73 |
# File 'lib/ooor.rb', line 71 def cache(store=nil) @cache_store ||= ActiveSupport::Cache.lookup_store(store) end |
#extensions ⇒ Object
82 83 84 |
# File 'lib/ooor.rb', line 82 def extensions @extensions ||= {} end |
#format_config(config) ⇒ Object
gives a hash config from a connection string or a yaml file, injects default values
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/ooor.rb', line 102 def format_config(config) if config.is_a?(String) && config.end_with?('.yml') env = defined?(Rails.env) ? Rails.env : nil config = load_config_file(config, env) end if config.is_a?(String) cs = config config = HashWithIndifferentAccess.new() elsif config[:ooor_url] cs = config[:ooor_url] elsif ENV['OOOR_URL'] cs = ENV['OOOR_URL'].dup() end config.merge!(parse_connection_string(cs)) if cs defaults = HashWithIndifferentAccess.new({ url: 'http://localhost:8069', username: 'admin' }) defaults[:password] = ENV['OOOR_PASSWORD'] if ENV['OOOR_PASSWORD'] defaults[:username] = ENV['OOOR_USERNAME'] if ENV['OOOR_USERNAME'] defaults[:database] = ENV['OOOR_DATABASE'] if ENV['OOOR_DATABASE'] defaults.merge(config) end |
#irregular_context_position(method) ⇒ Object
97 98 99 |
# File 'lib/ooor.rb', line 97 def irregular_context_position(method) IRREGULAR_CONTEXT_POSITIONS.merge(default_config[:irregular_context_positions] || {})[method.to_sym] end |
#logger ⇒ Object
89 90 91 |
# File 'lib/ooor.rb', line 89 def logger @logger ||= Logger.new($stdout) end |
#logger=(logger) ⇒ Object
93 94 95 |
# File 'lib/ooor.rb', line 93 def logger=(logger) @logger = logger end |
#model_registry ⇒ Object
87 |
# File 'lib/ooor.rb', line 87 def model_registry() @model_registry ||= ModelRegistry.new; end |
#new(config = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ooor.rb', line 60 def new(config={}) defaults = HashWithIndifferentAccess.new({generate_constants: true}) formated_config = format_config(config) self.default_config = defaults.merge(formated_config) session = session_handler.retrieve_session(default_config, :noweb) if default_config[:database] && default_config[:password] && default_config[:bootstrap] != false session.global_login() end Ooor.default_session = session end |
#session_handler ⇒ Object
86 |
# File 'lib/ooor.rb', line 86 def session_handler() @session_handler ||= SessionHandler.new; end |
#xtend(model_name, &block) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/ooor.rb', line 75 def xtend(model_name, &block) @extensions ||= {} @extensions[model_name] ||= [] @extensions[model_name] << block @extensions end |