Class: BinderCore::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/binder_core/config.rb

Overview

This is used to configure both file and folder context objects, interchangeably

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Config

Returns a new instance of Config.



4
5
6
# File 'lib/binder_core/config.rb', line 4

def initialize(context)
  @context = context
end

Instance Method Details

#add_params(params) ⇒ Object



53
54
55
# File 'lib/binder_core/config.rb', line 53

def add_params(params)
  @context.params.merge!(params)
end

#add_parser(klass, &test) ⇒ Object



25
26
27
28
29
# File 'lib/binder_core/config.rb', line 25

def add_parser( klass, &test )
  defn = BinderCore::Definition.new(klass, test)
  @context.parsers.unshift(defn)
  defn
end

#add_rule(klass, &test) ⇒ Object



31
32
33
34
35
# File 'lib/binder_core/config.rb', line 31

def add_rule( klass, &test )
  defn = BinderCore::Definition.new(klass, test)
  @context.rules.unshift(defn)
  defn
end

#calculate_size(limit, file) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/binder_core/config.rb', line 83

def calculate_size(limit, file)
  if File.directory? file
    i = 0
    Dir.open(file).each do |f|
      i += calculate_size(limit, file + "/" + f).to_i unless f == '.' || f == '..'
      break if i > limit
    end
    return i
  else
    return File.size?(file)
  end
end

#paramsObject



57
58
59
# File 'lib/binder_core/config.rb', line 57

def params
  @context.params
end

#set_assets(assets) ⇒ Object



49
50
51
# File 'lib/binder_core/config.rb', line 49

def set_assets(assets)
  @context.assets = assets
end

#set_console(console) ⇒ Object



8
9
10
11
# File 'lib/binder_core/config.rb', line 8

def set_console(console)
  @context.console = console
  @console = console
end

#set_data(data) ⇒ Object



45
46
47
# File 'lib/binder_core/config.rb', line 45

def set_data(data)
  @context.data = data
end

#set_name(name) ⇒ Object



37
38
39
# File 'lib/binder_core/config.rb', line 37

def set_name(name)
  @context.name = name if(@context.respond_to?(:name))
end

#set_parsers(parsers) ⇒ Object



21
22
23
# File 'lib/binder_core/config.rb', line 21

def set_parsers(parsers)
  @context.parsers += parsers
end

#set_path(path) ⇒ Object



13
14
15
# File 'lib/binder_core/config.rb', line 13

def set_path(path)
  @context.file = BinderCore::FileRef.new path
end

#set_route(route) ⇒ Object



41
42
43
# File 'lib/binder_core/config.rb', line 41

def set_route(route)
  @context.route = route
end

#set_rules(rules) ⇒ Object



17
18
19
# File 'lib/binder_core/config.rb', line 17

def set_rules(rules)
  @context.rules += rules
end

#verify_contextObject



61
62
63
# File 'lib/binder_core/config.rb', line 61

def verify_context
  unless valid_file?(@context.file.path) then raise InvalidContextError, "Invalid file at path:#{@context.file.path}" end
end