listly 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +175 -0
- data/README.md +45 -0
- data/Rakefile +21 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/listly/backup_lists.rb +110 -0
- data/lib/listly/base_list.rb +53 -0
- data/lib/listly/list_constants.rb +10 -0
- data/lib/listly/lists.rb +37 -0
- data/lib/listly/load_lists.rb +41 -0
- data/lib/listly/railtie.rb +23 -0
- data/lib/listly/version.rb +3 -0
- data/lib/listly.rb +23 -0
- data/listly.gemspec +42 -0
- data/log/test.log +0 -0
- metadata +191 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 67f25faccff6defb6be62e280348cc8f283009c0
|
4
|
+
data.tar.gz: 58491f3bd88ee9d92d182138ea937374ac4ab308
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 251b987f275f8b8219b74fc4b147f047d359983c1c84626a1bb2c41faefecc5036ade9cacca574b50047c499f656f6caf5d7932c7f03e27b1ea8a1615282c02b
|
7
|
+
data.tar.gz: 4320345d0927512998dc49a9acdde5dfc911f7c568dbfc071953cdd158b49cfcb2afb4fcfe824125952b3d69f4049e7f9c0c840e75b794f9e1e0442e062848ef
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
listly
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.1.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
listly (0.1.1)
|
5
|
+
rails (>= 4.1.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionmailer (4.2.1)
|
11
|
+
actionpack (= 4.2.1)
|
12
|
+
actionview (= 4.2.1)
|
13
|
+
activejob (= 4.2.1)
|
14
|
+
mail (~> 2.5, >= 2.5.4)
|
15
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
16
|
+
actionpack (4.2.1)
|
17
|
+
actionview (= 4.2.1)
|
18
|
+
activesupport (= 4.2.1)
|
19
|
+
rack (~> 1.6)
|
20
|
+
rack-test (~> 0.6.2)
|
21
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
22
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
23
|
+
actionview (4.2.1)
|
24
|
+
activesupport (= 4.2.1)
|
25
|
+
builder (~> 3.1)
|
26
|
+
erubis (~> 2.7.0)
|
27
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
28
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
29
|
+
activejob (4.2.1)
|
30
|
+
activesupport (= 4.2.1)
|
31
|
+
globalid (>= 0.3.0)
|
32
|
+
activemodel (4.2.1)
|
33
|
+
activesupport (= 4.2.1)
|
34
|
+
builder (~> 3.1)
|
35
|
+
activerecord (4.2.1)
|
36
|
+
activemodel (= 4.2.1)
|
37
|
+
activesupport (= 4.2.1)
|
38
|
+
arel (~> 6.0)
|
39
|
+
activesupport (4.2.1)
|
40
|
+
i18n (~> 0.7)
|
41
|
+
json (~> 1.7, >= 1.7.7)
|
42
|
+
minitest (~> 5.1)
|
43
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
44
|
+
tzinfo (~> 1.1)
|
45
|
+
arel (6.0.0)
|
46
|
+
builder (3.2.2)
|
47
|
+
coveralls (0.7.12)
|
48
|
+
multi_json (~> 1.10)
|
49
|
+
rest-client (>= 1.6.8, < 2)
|
50
|
+
simplecov (~> 0.9.1)
|
51
|
+
term-ansicolor (~> 1.3)
|
52
|
+
thor (~> 0.19.1)
|
53
|
+
diff-lcs (1.2.5)
|
54
|
+
docile (1.1.5)
|
55
|
+
domain_name (0.5.23)
|
56
|
+
unf (>= 0.0.5, < 1.0.0)
|
57
|
+
erubis (2.7.0)
|
58
|
+
given_core (3.7.0)
|
59
|
+
sorcerer (>= 0.3.7)
|
60
|
+
globalid (0.3.3)
|
61
|
+
activesupport (>= 4.1.0)
|
62
|
+
hike (1.2.3)
|
63
|
+
http-cookie (1.0.2)
|
64
|
+
domain_name (~> 0.5)
|
65
|
+
i18n (0.7.0)
|
66
|
+
json (1.8.2)
|
67
|
+
loofah (2.0.1)
|
68
|
+
nokogiri (>= 1.5.9)
|
69
|
+
mail (2.6.3)
|
70
|
+
mime-types (>= 1.16, < 3)
|
71
|
+
mime-types (2.4.3)
|
72
|
+
mini_portile (0.6.2)
|
73
|
+
minitest (5.5.1)
|
74
|
+
multi_json (1.11.0)
|
75
|
+
netrc (0.10.3)
|
76
|
+
nokogiri (1.6.6.2)
|
77
|
+
mini_portile (~> 0.6.0)
|
78
|
+
rack (1.6.0)
|
79
|
+
rack-test (0.6.3)
|
80
|
+
rack (>= 1.0)
|
81
|
+
rails (4.2.1)
|
82
|
+
actionmailer (= 4.2.1)
|
83
|
+
actionpack (= 4.2.1)
|
84
|
+
actionview (= 4.2.1)
|
85
|
+
activejob (= 4.2.1)
|
86
|
+
activemodel (= 4.2.1)
|
87
|
+
activerecord (= 4.2.1)
|
88
|
+
activesupport (= 4.2.1)
|
89
|
+
bundler (>= 1.3.0, < 2.0)
|
90
|
+
railties (= 4.2.1)
|
91
|
+
sprockets-rails
|
92
|
+
rails-deprecated_sanitizer (1.0.3)
|
93
|
+
activesupport (>= 4.2.0.alpha)
|
94
|
+
rails-dom-testing (1.0.6)
|
95
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
96
|
+
nokogiri (~> 1.6.0)
|
97
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
98
|
+
rails-html-sanitizer (1.0.2)
|
99
|
+
loofah (~> 2.0)
|
100
|
+
railties (4.2.1)
|
101
|
+
actionpack (= 4.2.1)
|
102
|
+
activesupport (= 4.2.1)
|
103
|
+
rake (>= 0.8.7)
|
104
|
+
thor (>= 0.18.1, < 2.0)
|
105
|
+
rake (10.4.2)
|
106
|
+
rest-client (1.8.0)
|
107
|
+
http-cookie (>= 1.0.2, < 2.0)
|
108
|
+
mime-types (>= 1.16, < 3.0)
|
109
|
+
netrc (~> 0.7)
|
110
|
+
rspec (3.2.0)
|
111
|
+
rspec-core (~> 3.2.0)
|
112
|
+
rspec-expectations (~> 3.2.0)
|
113
|
+
rspec-mocks (~> 3.2.0)
|
114
|
+
rspec-collection_matchers (1.1.2)
|
115
|
+
rspec-expectations (>= 2.99.0.beta1)
|
116
|
+
rspec-core (3.2.2)
|
117
|
+
rspec-support (~> 3.2.0)
|
118
|
+
rspec-expectations (3.2.0)
|
119
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
120
|
+
rspec-support (~> 3.2.0)
|
121
|
+
rspec-given (3.7.0)
|
122
|
+
given_core (= 3.7.0)
|
123
|
+
rspec (>= 2.14.0)
|
124
|
+
rspec-mocks (3.2.1)
|
125
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
126
|
+
rspec-support (~> 3.2.0)
|
127
|
+
rspec-rails (3.2.1)
|
128
|
+
actionpack (>= 3.0, < 4.3)
|
129
|
+
activesupport (>= 3.0, < 4.3)
|
130
|
+
railties (>= 3.0, < 4.3)
|
131
|
+
rspec-core (~> 3.2.0)
|
132
|
+
rspec-expectations (~> 3.2.0)
|
133
|
+
rspec-mocks (~> 3.2.0)
|
134
|
+
rspec-support (~> 3.2.0)
|
135
|
+
rspec-support (3.2.2)
|
136
|
+
simplecov (0.9.2)
|
137
|
+
docile (~> 1.1.0)
|
138
|
+
multi_json (~> 1.0)
|
139
|
+
simplecov-html (~> 0.9.0)
|
140
|
+
simplecov-html (0.9.0)
|
141
|
+
sorcerer (1.0.2)
|
142
|
+
sprockets (2.12.3)
|
143
|
+
hike (~> 1.2)
|
144
|
+
multi_json (~> 1.0)
|
145
|
+
rack (~> 1.0)
|
146
|
+
tilt (~> 1.1, != 1.3.0)
|
147
|
+
sprockets-rails (2.2.4)
|
148
|
+
actionpack (>= 3.0)
|
149
|
+
activesupport (>= 3.0)
|
150
|
+
sprockets (>= 2.8, < 4.0)
|
151
|
+
term-ansicolor (1.3.0)
|
152
|
+
tins (~> 1.0)
|
153
|
+
thor (0.19.1)
|
154
|
+
thread_safe (0.3.5)
|
155
|
+
tilt (1.4.1)
|
156
|
+
tins (1.3.5)
|
157
|
+
tzinfo (1.2.2)
|
158
|
+
thread_safe (~> 0.1)
|
159
|
+
unf (0.1.4)
|
160
|
+
unf_ext
|
161
|
+
unf_ext (0.0.6)
|
162
|
+
|
163
|
+
PLATFORMS
|
164
|
+
ruby
|
165
|
+
|
166
|
+
DEPENDENCIES
|
167
|
+
bundler (~> 1.9)
|
168
|
+
coveralls
|
169
|
+
listly!
|
170
|
+
rack
|
171
|
+
rake (~> 10.0)
|
172
|
+
rspec
|
173
|
+
rspec-collection_matchers
|
174
|
+
rspec-given
|
175
|
+
rspec-rails
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Listly
|
2
|
+
|
3
|
+
There are lots of occasions in Rails apps where you need simple lists, such as a list of States in a Country etc.
|
4
|
+
Listly is for when you want to store data in hash format in external yml type files such as storing them in the
|
5
|
+
rails locales files that can be retrieved from I18n.
|
6
|
+
|
7
|
+
## Travis CI
|
8
|
+
[![Build Status](https://travis-ci.org/netflakes/listly.svg?branch=master)](https://travis-ci.org/netflakes/listly)
|
9
|
+
|
10
|
+
## Coveralls
|
11
|
+
[![Coverage Status](https://coveralls.io/repos/netflakes/listly/badge.svg?branch=master)](https://coveralls.io/r/netflakes/listly?branch=master)
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'listly'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install listly
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
TODO: Write usage instructions here
|
32
|
+
|
33
|
+
## Development
|
34
|
+
|
35
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
36
|
+
|
37
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it ( https://github.com/[my-github-username]/listly/fork )
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
#
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
# - ensure the default 'rake' runs the whole suite!
|
6
|
+
task :default => 'spec:all'
|
7
|
+
#
|
8
|
+
desc 'Run the whole test suite'
|
9
|
+
namespace :spec do
|
10
|
+
# Or individual pieces
|
11
|
+
namespace :select do
|
12
|
+
RSpec::Core::RakeTask.new(:railtie) do |t|
|
13
|
+
t.pattern = FileList["spec/railtie/*_spec.rb"]
|
14
|
+
end
|
15
|
+
RSpec::Core::RakeTask.new(:listly) do |t|
|
16
|
+
t.pattern = FileList["spec/listly/*_spec.rb"]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
#
|
20
|
+
task :all => ["spec:select:listly", "spec:select:railtie"]
|
21
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "listly"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
#
|
2
|
+
module ListParent
|
3
|
+
#
|
4
|
+
# - creates items of the passed in item_class with the passed in type_prefix for code and name for list items
|
5
|
+
def all_list_items(type_prefix, item_class, list_items_hash = {})
|
6
|
+
list_items = []
|
7
|
+
list_items_hash.each do |item|
|
8
|
+
data = {}
|
9
|
+
item.each{ |key, value| data["#{type_prefix}_#{key}"] = "#{value}" }
|
10
|
+
list_items << Module.const_get("Lists::#{item_class}").new(data)
|
11
|
+
end
|
12
|
+
list_items
|
13
|
+
end
|
14
|
+
|
15
|
+
def list_item_name(all_items, code_field, name_field, list_item_code)
|
16
|
+
name = ''
|
17
|
+
all_items.map do |item|
|
18
|
+
if (item.send code_field) == list_item_code
|
19
|
+
name = item.send name_field
|
20
|
+
end
|
21
|
+
end
|
22
|
+
name
|
23
|
+
end
|
24
|
+
|
25
|
+
class MyListType
|
26
|
+
attr_accessor :list_hash # - this is for convenience methods in Rails
|
27
|
+
|
28
|
+
# - dynamically create the properties from the passed in hash at runtime
|
29
|
+
define_method :initialize do |args|
|
30
|
+
@list_hash = args
|
31
|
+
|
32
|
+
args.each do |name, value|
|
33
|
+
instance_variable_get("@#{name}")
|
34
|
+
instance_variable_set("@#{name}", value)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# - these are for convenience methods in Rails i.e. make lists behave like AR objects
|
39
|
+
def [](key)
|
40
|
+
list_hash[key.to_s]
|
41
|
+
end
|
42
|
+
|
43
|
+
def []=(key, value)
|
44
|
+
list_hash[key.to_s] = value
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
#
|
50
|
+
module Lists
|
51
|
+
#
|
52
|
+
# List Class Names as Constants
|
53
|
+
TEST1_TYPE = :test1_types_hash
|
54
|
+
TEST2_TYPE = :test2_types_hash
|
55
|
+
#
|
56
|
+
|
57
|
+
# some convenience methods to create the list modules and class from the CONSTANT
|
58
|
+
class << self
|
59
|
+
# Returns a hash of class names to hash storage details as sym.
|
60
|
+
def list_name_constants
|
61
|
+
self.constants.each_with_object({}) do |name, hash|
|
62
|
+
# Ignore any class constants
|
63
|
+
next if (storage_location = Lists.const_get(name)).is_a?(Module)
|
64
|
+
hash[name] = storage_location
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Returns a module name from a constant name.
|
69
|
+
def module_name_for_list_name(name)
|
70
|
+
module_name = name.to_s.titleize.gsub(' ', '')
|
71
|
+
end
|
72
|
+
|
73
|
+
def class_name_for_item_name(name)
|
74
|
+
class_name = name.to_s.titleize.gsub(' ', '')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
#
|
79
|
+
Lists.list_name_constants.each do |name, store_hash|
|
80
|
+
list_module = Module.new
|
81
|
+
new_module_name = Lists.module_name_for_list_name(name)
|
82
|
+
# - add the new module to the list of constants!
|
83
|
+
list_module.module_eval do
|
84
|
+
include ListParent
|
85
|
+
|
86
|
+
define_method(:storage_location) { store_hash }
|
87
|
+
|
88
|
+
define_method("all_#{name.to_s.underscore.pluralize}") {
|
89
|
+
all_list_items(name.to_s.underscore.to_sym,
|
90
|
+
"#{new_module_name}::My#{new_module_name}", I18n.t("#{store_hash}"))
|
91
|
+
}
|
92
|
+
|
93
|
+
define_method("#{name.to_s.underscore}_name") {
|
94
|
+
list_item_name(Module.const_get("all_#{name.to_s.underscore.pluralize}"),
|
95
|
+
"#{name.to_s.underscore}_code".to_sym, "#{name.to_s.underscore}_name".to_sym,
|
96
|
+
list_item_code)
|
97
|
+
}
|
98
|
+
end
|
99
|
+
# - create the internal class that will hold the list data (hash)
|
100
|
+
klass = Class.new(ListParent::MyListType)
|
101
|
+
|
102
|
+
klass.send(:define_method, :attr_accessor) { "#{new_module_name}_code".to_sym }
|
103
|
+
klass.send(:define_method, :attr_accessor) { "#{new_module_name}_name".to_sym }
|
104
|
+
klass.send(:define_method, :code) { code }
|
105
|
+
|
106
|
+
# - add this class to the module constants
|
107
|
+
class_name = "My#{new_module_name}"
|
108
|
+
list_module.const_set(class_name, klass)
|
109
|
+
Lists.const_set(new_module_name, list_module)
|
110
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#
|
2
|
+
module Listly
|
3
|
+
#
|
4
|
+
module BaseList
|
5
|
+
#
|
6
|
+
# - creates items of the passed in item_class with the passed in type_prefix for code and name for list items
|
7
|
+
def all_list_items(type_prefix, item_class, list_items_hash = {})
|
8
|
+
list_items = []
|
9
|
+
list_items_hash.each do |item|
|
10
|
+
data = {}
|
11
|
+
item.each{ |key, value| data["#{type_prefix}_#{key}"] = "#{value}" }
|
12
|
+
list_items << Module.const_get("Listly::#{item_class}").new(data)
|
13
|
+
end
|
14
|
+
list_items
|
15
|
+
end
|
16
|
+
|
17
|
+
def list_item_name(all_items, code_field, name_field, list_item_code)
|
18
|
+
name = ''
|
19
|
+
all_items.map do |item|
|
20
|
+
if (item.send code_field) == list_item_code
|
21
|
+
name = item.send name_field
|
22
|
+
end
|
23
|
+
end
|
24
|
+
name
|
25
|
+
end
|
26
|
+
|
27
|
+
class MyListType
|
28
|
+
attr_accessor :list_hash # - this is for convenience methods in Rails
|
29
|
+
|
30
|
+
# - dynamically create the properties from the passed in hash at runtime
|
31
|
+
define_method :initialize do |args|
|
32
|
+
@list_hash = args
|
33
|
+
|
34
|
+
args.each do |name, value|
|
35
|
+
# - add instance getters and setters dynamically
|
36
|
+
instance_variable_get("@#{name}")
|
37
|
+
instance_variable_set("@#{name}", value)
|
38
|
+
# - add attr_reader dynamically
|
39
|
+
self.class_eval("attr_reader :#{name}")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# - these are for convenience methods in Rails i.e. make lists behave like AR objects
|
44
|
+
def [](key)
|
45
|
+
list_hash[key.to_s]
|
46
|
+
end
|
47
|
+
|
48
|
+
def []=(key, value)
|
49
|
+
list_hash[key.to_s] = value
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/listly/lists.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#
|
2
|
+
module Listly
|
3
|
+
#
|
4
|
+
# some convenience methods to create the list modules and class from the CONSTANT
|
5
|
+
class << self
|
6
|
+
#
|
7
|
+
# List Class Names as Constants
|
8
|
+
def include_constants_module
|
9
|
+
constants_module_sym = Listly.config.listly_constants_module
|
10
|
+
constants_module_str = constants_module_sym.to_s.titleize.gsub(' ', '')
|
11
|
+
constants_module = Module.const_get(constants_module_str) unless constants_module_str.length == 0
|
12
|
+
|
13
|
+
if constants_module
|
14
|
+
self.send(:include, constants_module)
|
15
|
+
else
|
16
|
+
self.send(:include, Listly::ListConstants)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
# Returns a hash of class names to hash storage details as sym.
|
20
|
+
def list_name_constants
|
21
|
+
self.constants.each_with_object({}) do |name, hash|
|
22
|
+
# Ignore any class constants
|
23
|
+
next if (storage_location = Listly.const_get(name)).is_a?(Module)
|
24
|
+
hash[name] = storage_location
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns a module name from a constant name.
|
29
|
+
def module_name_for_list_name(name)
|
30
|
+
module_name = name.to_s.titleize.gsub(' ', '')
|
31
|
+
end
|
32
|
+
|
33
|
+
def class_name_for_item_name(name)
|
34
|
+
class_name = name.to_s.titleize.gsub(' ', '')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module LoadLists
|
2
|
+
def self.load
|
3
|
+
#
|
4
|
+
# this will dynamically include the configured Constants module..
|
5
|
+
#
|
6
|
+
Listly.include_constants_module
|
7
|
+
#
|
8
|
+
# as this file is loaded each List Module and internal item Class is dynamically created!
|
9
|
+
#
|
10
|
+
Listly.list_name_constants.each do |name, store_hash|
|
11
|
+
list_module = Module.new
|
12
|
+
new_module_name = Listly.module_name_for_list_name(name)
|
13
|
+
# - add the new module to the list of constants!
|
14
|
+
list_module.module_eval do
|
15
|
+
include Listly::BaseList
|
16
|
+
|
17
|
+
define_method(:storage_location) { store_hash }
|
18
|
+
|
19
|
+
define_method("all_#{name.to_s.underscore.pluralize}") {
|
20
|
+
all_list_items(name.to_s.underscore.to_sym,
|
21
|
+
"#{new_module_name}::My#{new_module_name}", I18n.t("#{store_hash}"))
|
22
|
+
}
|
23
|
+
|
24
|
+
define_method("#{name.to_s.underscore}_name") {
|
25
|
+
list_item_name(Module.const_get("all_#{name.to_s.underscore.pluralize}"),
|
26
|
+
"#{name.to_s.underscore}_code".to_sym, "#{name.to_s.underscore}_name".to_sym,
|
27
|
+
list_item_code)
|
28
|
+
}
|
29
|
+
end
|
30
|
+
# - create the internal class that will hold the list data (hash)
|
31
|
+
klass = Class.new(Listly::BaseList::MyListType)
|
32
|
+
klass.send(:define_method, :code) { code }
|
33
|
+
|
34
|
+
# - add this class to the module constants
|
35
|
+
class_name = "My#{new_module_name}"
|
36
|
+
list_module.const_set(class_name, klass)
|
37
|
+
|
38
|
+
Listly.const_set(new_module_name, list_module)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#
|
2
|
+
module Listly
|
3
|
+
class Railtie < Rails::Railtie
|
4
|
+
#
|
5
|
+
puts "\n\n Loading Railtie..\n\n"
|
6
|
+
#
|
7
|
+
# enable namespaced configuration in Rails environments
|
8
|
+
config.listly = ActiveSupport::OrderedOptions.new
|
9
|
+
#
|
10
|
+
initializer :after_initialize do |app|
|
11
|
+
#
|
12
|
+
Listly.configure do |config|
|
13
|
+
config.listly_store_location = app.config.listly[:listly_store_location]
|
14
|
+
config.listly_constants_module = app.config.listly[:listly_constants_module]
|
15
|
+
end
|
16
|
+
#
|
17
|
+
# dynamically load the client rails app module that has the list constants
|
18
|
+
LoadLists.load
|
19
|
+
Listly.include_constants_module
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
#
|
data/lib/listly.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#
|
2
|
+
require File.dirname(__FILE__) + '/listly/base_list'
|
3
|
+
require File.dirname(__FILE__) + '/listly/list_constants'
|
4
|
+
require File.dirname(__FILE__) + '/listly/lists'
|
5
|
+
require File.dirname(__FILE__) + '/listly/load_lists'
|
6
|
+
require File.dirname(__FILE__) + '/listly/railtie' if defined? ::Rails::Railtie
|
7
|
+
#
|
8
|
+
# The config class allows the Rails Application to store configuration about the gem
|
9
|
+
#
|
10
|
+
module Listly
|
11
|
+
class Config
|
12
|
+
attr_accessor :listly_store_location, :listly_constants_module
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.config
|
16
|
+
@@config ||= Config.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.configure
|
20
|
+
yield self.config
|
21
|
+
end
|
22
|
+
end
|
23
|
+
#
|
data/listly.gemspec
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'listly/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "listly"
|
8
|
+
spec.version = Listly::VERSION
|
9
|
+
spec.authors = ["Steve Forkin"]
|
10
|
+
spec.email = ["steve.forkin@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{List objects from hash data stored in i18n}
|
13
|
+
spec.description = %q{Gem to create simple list objects from hash data stored in i18n}
|
14
|
+
spec.homepage = "http://github.com/netflakes/listly"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
#if spec.respond_to?(:metadata)
|
22
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
|
23
|
+
#end
|
24
|
+
#
|
25
|
+
# Development dependencies
|
26
|
+
#
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "coveralls"
|
30
|
+
#
|
31
|
+
# - gem related ones
|
32
|
+
spec.add_development_dependency 'rack'
|
33
|
+
spec.add_development_dependency 'rspec'
|
34
|
+
spec.add_development_dependency 'rspec-given'
|
35
|
+
spec.add_development_dependency 'rspec-collection_matchers'
|
36
|
+
spec.add_development_dependency 'rspec-rails'
|
37
|
+
#
|
38
|
+
# Runtime dependencies
|
39
|
+
#
|
40
|
+
spec.add_runtime_dependency 'rails', '>= 4.1.1'
|
41
|
+
#
|
42
|
+
end
|
data/log/test.log
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: listly
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steve Forkin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-31 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.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: coveralls
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-given
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec-collection_matchers
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec-rails
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rails
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 4.1.1
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 4.1.1
|
139
|
+
description: Gem to create simple list objects from hash data stored in i18n
|
140
|
+
email:
|
141
|
+
- steve.forkin@gmail.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".coveralls.yml"
|
147
|
+
- ".gitignore"
|
148
|
+
- ".rspec"
|
149
|
+
- ".ruby-gemset"
|
150
|
+
- ".ruby-version"
|
151
|
+
- ".travis.yml"
|
152
|
+
- Gemfile
|
153
|
+
- Gemfile.lock
|
154
|
+
- README.md
|
155
|
+
- Rakefile
|
156
|
+
- bin/console
|
157
|
+
- bin/setup
|
158
|
+
- lib/listly.rb
|
159
|
+
- lib/listly/backup_lists.rb
|
160
|
+
- lib/listly/base_list.rb
|
161
|
+
- lib/listly/list_constants.rb
|
162
|
+
- lib/listly/lists.rb
|
163
|
+
- lib/listly/load_lists.rb
|
164
|
+
- lib/listly/railtie.rb
|
165
|
+
- lib/listly/version.rb
|
166
|
+
- listly.gemspec
|
167
|
+
- log/test.log
|
168
|
+
homepage: http://github.com/netflakes/listly
|
169
|
+
licenses: []
|
170
|
+
metadata: {}
|
171
|
+
post_install_message:
|
172
|
+
rdoc_options: []
|
173
|
+
require_paths:
|
174
|
+
- lib
|
175
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
|
+
requirements:
|
182
|
+
- - ">="
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: '0'
|
185
|
+
requirements: []
|
186
|
+
rubyforge_project:
|
187
|
+
rubygems_version: 2.2.2
|
188
|
+
signing_key:
|
189
|
+
specification_version: 4
|
190
|
+
summary: List objects from hash data stored in i18n
|
191
|
+
test_files: []
|