Class: Raka
- Inherits:
-
Object
- Object
- Raka
- Defined in:
- lib/raka.rb
Overview
initialize raka
Constant Summary collapse
- Pattern =
Pattern
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #create_logger(level) ⇒ Object
- #define_token_creator(ext, ext_alias = nil) ⇒ Object
-
#initialize(env, options) ⇒ Raka
constructor
A new instance of Raka.
- #scope(*names, &block) ⇒ Object
Constructor Details
#initialize(env, options) ⇒ Raka
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/raka.rb', line 40 def initialize(env, ) @env = env defaults = { output_types: [:csv], input_types: [], type_aliases: {}, scopes: [], lang: ['lang/shell'], user_lang: [] } = = OpenStruct.new(defaults.merge()) create_logger .log_level || (ENV['LOG_LEVEL'] || Logger::INFO).to_i .input_types |= .output_types # any output can be used as intermediate # specify root of scopes in options, scopes will append to each root @scopes = .scopes.empty? ? [] : [.scopes] .lang.each { |path| load File::join(File::dirname(__FILE__), "#{path}/impl.rb") } .user_lang.each { |path| load path.to_s + '.rb' } # These are where the dsl starts .output_types.each do |ext| define_token_creator(ext, .type_aliases[ext]) end end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
12 13 14 |
# File 'lib/raka.rb', line 12 def logger @logger end |
Instance Method Details
#create_logger(level) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/raka.rb', line 14 def create_logger(level) @env.define_singleton_method :logger do logger = Logger.new(STDOUT) logger.level = level logger end end |
#define_token_creator(ext, ext_alias = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/raka.rb', line 22 def define_token_creator(ext, ext_alias = nil) # closures env = @env = scopes = @scopes @env.define_singleton_method(ext_alias || ext) do |*args| # Here the compiler are bound with @options so that when we change @options # using methods like scope in Rakefile, the subsequent rules defined will honor # the new settings # clone to fix the scopes when defining rule inline_scope_pattern = !args.empty? ? args[0] : nil Token.new( DSLCompiler.new(env, ), Context.new(ext, scopes.clone), [], inline_scope_pattern ) end end |
#scope(*names, &block) ⇒ Object
65 66 67 68 69 |
# File 'lib/raka.rb', line 65 def scope(*names, &block) @scopes.push(names) block.call @scopes.pop end |