mattock 0.2.9 → 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,80 @@
1
+ require 'valise'
2
+
3
+ module Mattock
4
+ #Configuration for the set of Tasklibs - useful for when there are settings
5
+ #that shouldn't be part of the Rakefile, or are specific to a particular
6
+ #environment rather than a set of tasks - e.g. specific to each developer's
7
+ #laptop or the server.
8
+ #
9
+ #@example How to Use:
10
+ # module CoolTasks
11
+ # def config
12
+ # @config ||= Mattock::ConfigurationStore.new("cool_tasks")
13
+ # end
14
+ #
15
+ # def preferences
16
+ # config.loaded["preferences.yaml"]
17
+ # end
18
+ #
19
+ # class AwesomeLib < Mattock::Tasklib
20
+ # setting :level, CoolTasks.preferences[:level]
21
+ # end
22
+ # end
23
+ #
24
+ #@example In Rakefile
25
+ # CoolTasks.config.register_search_path(__FILE__)
26
+ #
27
+ #Having done that, any preferences.yaml file in any of several directories
28
+ #will get merged into a single hash and be available as CoolTasks.preferences
29
+ #
30
+ #The search path will look like:
31
+ #
32
+ # * /etc/mattock
33
+ # * /etc/cool_tasks
34
+ # * /usr/share/mattock
35
+ # * /usr/share/cool_tasks
36
+ # * ~/.mattock
37
+ # * ~/.cool_tasks
38
+ # * <Rakefile_dir>/.cool_tasks
39
+ #
40
+ # Each file found will be merged into the running hash, so preferences.yaml
41
+ # in the project dir will be able to override everything.
42
+ #
43
+ #Last bonus: any file can be added into that search path, and the 'closest'
44
+ #one will be found and returned by config.loaded[filename]
45
+ class ConfigurationStore
46
+ #@param [String] app_name The path component to represent this gem -
47
+ # consider downcasing your root module
48
+ #@param [String] library_default_dir If present, a directory containing
49
+ # default files that come in the gem
50
+ def initialize(app_name, library_default_dir = nil)
51
+ @app_name = app_name
52
+ @valise = Valise::Set.define do
53
+ rw "~/.#{@app_name}"
54
+ rw "~/.mattock"
55
+ rw "/usr/share/#{@app_name}"
56
+ rw "/usr/share/mattock"
57
+ rw "/etc/#{@app_name}"
58
+ rw "/etc/mattock"
59
+ ro library_default_dir unless library_default_dir.nil?
60
+ ro from_here("default_configuration")
61
+
62
+ handle "preferences.yaml", :yaml, :hash_merge
63
+ end
64
+
65
+ @loaded ||= Hash.new{|h,k| h[k] = @valise.find(k).contents}
66
+ end
67
+
68
+ attr_reader :loaded, :valise
69
+
70
+ def register_search_path(from_file)
71
+ directory = File::expand_path("../.#{@app_name}", from_file)
72
+ @valise.prepend_search_root(Valise::SearchRoot.new(directory))
73
+ loaded.clear
74
+ end
75
+
76
+ def user_preferences
77
+ loaded["preferences.yaml"]
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,24 @@
1
+ require 'mattock/configuration-store'
2
+ require 'file-sandbox'
3
+
4
+ describe Mattock::ConfigurationStore do
5
+ include FileSandbox
6
+ let :store do
7
+ described_class.new("test", "default_configs").tap do |store|
8
+ store.register_search_path('./Rakefile')
9
+ end
10
+ end
11
+
12
+ before :each do
13
+ sandbox["default_configs/preferences.yaml"].contents = YAML::dump({"defaults" => "a", "local" => "b"})
14
+ sandbox[".test/preferences.yaml"].contents = YAML::dump({"local" => "c"})
15
+ end
16
+
17
+ it "should make default configs available" do
18
+ store.user_preferences["defaults"].should == "a"
19
+ end
20
+
21
+ it "should make local configs available" do
22
+ store.user_preferences["local"].should == "c"
23
+ end
24
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mattock
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.9
5
+ version: 0.2.10
6
6
  platform: ruby
7
7
  authors:
8
8
  - Judson Lester
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-03-07 00:00:00 Z
13
+ date: 2012-03-08 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: corundum
@@ -28,11 +28,9 @@ dependencies:
28
28
  requirement: &id002 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
- - - ">"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- segments:
34
- - 0
35
- version: "0"
33
+ version: "0.6"
36
34
  type: :runtime
37
35
  prerelease: false
38
36
  version_requirements: *id002
@@ -77,6 +75,7 @@ files:
77
75
  - lib/mattock/tasklib.rb
78
76
  - lib/mattock/task.rb
79
77
  - lib/mattock/configurable.rb
78
+ - lib/mattock/configuration-store.rb
80
79
  - lib/mattock/cascading-definition.rb
81
80
  - lib/mattock.rb
82
81
  - doc/README
@@ -85,6 +84,7 @@ files:
85
84
  - spec/command-task.rb
86
85
  - spec/tasklib.rb
87
86
  - spec/configurable.rb
87
+ - spec/configuration-store.rb
88
88
  - spec/yard-extensions.rb
89
89
  - spec/template-host.rb
90
90
  - spec_help/spec_helper.rb
@@ -98,7 +98,7 @@ rdoc_options:
98
98
  - --main
99
99
  - doc/README
100
100
  - --title
101
- - mattock-0.2.9 RDoc
101
+ - mattock-0.2.10 RDoc
102
102
  require_paths:
103
103
  - lib/
104
104
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -106,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - ">="
108
108
  - !ruby/object:Gem::Version
109
- hash: 927991119
109
+ hash: -164997549
110
110
  segments:
111
111
  - 0
112
112
  version: "0"