ysets 0.1.0

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.
Files changed (8) hide show
  1. data/Gemfile +13 -0
  2. data/LICENSE.txt +20 -0
  3. data/README.rdoc +52 -0
  4. data/Rakefile +51 -0
  5. data/VERSION +1 -0
  6. data/lib/ysets.rb +43 -0
  7. data/lib/ysets/railtie.rb +10 -0
  8. metadata +118 -0
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "> 2.1.0"
10
+ gem "bundler", "> 1.0.0"
11
+ gem "jeweler", "> 1.5.1"
12
+ gem "simplecov", ">= 0"
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 cowboycoded
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,52 @@
1
+ = ysets
2
+
3
+ YAML settings for your Rails 3 app.
4
+
5
+ ===Install the gem
6
+
7
+ Add this to your Gemfile
8
+ gem "ysets"
9
+
10
+ Install with Bundler
11
+ bundle install
12
+
13
+ ===Adding the YAML file with your key/value pairs
14
+
15
+ 1. Create a YAML file inside /your_rails_app/config/ysets/ClassName.yml
16
+ 2. On your application.rb add
17
+ require "ysets/railtie"
18
+ module YourApp
19
+ class Application < Rails::Application
20
+ Ysets::Railtie.setup!
21
+ end
22
+ end
23
+
24
+ ===YAML file content
25
+ You can define key/value pairs in the YAML file and these will be available in your app. You can set the defaults and any environment specific values.
26
+ The file must contain each environment that you will use in your Rails app. Here is a sample.yml:
27
+
28
+ defaults: &defaults
29
+ api_key: asdf12345lkj
30
+ some_number: 999
31
+ erb_stuffs: <%= "erb stuff works" %>
32
+ some_array:
33
+ - element1
34
+ - element2
35
+
36
+ development:
37
+ <<: *defaults
38
+ api_key: api key for dev
39
+
40
+ test:
41
+ <<: *defaults
42
+
43
+ production:
44
+ <<: *defaults
45
+
46
+ In the above example, you can define the key/value pair using strings, numbers, erb code, or arrays. Notice that the "api_key" in the development
47
+ environment will override the "api_key" from defaults.
48
+
49
+ ===Accessing the values in your Rails app
50
+
51
+ SAMPLE.api_key # => asdf12345lkj
52
+ SAMPLE.some_array[0] # => element1
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "ysets"
16
+ gem.homepage = "http://www.rakuten.com"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{YAML Settings}
19
+ gem.description = %Q{Create settings/contants for your Rails 3 app using yml key/value pairs}
20
+ gem.email = "tuongvan.a.pham@mail.rakuten.com"
21
+ gem.authors = ["tonny"]
22
+ gem.files.exclude 'test_app/**/*'
23
+ gem.files.exclude 'test_app/**/.*'
24
+ gem.files.include 'init.rb'
25
+ gem.files.include 'lib/**/*'
26
+ gem.files.include 'lib/**/.*'
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rspec/core'
31
+ require 'rspec/core/rake_task'
32
+ RSpec::Core::RakeTask.new(:spec) do |spec|
33
+ spec.pattern = FileList['spec/**/*_spec.rb']
34
+ end
35
+
36
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
37
+ spec.pattern = 'spec/**/*_spec.rb'
38
+ spec.rcov = true
39
+ end
40
+
41
+ task :default => :spec
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "ysets #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.3
data/lib/ysets.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'yaml'
2
+ require 'erb'
3
+ YSETS_PATH = "#{File.dirname(__FILE__)}/ysets"
4
+ require "#{YSETS_PATH}/railtie.rb"
5
+
6
+ module Ysets
7
+ class UndefinedYset < StandardError; end
8
+ class << self
9
+ def setup!
10
+ find_ymls.each do |yml|
11
+ create_yset_class(yml)
12
+ end
13
+ end
14
+
15
+ def find_ymls
16
+ main_file = "#{Rails.root.to_s}/config/yset.yml"
17
+ ysets_main_file = File.exists?(main_file) ? [main_file] : []
18
+ ysets_namespaced_files = Dir.glob("#{Rails.root.to_s}/config/ysets/**/*.yml")
19
+ ysets_main_file.concat(ysets_namespaced_files)
20
+ end
21
+
22
+ def create_yset_class(yml_file)
23
+ hash = load_yml(yml_file)
24
+ klass_name = File.basename(yml_file).gsub(".yml","").camelize
25
+ klass_name = "#{klass_name}".upcase unless klass_name=="YSETS"
26
+ klass = Object.const_set(klass_name,Class.new)
27
+ hash.each do |key,value|
28
+ klass.define_singleton_method(key){ value }
29
+ end
30
+ klass.class_eval do
31
+ def self.method_missing(method_id,*args)
32
+ raise UndefinedYset, "#{method_id} is not defined in #{self.to_s}"
33
+ end
34
+ end
35
+ klass.freeze unless Rails.env.test?
36
+ end
37
+
38
+ def load_yml(yml_file)
39
+ erb = ERB.new(File.read(yml_file)).result
40
+ erb.present? ? YAML.load(erb).to_hash[Rails.env] : {}
41
+ end
42
+ end # class << self
43
+ end
@@ -0,0 +1,10 @@
1
+ require 'rails'
2
+ require 'ysets'
3
+
4
+ module Ysets
5
+ class Railtie < Rails::Railtie
6
+ def self.setup!
7
+ Ysets.setup!
8
+ end
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ysets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - tonny
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>'
20
+ - !ruby/object:Gem::Version
21
+ version: 2.1.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>'
28
+ - !ruby/object:Gem::Version
29
+ version: 2.1.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>'
36
+ - !ruby/object:Gem::Version
37
+ version: 1.0.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>'
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: jeweler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>'
52
+ - !ruby/object:Gem::Version
53
+ version: 1.5.1
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>'
60
+ - !ruby/object:Gem::Version
61
+ version: 1.5.1
62
+ - !ruby/object:Gem::Dependency
63
+ name: simplecov
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Create contants for your Rails 3 app using yml files
79
+ email: jwall149@gmail.com
80
+ executables: []
81
+ extensions: []
82
+ extra_rdoc_files:
83
+ - LICENSE.txt
84
+ - README.rdoc
85
+ files:
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.rdoc
89
+ - Rakefile
90
+ - VERSION
91
+ - lib/ysets.rb
92
+ - lib/ysets/railtie.rb
93
+ homepage: http://www.vnadc.com
94
+ licenses:
95
+ - MIT
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 1.8.23
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: YAML Settings
118
+ test_files: []