fluidfeatures-rails 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module FluidFeatures
2
2
  module Rails
3
- VERSION = '0.6.0'
3
+ VERSION = '0.6.1'
4
4
  end
5
5
  end
@@ -5,47 +5,59 @@ module Fluidfeatures
5
5
 
6
6
  def create_initializer_file
7
7
 
8
- puts "Enter FluidFeatures credentials [press enter to skip]"
9
- print "development app_id: "
10
- dev_app_id = gets.chomp
11
-
12
- print "development secret: "
13
- dev_secret = gets.chomp
14
-
15
- print "production app_id: "
16
- prod_app_id = gets.chomp
17
-
18
- print "production secret: "
19
- prod_secret = gets.chomp
20
-
21
- print "test app_id: "
22
- test_app_id = gets.chomp
23
-
24
- print "test secret: "
25
- test_secret = gets.chomp
8
+ if File.file? CONFIG_FILE
9
+ config = YAML.load_file(CONFIG_FILE)
10
+ else
11
+ config = {
12
+ "common" => {
13
+ "base_uri" => "https://www.fluidfeatures.com/service",
14
+ "cache" => {
15
+ "enable" => false,
16
+ "dir" => "tmp/fluidfeatures",
17
+ "limit" => "10MB"
18
+ },
19
+ },
20
+ "development" => {},
21
+ "production" => {},
22
+ "test" => {},
23
+ }
24
+ end
26
25
 
27
- puts "Warning: production app_id and secret have not been set in #{CONFIG_FILE}"
28
-
29
- create_file CONFIG_FILE, """
30
- common:
31
- base_uri: https://www.fluidfeatures.com/service
32
- cache:
33
- enable: false
34
- dir: tmp/fluidfeatures
35
- limit: 2mb
36
-
37
- development:
38
- app_id: #{dev_app_id}
39
- secret: #{dev_secret}
40
-
41
- test:
42
- app_id: #{test_app_id}
43
- secret: #{test_secret}
44
-
45
- production:
46
- app_id: #{prod_app_id}
47
- secret: #{prod_secret}
48
- """
26
+ puts "Enter FluidFeatures credentials [press enter to skip]"
27
+ ["development", "production", "test"].each do |env|
28
+ config[env] ||= {}
29
+ ["app_id", "secret", "base_uri"].each do |key|
30
+ if config[env][key] and config[env][key].size > 0
31
+ default = config[env][key]
32
+ elsif config["common"][key] and config["common"][key].size
33
+ default = config["common"][key]
34
+ end
35
+ print "%s %s %s: " % [
36
+ env,
37
+ key,
38
+ default ? "[#{default}]" : ""
39
+ ]
40
+ value = gets.chomp.strip
41
+ if value and value.size > 0
42
+ config[env][key] = value
43
+ elsif default
44
+ config[env][key] = default
45
+ else
46
+ config[env][key] = nil
47
+ end
48
+ end
49
+ if config[env]["base_uri"] == config["common"]["base_uri"]
50
+ config[env].delete("base_uri")
51
+ end
52
+ end
53
+
54
+ yaml = YAML.dump(config)
55
+ # remove "---" at top
56
+ yaml.sub!(/^---\r?\n/, "")
57
+ # add extra line between environments
58
+ yaml.gsub!(/(\r?\n)(\S)/) {|m| $1 + $1 + $2 }
59
+
60
+ create_file CONFIG_FILE, yaml
49
61
  end
50
62
  end
51
63
  end
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
- require "generators/fluidfeatures/rails/install/install_generator"
2
+ require "generators/fluidfeatures/config_generator"
3
3
 
4
- describe FluidFeatures::Rails::Generators::InstallGenerator do
4
+ describe Fluidfeatures::ConfigGenerator do
5
5
  it "creates a configuration file" do
6
6
  subject.should_receive(:create_file).with("config/fluidfeatures.yml", kind_of(String))
7
7
  subject.create_initializer_file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluidfeatures-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -115,7 +115,7 @@ files:
115
115
  - lib/pre_ruby192/uri.rb
116
116
  - spec/controller_extentions_spec.rb
117
117
  - spec/controller_spec.rb
118
- - spec/generators/fluidfeatures/rails/install/install_generator_spec.rb
118
+ - spec/generators/fluidfeatures/config_generator_spec.rb
119
119
  - spec/initializer_spec.rb
120
120
  - spec/routes_spec.rb
121
121
  - spec/spec_helper.rb