Module: SproutCore

Defined in:
lib/sproutcore.rb

Constant Summary collapse

VERSION =

:stopdoc:

'1.0.0'
LIBPATH =
::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
PATH =
::File.dirname(LIBPATH) + ::File::SEPARATOR

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#logger=(value) ⇒ Object (writeonly)

Sets the attribute logger

Parameters:

  • value

    the value to set the attribute logger to.



91
92
93
# File 'lib/sproutcore.rb', line 91

def logger=(value)
  @logger = value
end

Class Method Details

.build_modeObject

Returns the current build mode. The build mode is determined based on the current environment build_mode settings. Note that for backwards compatibility reasons, :development and :debug are treated as being identical.



97
98
99
100
101
102
# File 'lib/sproutcore.rb', line 97

def self.build_mode
  ret = env.build_mode || :production
  ret = ret.to_sym unless ret.nil?
  ret = :debug if ret == :development # backwards compatibility
  ret
end

.build_mode=(new_mode) ⇒ Object



104
105
106
107
108
109
# File 'lib/sproutcore.rb', line 104

def self.build_mode=(new_mode)
  new_mode = new_mode.to_sym
  new_mode = :debug if new_mode == :development
  env.build_mode = new_mode
  self.build_mode
end

.builtin_projectObject

Returns a project instance representing the builtin library



112
113
114
# File 'lib/sproutcore.rb', line 112

def self.builtin_project
  @builtin_project ||= SC::Project.new(PATH)
end

.envObject

Global variable that can store specific environmental settings. This is where you will find the build mode among other things set by sc-build.



64
65
66
# File 'lib/sproutcore.rb', line 64

def self.env
  @env ||= HashStruct.new(:build_mode => :debug, :buildfile_names => %w(Buildfile sc-config sc-config.rb))
end

.env=(hash) ⇒ Object



67
# File 'lib/sproutcore.rb', line 67

def self.env=(hash); @env = HashStruct.new(hash); end

.libpath(*args) ⇒ Object

Returns the library path for the module. If any arguments are given, they will be joined to the end of the libray path using File.join.



36
37
38
# File 'lib/sproutcore.rb', line 36

def self.libpath( *args )
  args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
end

.loggerObject

Returns a standard logger object. You can replace this with your own logger to redirect all SproutCore log output if needed. Otherwise, a logger will bre created based on your env.log_level and env.logfile options.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/sproutcore.rb', line 73

def self.logger 
  return @logger unless @logger.nil?
  
  if env.logfile
    @logger = Logger.new env.logfile, 10, 1024000
  else
    @logger = Logger.new $stderr
    
    # if we are logging to the screen, no reason to use a std loggin fmt
    @logger.formatter = lambda do |severity, time, progname, msg|
      [severity, '~', msg.to_s, "\n"].join(' ') 
    end
  end
  
  @logger.level = (env.log_level == :debug) ? Logger::DEBUG : ((env.log_level == :info) ? Logger::INFO : Logger::WARN)
  
  return @logger
end

.path(*args) ⇒ Object

Returns the lpath for the module. If any arguments are given, they will be joined to the end of the path using File.join.



44
45
46
# File 'lib/sproutcore.rb', line 44

def self.path( *args )
  args.empty? ? PATH : ::File.join(PATH, args.flatten)
end

.projectObject

Returns the current project, if defined. This is normally only set when you start sc-server in interactive mode.



118
# File 'lib/sproutcore.rb', line 118

def self.project; @project; end

.project=(project) ⇒ Object



119
# File 'lib/sproutcore.rb', line 119

def self.project=(project); @project = project; end

.require_all_libs_relative_to(fname, dir = nil) ⇒ Object

Utility method used to rquire all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in. Optionally, a specific directory name can be passed in such that the filename does not have to be equivalent to the directory.



53
54
55
56
57
58
59
# File 'lib/sproutcore.rb', line 53

def self.require_all_libs_relative_to( fname, dir = nil )
  dir ||= ::File.basename(fname, '.*')
  search_me = ::File.expand_path(
      ::File.join(::File.dirname(fname), dir, '*.rb'))

  Dir.glob(search_me).sort.each {|rb| require rb}
end

.versionObject

Returns the version string for the library.



28
29
30
# File 'lib/sproutcore.rb', line 28

def self.version
  VERSION
end