Class: Bowdler::SimpleDsl

Inherits:
Object
  • Object
show all
Defined in:
lib/bowdler/simple_dsl.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSimpleDsl

Returns a new instance of SimpleDsl.



12
13
14
15
16
# File 'lib/bowdler/simple_dsl.rb', line 12

def initialize
  @root_path = Dir.pwd
  @assets = {}
  @bower_directory = 'vendor'
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingObject



55
56
# File 'lib/bowdler/simple_dsl.rb', line 55

def method_missing(*)
end

Instance Attribute Details

#bower_directoryObject (readonly)

Returns the value of attribute bower_directory.



10
11
12
# File 'lib/bowdler/simple_dsl.rb', line 10

def bower_directory
  @bower_directory
end

#root_pathObject (readonly)

Returns the value of attribute root_path.



10
11
12
# File 'lib/bowdler/simple_dsl.rb', line 10

def root_path
  @root_path
end

Class Method Details

.evalute(filename) ⇒ Object



6
7
8
# File 'lib/bowdler/simple_dsl.rb', line 6

def self.evalute(filename)
  new.tap { |dsl| dsl.eval_file(File.join(dsl.root_path, filename)) }
end

Instance Method Details

#asset(name, version = 'latest') ⇒ Object



22
23
24
# File 'lib/bowdler/simple_dsl.rb', line 22

def asset(name, version = 'latest')
  @assets[name] = version
end

#assets_path(path) ⇒ Object



26
27
28
# File 'lib/bowdler/simple_dsl.rb', line 26

def assets_path(path)
  @bower_directory = path
end

#delete_bower_jsonObject



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

def delete_bower_json
  File.delete(File.join(@root_path, 'bower.json'))
end

#dependencies_to_json(data) ⇒ Object



48
49
50
51
52
53
# File 'lib/bowdler/simple_dsl.rb', line 48

def dependencies_to_json(data)
  JSON.pretty_generate({
    :name => 'bundler-bower generated',
    :dependencies => data
  })
end

#eval_file(file) ⇒ Object



18
19
20
# File 'lib/bowdler/simple_dsl.rb', line 18

def eval_file(file)
  instance_eval(File.open(file, 'rb') { |f| f.read }, file.to_s)
end

#generate_dotbowerrcObject



30
31
32
33
34
# File 'lib/bowdler/simple_dsl.rb', line 30

def generate_dotbowerrc
  contents = JSON.parse(File.read(File.join(@root_path, '.bowerrc'))) rescue {}
  contents['directory'] = @bower_directory
  JSON.pretty_generate(contents)
end

#write_bower_jsonObject



40
41
42
# File 'lib/bowdler/simple_dsl.rb', line 40

def write_bower_json
  open(File.join(@root_path, 'bower.json'), 'w') {|f| f.write(dependencies_to_json(@assets))}
end

#write_dotbowerrcObject



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

def write_dotbowerrc
  open(File.join(@root_path, '.bowerrc'), 'w') {|f| f.write(generate_dotbowerrc)}
end