fume-settable 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fume-settable.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Sunteya
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Fume-Settable
2
+
3
+ a simple settings plugin for read on yaml, ruby, database, etc
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fume-settable'
10
+
11
+ Or install it yourself as:
12
+
13
+ $ gem install fume-settable
14
+
15
+ ## Usage
16
+
17
+ ### 1. Define Class
18
+
19
+ #### `project.rb`
20
+ class Project < Fume::Settable::Base
21
+ yaml_provider Rails.root.join("config/application.yml") # yaml provider
22
+ ruby_provider Rails.root.join("config/application.local.rb") # ruby provider
23
+ append_providers ->(name) { "@lambda" if name == "lambda" } # lambda provider
24
+ append_providers :fetch_on_method # method provider
25
+
26
+ def fetch_on_method(name)
27
+ "@method" if name == "method"
28
+ end
29
+ end
30
+
31
+ #### `config/application.yml`
32
+ yaml: @yaml
33
+
34
+ #### `config/application.local.rb`
35
+ settings.ruby = "@ruby"
36
+
37
+ ### 2. Run
38
+
39
+ Project.settings.ruby # return "@ruby"
40
+ Project.settings.yaml # return "@yaml"
41
+ Project.settings.lambda # return "@lambda"
42
+ Project.settings.method # return "@method"
43
+ Project.settings.unknow # return nil
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/version_task'
5
+ Rake::VersionTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |gem|
3
+ gem.authors = ["Sunteya"]
4
+ gem.email = ["Sunteya@gmail.com"]
5
+ gem.description = "a simple settings plugin for read on yaml, ruby, database, etc"
6
+ gem.summary = gem.description
7
+ gem.homepage = ""
8
+
9
+ gem.files = `git ls-files`.split($\)
10
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
11
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
12
+ gem.name = "fume-settable"
13
+ gem.require_paths = ["lib"]
14
+ gem.version = File.read(File.expand_path("../VERSION", __FILE__)).chomp
15
+
16
+ gem.add_dependency "hashie"
17
+ gem.add_dependency "activesupport", ">= 3.0"
18
+
19
+ gem.add_development_dependency "rake"
20
+ gem.add_development_dependency "version"
21
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path('../../fume-settable', __FILE__)
@@ -0,0 +1,51 @@
1
+ require File.expand_path('../ruby_provider', __FILE__)
2
+ require File.expand_path('../yaml_provider', __FILE__)
3
+
4
+ module Fume
5
+ module Settable
6
+ class Base
7
+ include YamlProvider
8
+ include RubyProvider
9
+ class_attribute :providers
10
+ self.providers = []
11
+
12
+ def self.fetch(name)
13
+ (self.providers || []).each do |provider|
14
+ value = provider.call(name.to_s)
15
+ return value if value
16
+ end
17
+ nil
18
+ end
19
+
20
+ def self.settings
21
+ Proxy.new(&self.method(:fetch))
22
+ end
23
+
24
+ def self.append_providers(*providers, &block)
25
+ providers = [ providers, block ].compact.flatten
26
+
27
+ providers.each do |provider|
28
+ if provider.respond_to? :call
29
+ self.providers << provider
30
+ else
31
+ self.providers << ->(name) { send(provider, name) }
32
+ end
33
+ end
34
+ end
35
+
36
+ class Proxy
37
+ def initialize(&block)
38
+ @callback = block
39
+ end
40
+
41
+ def [](name)
42
+ @callback.call(name)
43
+ end
44
+
45
+ def method_missing(name, *args, &block)
46
+ @callback.call(name, *args, &block)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,35 @@
1
+ require 'active_support/concern'
2
+ require "hashie"
3
+
4
+ module Fume
5
+ module Settable
6
+ module RubyProvider
7
+ extend ActiveSupport::Concern
8
+
9
+ module ClassMethods
10
+ def ruby_provider(*files)
11
+ append_providers ProviderRuby.new(*files)
12
+ end
13
+ end
14
+
15
+ class ProviderRuby
16
+ def initialize(*files)
17
+ files = [ files ].flatten
18
+ @data = Hashie::Mash.new
19
+ files.each do |file|
20
+ next if !File.exist?(file)
21
+ instance_eval File.read(file), file.to_s
22
+ end
23
+ end
24
+
25
+ def settings
26
+ @data
27
+ end
28
+
29
+ def call(name)
30
+ @data[name]
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,31 @@
1
+ require 'active_support/concern'
2
+
3
+ module Fume
4
+ module Settable
5
+ module YamlProvider
6
+ extend ActiveSupport::Concern
7
+
8
+ module ClassMethods
9
+ def yaml_provider(*files)
10
+ append_providers ProviderYaml.new(*files)
11
+ end
12
+ end
13
+
14
+ class ProviderYaml
15
+ def initialize(*files)
16
+ files = [ files ].flatten
17
+ @data = {}
18
+ files.each do |file|
19
+ next if !File.exist?(file)
20
+ content = YAML.load(File.read(file))
21
+ @data = @data.deep_merge(content) if content
22
+ end
23
+ end
24
+
25
+ def call(name)
26
+ @data[name]
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ module Fume
2
+ module Settable
3
+ VERSION = File.read(File.expand_path("../../VERSION", __FILE__)).chomp
4
+ end
5
+ end
6
+
7
+ require File.expand_path('../fume-settable/base', __FILE__)
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fume-settable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sunteya
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: hashie
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activesupport
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '3.0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '3.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
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: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: version
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: a simple settings plugin for read on yaml, ruby, database, etc
79
+ email:
80
+ - Sunteya@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE
88
+ - README.md
89
+ - Rakefile
90
+ - VERSION
91
+ - fume-settable.gemspec
92
+ - lib/fume-settable.rb
93
+ - lib/fume-settable/base.rb
94
+ - lib/fume-settable/ruby_provider.rb
95
+ - lib/fume-settable/yaml_provider.rb
96
+ - lib/fume/settable.rb
97
+ homepage: ''
98
+ licenses: []
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ segments:
110
+ - 0
111
+ hash: 3491969668467509048
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ segments:
119
+ - 0
120
+ hash: 3491969668467509048
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 1.8.24
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: a simple settings plugin for read on yaml, ruby, database, etc
127
+ test_files: []