informante 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +100 -0
- data/Rakefile +1 -0
- data/informante.gemspec +23 -0
- data/lib/generators/informante/install_generator.rb +17 -0
- data/lib/generators/templates/informante.rb +7 -0
- data/lib/generators/templates/informante.yml +46 -0
- data/lib/informante.rb +62 -0
- data/lib/informante/hash.rb +10 -0
- data/lib/informante/informante_object.rb +15 -0
- data/lib/informante/templates.rb +4 -0
- data/lib/informante/version.rb +3 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a8f97cb1b4499fe1d35af676b87e07d14010ba28
|
4
|
+
data.tar.gz: 6108c457932262b534b06197f542e6c6858fdde5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eb3b90c313d7c77eeefa0575b4c8a7506e196166048813f837770fc38f03141e57b9e5831be10b36465c08d615e336ba8e497362d158f3d936f75a8a204d8439
|
7
|
+
data.tar.gz: 3749c60bf413a622f4d73f7b9f7c773972fe0f33b328ead611ba65ea606002bd160adc1708f96feb1ea334f8f48c5101f4f79b38f1ad95a74612fec96940fbdd
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 igortice
|
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,100 @@
|
|
1
|
+
# Informante
|
2
|
+
|
3
|
+
Simple rails gem for configurations of global inforamations
|
4
|
+
|
5
|
+
This gem is to provide a simple way of storing information in one place and get this information anywhere in a Rails application.
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'informante'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
bundle install
|
20
|
+
```
|
21
|
+
|
22
|
+
Finishing, use the generator provided by Informante:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
rails g informante:install
|
26
|
+
```
|
27
|
+
> This command is responsible for generating two files for our application:
|
28
|
+
> * informante.yml - file with yaml markup to store information for our application
|
29
|
+
> * informante.rb - contains global method called `informante` for our application
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
By default, our `informante.yml` file has the following configuration:
|
34
|
+
|
35
|
+
```yaml
|
36
|
+
# -- basic example for informante.yml --
|
37
|
+
#
|
38
|
+
system:
|
39
|
+
name : 'Name System'
|
40
|
+
title : 'Title System'
|
41
|
+
description : 'Description System'
|
42
|
+
company : '© Company System'
|
43
|
+
business : 'Business System'
|
44
|
+
developers : [
|
45
|
+
{
|
46
|
+
name : 'name',
|
47
|
+
email : 'email',
|
48
|
+
site : 'site'
|
49
|
+
},
|
50
|
+
]
|
51
|
+
```
|
52
|
+
|
53
|
+
> you can store the configuration file that you want, simply follow the standard format for yaml and save the file `informante.yml`
|
54
|
+
|
55
|
+
At every point of our application, just use the global method `informante`.
|
56
|
+
See an example on the console:
|
57
|
+
|
58
|
+
```sh
|
59
|
+
$ informante[:system][:name]
|
60
|
+
>> "Name System"
|
61
|
+
```
|
62
|
+
|
63
|
+
By default our informante method returns a hash with symbol key. This method responds to four types of format:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
- informante(:hash) # informante(:hash) == informant
|
67
|
+
- informante(:object)
|
68
|
+
- informante(:array)
|
69
|
+
- informante(:string)
|
70
|
+
```
|
71
|
+
Example for respond to object:
|
72
|
+
|
73
|
+
```sh
|
74
|
+
$ informante(:object).system.description
|
75
|
+
>> "Description System"
|
76
|
+
```
|
77
|
+
|
78
|
+
Example for respond to string:
|
79
|
+
|
80
|
+
```sh
|
81
|
+
$ informante(:string)
|
82
|
+
>> "{:system=>{:name=>\"Name System\", :title=>\"Title System\", :description=>\"Description System\", :company=>\"© Company System\", :business=>\"Business System\", :developers=>[{:name=>\"name\", :email=>\"email\", :site=>\"site\"}]}}"
|
83
|
+
```
|
84
|
+
|
85
|
+
|
86
|
+
## Notes
|
87
|
+
|
88
|
+
You can use the `informante` method directly:
|
89
|
+
|
90
|
+
* **controllers**
|
91
|
+
* **views**
|
92
|
+
* **models**
|
93
|
+
* **helpers**
|
94
|
+
|
95
|
+
Important, every time you **modify** the `informante.yml` file you must **restart** the **rails server**.
|
96
|
+
|
97
|
+
|
98
|
+
## Version
|
99
|
+
|
100
|
+
0.0.1
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/informante.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'informante/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "informante"
|
8
|
+
spec.version = Informante::VERSION
|
9
|
+
spec.authors = ["igortice"]
|
10
|
+
spec.email = ["igortice@gmail.com"]
|
11
|
+
spec.summary = %q{Simple gem rails for configurations of global inforamations}
|
12
|
+
spec.description = %q{This gem is to provide a simple way of storing information in one place and get this information anywhere in a Rails application.}
|
13
|
+
spec.homepage = "https://github.com/igortice/informante"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'informante/templates'
|
2
|
+
|
3
|
+
module Informante::Generators
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path("../../templates", __FILE__)
|
6
|
+
|
7
|
+
def copy_config_file
|
8
|
+
file_name = Informante::NAME_TEMPLATE_CONIG
|
9
|
+
copy_file(file_name, "config/#{file_name}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def copy_initializer_file
|
13
|
+
file_name = Informante::NAME_TEMPLATE_INITIALIZERS
|
14
|
+
copy_file(file_name, "config/initializers/#{file_name}")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# -- serveral examples for yml --
|
2
|
+
#
|
3
|
+
# invoice: 34843
|
4
|
+
# date : 2001-01-23
|
5
|
+
# bill_to: &id001
|
6
|
+
# given : Chris
|
7
|
+
# family : Dumars
|
8
|
+
# address:
|
9
|
+
# lines: |
|
10
|
+
# 458 Walkman Dr.
|
11
|
+
# Suite #292
|
12
|
+
# city : Royal Oak
|
13
|
+
# state : MI
|
14
|
+
# postal : 48046
|
15
|
+
# ship_to: *id001
|
16
|
+
# product:
|
17
|
+
# - sku : BL394D
|
18
|
+
# quantity : 4
|
19
|
+
# description : Basketball
|
20
|
+
# price : 450.00
|
21
|
+
# - sku : BL4438H
|
22
|
+
# quantity : 1
|
23
|
+
# description : Super Hoop
|
24
|
+
# price : 2392.00
|
25
|
+
# tax : 251.42
|
26
|
+
# total: 4443.52
|
27
|
+
# comments: >
|
28
|
+
# Late afternoon is best.
|
29
|
+
# Backup contact is Nancy
|
30
|
+
# Billsmer @ 338-4338.
|
31
|
+
|
32
|
+
# -- basic example for informante.yml --
|
33
|
+
#
|
34
|
+
system:
|
35
|
+
name : 'Name System'
|
36
|
+
title : 'Title System'
|
37
|
+
description : 'Description System'
|
38
|
+
company : '© Company System'
|
39
|
+
business : 'Business System'
|
40
|
+
developers : [
|
41
|
+
{
|
42
|
+
name : 'name',
|
43
|
+
email : 'email',
|
44
|
+
site : 'site'
|
45
|
+
},
|
46
|
+
]
|
data/lib/informante.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'informante/templates'
|
2
|
+
require 'informante/informante_object'
|
3
|
+
require 'informante/hash'
|
4
|
+
|
5
|
+
module Informante
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def set(type = nil)
|
9
|
+
return nil unless type
|
10
|
+
|
11
|
+
config(type)
|
12
|
+
end
|
13
|
+
|
14
|
+
def config(type = :hash)
|
15
|
+
case type
|
16
|
+
when :hash
|
17
|
+
to_hash
|
18
|
+
when :object
|
19
|
+
to_object
|
20
|
+
when :array
|
21
|
+
to_array
|
22
|
+
when :string
|
23
|
+
to_string
|
24
|
+
else
|
25
|
+
raise "type `:#{type}` invalid for informante"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_hash
|
30
|
+
file_informante_to_yaml.recursive_symbolize_keys!
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_array
|
34
|
+
to_hash.to_a
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_string
|
38
|
+
to_hash.to_s
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_object
|
42
|
+
InformanteObject.new to_hash
|
43
|
+
end
|
44
|
+
|
45
|
+
def path_file_informante_config
|
46
|
+
Rails.root.join('config', Informante::NAME_TEMPLATE_CONIG)
|
47
|
+
end
|
48
|
+
|
49
|
+
def file_informante
|
50
|
+
File.exist?(path_file_informante_config) ? File.read(path_file_informante_config) : nil
|
51
|
+
end
|
52
|
+
|
53
|
+
def file_informante_to_yaml
|
54
|
+
if self.file_informante
|
55
|
+
begin
|
56
|
+
YAML.load(file_informante)
|
57
|
+
rescue => e
|
58
|
+
raise "problem sintaxe file #{Informante::NAME_TEMPLATE_CONIG} #{e.to_s}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class Hash
|
2
|
+
def recursive_symbolize_keys!
|
3
|
+
symbolize_keys!
|
4
|
+
# symbolize each hash in .values
|
5
|
+
values.each { |h| h.recursive_symbolize_keys! if h.is_a?(Hash) }
|
6
|
+
# symbolize each hash inside an array in .values
|
7
|
+
values.select { |v| v.is_a?(Array) }.flatten.each { |h| h.recursive_symbolize_keys! if h.is_a?(Hash) }
|
8
|
+
self
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class InformanteObject < OpenStruct
|
2
|
+
def initialize(hash=nil)
|
3
|
+
@table = {}
|
4
|
+
@hash_table = {}
|
5
|
+
|
6
|
+
if hash
|
7
|
+
hash.each do |k,v|
|
8
|
+
@table[k.to_sym] = (v.is_a?(Hash) ? self.class.new(v) : v)
|
9
|
+
@hash_table[k.to_sym] = v
|
10
|
+
|
11
|
+
new_ostruct_member(k)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: informante
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- igortice
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: This gem is to provide a simple way of storing information in one place
|
42
|
+
and get this information anywhere in a Rails application.
|
43
|
+
email:
|
44
|
+
- igortice@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- informante.gemspec
|
55
|
+
- lib/generators/informante/install_generator.rb
|
56
|
+
- lib/generators/templates/informante.rb
|
57
|
+
- lib/generators/templates/informante.yml
|
58
|
+
- lib/informante.rb
|
59
|
+
- lib/informante/hash.rb
|
60
|
+
- lib/informante/informante_object.rb
|
61
|
+
- lib/informante/templates.rb
|
62
|
+
- lib/informante/version.rb
|
63
|
+
homepage: https://github.com/igortice/informante
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.1.11
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Simple gem rails for configurations of global inforamations
|
87
|
+
test_files: []
|