lodestone 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/lodestone.rb +15 -9
  2. metadata +3 -3
data/lib/lodestone.rb CHANGED
@@ -9,31 +9,37 @@ require "fileutils"
9
9
 
10
10
  module Lodestone
11
11
  @ls = LodestoneParser.new
12
- @opts = Hash.new
13
12
 
14
13
  def self.__parse definition
14
+ opts = Hash.new
15
15
  @ls.parse( definition.to_s ).content.each do |thing|
16
16
  next if thing.nil?
17
- @opts.merge!( thing[0].to_sym => thing[1] )
17
+ opts.merge!( thing[0].to_sym => thing[1] )
18
18
  end
19
- @opts
19
+ opts
20
20
  end
21
21
 
22
22
  def self.apply definition
23
23
  definition_hash = self.__parse definition
24
+ path = definition_hash[:path] or return false, "No file or dir specified"
25
+ user = definition_hash[:user] or nil
26
+ group = definition_hash[:group] or nil
27
+ perms = definition_hash[:perms] or nil
24
28
 
25
- unless File.exists? definition_hash[:path]
26
- return false, "#{definition_hash[:path]} does not exist"
29
+ unless File.exists? path
30
+ return false, "#{path} does not exist"
27
31
  end
28
32
 
29
33
  begin
30
- FileUtils.chown definition_hash[:user], definition_hash[:group], definition_hash[:path]
31
- FileUtils.chmod definition_hash[:perms].to_i(8), definition_hash[:path]
34
+ FileUtils.chown user, group, path
35
+ if perms
36
+ FileUtils.chmod perms.to_i(8), path
37
+ end
32
38
  rescue Exception => e
33
- return false, "Failed to set the perms on #{definition_hash[:path]} - #{e}"
39
+ return false, "Failed to set the perms on #{path} - #{e}"
34
40
  end
35
41
 
36
- return true, "Succesfully applied definition to #{definition_hash[:path]}"
42
+ return true, "Succesfully applied definition to #{path}"
37
43
 
38
44
  end
39
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lodestone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-02 00:00:00.000000000 Z
12
+ date: 2013-02-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: treetop
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  version: '0'
62
62
  requirements: []
63
63
  rubyforge_project:
64
- rubygems_version: 1.8.21
64
+ rubygems_version: 1.8.24
65
65
  signing_key:
66
66
  specification_version: 3
67
67
  summary: A DSL to set perms on a dir in a sane way