coconut 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +4 -85
- data/changelog.md +3 -0
- data/features/multiple_file_configuration.feature +22 -0
- data/lib/coconut/dsl/application.rb +4 -0
- data/lib/coconut/dsl/asset_file.rb +13 -0
- data/lib/coconut/dsl/asset_file_list.rb +19 -0
- data/lib/coconut/dsl/asset_folder.rb +5 -6
- data/lib/coconut/version.rb +1 -1
- data/spec/coconut/dsl/application_spec.rb +7 -0
- data/spec/coconut/dsl/asset_file_list_spec.rb +21 -0
- data/spec/coconut/dsl/asset_file_spec.rb +19 -0
- data/spec/coconut/dsl/{assets_folder_spec.rb → asset_folder_spec.rb} +0 -0
- metadata +14 -6
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -119,91 +119,10 @@ what environment the application is running on. Therefore **the environment
|
|
119
119
|
will be the return value of that block**.
|
120
120
|
|
121
121
|
|
122
|
-
#### Coconut flavours (
|
123
|
-
You can structure the configuration
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
#####a) Single file
|
128
|
-
If your configuration is small this is probably the best choice. In this case
|
129
|
-
your application section will only be composed of *Assets*. You will need
|
130
|
-
nothing more. The first example of this README uses this Coconut flavour.
|
131
|
-
|
132
|
-
#####b) Folder
|
133
|
-
If you want to split your configuration in several files and put them in the
|
134
|
-
same folder you will be able to tell Coconut how to find them. Coconut will
|
135
|
-
load **every file in that folder and run them as if they were Coconut scripts**.
|
136
|
-
|
137
|
-
If the file that has the *Application* level configuration is in that folder
|
138
|
-
too it will be run and will cause an error. You have two options to avoid this:
|
139
|
-
|
140
|
-
1. Name that file `config.rb`. By convention Coconut won't run a file in an
|
141
|
-
asset folder if it is called like that.
|
142
|
-
2. Put the configuration file that has the *Application* level configuration
|
143
|
-
in a different folder. In this case the files in the given folder will only
|
144
|
-
have *Asset* configuration.
|
145
|
-
|
146
|
-
```ruby
|
147
|
-
Coconut.configure MyApp do
|
148
|
-
asset_folder 'path/to/folder'
|
149
|
-
end
|
150
|
-
```
|
151
|
-
|
152
|
-
This allows you to write your files focusing only on *Assets*, given that
|
153
|
-
when Coconut will run then within the *Application* block. So you could
|
154
|
-
have the following project structure:
|
155
|
-
|
156
|
-
.
|
157
|
-
..
|
158
|
-
/config
|
159
|
-
config.rb
|
160
|
-
database.rb
|
161
|
-
oauth.rb
|
162
|
-
s3.rb
|
163
|
-
/lib
|
164
|
-
/spec
|
165
|
-
|
166
|
-
You could have the *Application* block on the `config.rb` file like this
|
167
|
-
(assuming that you run the application from the root of the project):
|
168
|
-
|
169
|
-
```ruby
|
170
|
-
Coconut.configure MyApp do
|
171
|
-
asset_folder 'config'
|
172
|
-
end
|
173
|
-
```
|
174
|
-
|
175
|
-
And each of the asset files would only include asset configuration:
|
176
|
-
|
177
|
-
```ruby
|
178
|
-
database do
|
179
|
-
environment :development do
|
180
|
-
#...
|
181
|
-
end
|
182
|
-
|
183
|
-
environment :staging, :production do
|
184
|
-
#...
|
185
|
-
end
|
186
|
-
end
|
187
|
-
```
|
188
|
-
|
189
|
-
You would only need to require the `config/config.rb` file to access the
|
190
|
-
configuration.
|
191
|
-
|
192
|
-
#####c) List of files
|
193
|
-
|
194
|
-
*NOT DEVELOPED YET: will be available on next version (0.1.1)*
|
195
|
-
|
196
|
-
This flavour is exactly like the *folder* one with the difference that instead
|
197
|
-
of providing the path to the folder to the asset configuration files you provide
|
198
|
-
the path to every one of them:
|
199
|
-
|
200
|
-
```ruby
|
201
|
-
Coconut.configure MyApp do
|
202
|
-
asset_files 'database.rb', 'oauth.rb', 's3.rb'
|
203
|
-
end
|
204
|
-
```
|
205
|
-
|
206
|
-
Notice that the paths are relative to where the `config.rb` file is located.
|
122
|
+
#### Coconut flavours (how to structure your configuration).
|
123
|
+
You can structure the configuration in several ways with coconut. See
|
124
|
+
[coconut flavours](https://github.com/jacegu/coconut/wiki/Coconut-flavours--\(how-to-split-your-configuration\))
|
125
|
+
in the wiki.
|
207
126
|
|
208
127
|
### 2) Asset
|
209
128
|
Each of this blocks represent one of the assets of your application. Inside
|
data/changelog.md
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
Feature: Load configuration from specific asset files.
|
2
|
+
|
3
|
+
You can split your configuration into asset files, and tell Coconut to load
|
4
|
+
the configuration from them.
|
5
|
+
|
6
|
+
Scenario: Loading asset configuration from specific files.
|
7
|
+
Given I have my application config in "/tmp/coconut_config/config.rb" with content:
|
8
|
+
"""
|
9
|
+
Coconut.configure MyApp do
|
10
|
+
asset_files '/tmp/coconut_config/s3.rb'
|
11
|
+
end
|
12
|
+
"""
|
13
|
+
And I have a "s3.rb" asset file on /tmp/coconut_config with content:
|
14
|
+
"""
|
15
|
+
s3 do
|
16
|
+
env(:development) { key 'xxx' }
|
17
|
+
env(:production) { key 'yyy' }
|
18
|
+
end
|
19
|
+
"""
|
20
|
+
When I run my application on the "production" environment
|
21
|
+
And I query the configuration for "s3.key"
|
22
|
+
Then the configured value should be "yyy"
|
@@ -24,6 +24,10 @@ module Coconut
|
|
24
24
|
instance_eval AssetFolder.config_from(path, IGNORED_FILES)
|
25
25
|
end
|
26
26
|
|
27
|
+
def asset_files(*files)
|
28
|
+
instance_eval AssetFileList.config_from(*files)
|
29
|
+
end
|
30
|
+
|
27
31
|
def method_missing(asset, *args, &config)
|
28
32
|
::Kernel::raise InvalidName, __taken_error_message(asset, 'asset name') if __taken?(asset)
|
29
33
|
@assets_config[asset] = Asset.configure(@current_environment, &config)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'asset_file'
|
2
|
+
|
3
|
+
module Coconut
|
4
|
+
module Dsl
|
5
|
+
class AssetFileList
|
6
|
+
def self.config_from(*file_paths)
|
7
|
+
new(*file_paths).assets_config
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(*file_paths)
|
11
|
+
@files = file_paths.map { |file| AssetFile.new(file) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def assets_config
|
15
|
+
@files.map { |file| file.asset_config }.join("\n")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative 'asset_file_list'
|
2
|
+
|
1
3
|
module Coconut
|
2
4
|
module Dsl
|
3
5
|
class AssetFolder
|
@@ -11,7 +13,7 @@ module Coconut
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def assets_config
|
14
|
-
|
16
|
+
AssetFileList.new(*asset_files_in_folder).assets_config
|
15
17
|
end
|
16
18
|
|
17
19
|
private
|
@@ -32,13 +34,10 @@ module Coconut
|
|
32
34
|
Dir.open(@path)
|
33
35
|
end
|
34
36
|
|
35
|
-
def content(file)
|
36
|
-
File.read(file)
|
37
|
-
end
|
38
|
-
|
39
37
|
def path_to(file)
|
40
38
|
File.expand_path(File.join(@path, file))
|
41
39
|
end
|
42
40
|
end
|
43
|
-
|
41
|
+
|
42
|
+
end
|
44
43
|
end
|
data/lib/coconut/version.rb
CHANGED
@@ -21,4 +21,11 @@ describe Coconut::Dsl::Application do
|
|
21
21
|
config = described_class.configure(:current) { asset_folder path }
|
22
22
|
config.asset.property.should eq 'value'
|
23
23
|
end
|
24
|
+
|
25
|
+
it 'can load asset configuration from a list of files' do
|
26
|
+
Coconut::Dsl::AssetFileList.stub(:config_from).with('/file/path.rb').
|
27
|
+
and_return("asset { environment(:current) { property 'value' } }")
|
28
|
+
config = described_class.configure(:current) { asset_files '/file/path.rb' }
|
29
|
+
config.asset.property.should eq 'value'
|
30
|
+
end
|
24
31
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'coconut/dsl/asset_file_list'
|
2
|
+
|
3
|
+
describe Coconut::Dsl::AssetFileList do
|
4
|
+
let(:path1) { '/tmp/asset1.rb' }
|
5
|
+
let(:path2) { '/tmp/asset2.rb' }
|
6
|
+
let(:config1) { "asset1 { env(:current) { property 'value for asset1' } }" }
|
7
|
+
let(:config2) { "asset2 { env(:current) { property 'value for asset2' } }" }
|
8
|
+
|
9
|
+
before do
|
10
|
+
File.open('/tmp/asset1.rb', 'w+') { |f| f.write(config1) }
|
11
|
+
File.open('/tmp/asset2.rb', 'w+') { |f| f.write(config2) }
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
File.delete('/tmp/asset1.rb', '/tmp/asset2.rb')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'reads the content of the asset file at path' do
|
19
|
+
described_class.config_from(path1, path2).should eq "#{config1}\n#{config2}"
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'coconut/dsl/asset_file'
|
2
|
+
|
3
|
+
describe Coconut::Dsl::AssetFile do
|
4
|
+
subject { described_class.new(path) }
|
5
|
+
let(:path) { '/tmp/asset.rb' }
|
6
|
+
let(:config) { "asset { env(:current) { property 'value' } }" }
|
7
|
+
|
8
|
+
before do
|
9
|
+
File.open('/tmp/asset.rb', 'w+') { |f| f.write(config) }
|
10
|
+
end
|
11
|
+
|
12
|
+
after do
|
13
|
+
File.delete('/tmp/asset.rb')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'reads the content of the asset file at path' do
|
17
|
+
subject.asset_config.should eq config
|
18
|
+
end
|
19
|
+
end
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coconut
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
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: 2012-12-
|
12
|
+
date: 2012-12-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cucumber
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- changelog.md
|
92
92
|
- coconut.gemspec
|
93
93
|
- features/folder_configuration.feature
|
94
|
+
- features/multiple_file_configuration.feature
|
94
95
|
- features/single_file_configuration.feature
|
95
96
|
- features/step_definitions/configuration_steps.rb
|
96
97
|
- features/support/env.rb
|
@@ -98,6 +99,8 @@ files:
|
|
98
99
|
- lib/coconut/config.rb
|
99
100
|
- lib/coconut/dsl/application.rb
|
100
101
|
- lib/coconut/dsl/asset.rb
|
102
|
+
- lib/coconut/dsl/asset_file.rb
|
103
|
+
- lib/coconut/dsl/asset_file_list.rb
|
101
104
|
- lib/coconut/dsl/asset_folder.rb
|
102
105
|
- lib/coconut/dsl/blank_slate.rb
|
103
106
|
- lib/coconut/dsl/environment.rb
|
@@ -105,8 +108,10 @@ files:
|
|
105
108
|
- spec/coconut/coconut_spec.rb
|
106
109
|
- spec/coconut/config_spec.rb
|
107
110
|
- spec/coconut/dsl/application_spec.rb
|
111
|
+
- spec/coconut/dsl/asset_file_list_spec.rb
|
112
|
+
- spec/coconut/dsl/asset_file_spec.rb
|
113
|
+
- spec/coconut/dsl/asset_folder_spec.rb
|
108
114
|
- spec/coconut/dsl/asset_spec.rb
|
109
|
-
- spec/coconut/dsl/assets_folder_spec.rb
|
110
115
|
- spec/coconut/dsl/blank_slate_spec.rb
|
111
116
|
- spec/coconut/dsl/environment_spec.rb
|
112
117
|
homepage: http://github.com/jacegu/coconut
|
@@ -123,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
128
|
version: '0'
|
124
129
|
segments:
|
125
130
|
- 0
|
126
|
-
hash: -
|
131
|
+
hash: -2312631787946944813
|
127
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
133
|
none: false
|
129
134
|
requirements:
|
@@ -132,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
137
|
version: '0'
|
133
138
|
segments:
|
134
139
|
- 0
|
135
|
-
hash: -
|
140
|
+
hash: -2312631787946944813
|
136
141
|
requirements: []
|
137
142
|
rubyforge_project:
|
138
143
|
rubygems_version: 1.8.24
|
@@ -142,14 +147,17 @@ summary: Coconut is a simple DSL that allows you to easily write and query your
|
|
142
147
|
configuration with pure Ruby.
|
143
148
|
test_files:
|
144
149
|
- features/folder_configuration.feature
|
150
|
+
- features/multiple_file_configuration.feature
|
145
151
|
- features/single_file_configuration.feature
|
146
152
|
- features/step_definitions/configuration_steps.rb
|
147
153
|
- features/support/env.rb
|
148
154
|
- spec/coconut/coconut_spec.rb
|
149
155
|
- spec/coconut/config_spec.rb
|
150
156
|
- spec/coconut/dsl/application_spec.rb
|
157
|
+
- spec/coconut/dsl/asset_file_list_spec.rb
|
158
|
+
- spec/coconut/dsl/asset_file_spec.rb
|
159
|
+
- spec/coconut/dsl/asset_folder_spec.rb
|
151
160
|
- spec/coconut/dsl/asset_spec.rb
|
152
|
-
- spec/coconut/dsl/assets_folder_spec.rb
|
153
161
|
- spec/coconut/dsl/blank_slate_spec.rb
|
154
162
|
- spec/coconut/dsl/environment_spec.rb
|
155
163
|
has_rdoc:
|