static-data 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/static-data/base.rb +23 -1
- data/lib/static-data/version.rb +1 -1
- data/static-data.gemspec +2 -2
- metadata +3 -3
data/lib/static-data/base.rb
CHANGED
@@ -1,22 +1,44 @@
|
|
1
1
|
module StaticData
|
2
2
|
class Base
|
3
|
+
# Overrides the default model class for this StaticData class. Use this
|
4
|
+
# if your StaticData class name is not "Static + ModelClass". If you stick
|
5
|
+
# to the standard naming convention, you don't need this method.
|
3
6
|
def self.set_model_class(other_model_class)
|
4
7
|
@model_class_name = other_model_class
|
5
8
|
end
|
6
9
|
|
10
|
+
# Returns the model class for this StaticData subclass (which is the class
|
11
|
+
# name without the "Static" prefix by default, but can be overridden via
|
12
|
+
# set_model_class).
|
7
13
|
def self.model_class
|
8
14
|
model_class_name = @model_class_name || self.name.sub(/^Static/, '')
|
9
15
|
Object.const_get(model_class_name)
|
10
16
|
end
|
11
17
|
|
18
|
+
# Deletes all model_class records from the database.
|
12
19
|
def self.reset
|
13
20
|
self.model_class.delete_all
|
14
21
|
end
|
15
22
|
|
23
|
+
# Override this method to control which attributes make up the data
|
24
|
+
# returned by the `rows` method.
|
25
|
+
def self.columns
|
26
|
+
[]
|
27
|
+
end
|
28
|
+
|
29
|
+
# Override this method to return the record data that should always exist
|
30
|
+
# in the model class's database table. The columns must appear in the
|
31
|
+
# the order specified by the `columns` method.
|
32
|
+
def self.rows
|
33
|
+
[]
|
34
|
+
end
|
35
|
+
|
36
|
+
# Creates new records for all of the data returned by the `rows` method
|
37
|
+
# of the StaticData subclass.
|
16
38
|
def self.install
|
17
39
|
cols = self.columns
|
18
40
|
row_class = self.model_class
|
19
|
-
rows.each do |row|
|
41
|
+
self.rows.each do |row|
|
20
42
|
row_class.create!(Hash[cols.zip(row)], :without_protection => true)
|
21
43
|
end
|
22
44
|
end
|
data/lib/static-data/version.rb
CHANGED
data/static-data.gemspec
CHANGED
@@ -7,13 +7,13 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "static-data"
|
8
8
|
spec.version = StaticData::VERSION
|
9
9
|
spec.authors = ["Ben Turner"]
|
10
|
-
spec.email = ["
|
10
|
+
spec.email = ["codewrangler@outofcoffee.com"]
|
11
11
|
spec.description = %q{Rails plugin to manage static data in ActiveRecord
|
12
12
|
models/tables}
|
13
13
|
spec.summary = %q{StaticData is a Rails plugin that lets you easily
|
14
14
|
manage fixed data that you want to always have in your database, and
|
15
15
|
is primarily useful for pre-populating lookup tables and the like.}
|
16
|
-
spec.homepage = ""
|
16
|
+
spec.homepage = "https://github.com/kindjar/static-data"
|
17
17
|
spec.license = "MIT"
|
18
18
|
|
19
19
|
spec.files = `git ls-files`.split($/)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: static-data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -77,7 +77,7 @@ dependencies:
|
|
77
77
|
version: '2.6'
|
78
78
|
description: ! "Rails plugin to manage static data in ActiveRecord \n models/tables"
|
79
79
|
email:
|
80
|
-
-
|
80
|
+
- codewrangler@outofcoffee.com
|
81
81
|
executables: []
|
82
82
|
extensions: []
|
83
83
|
extra_rdoc_files: []
|
@@ -94,7 +94,7 @@ files:
|
|
94
94
|
- lib/static-data/version.rb
|
95
95
|
- spec/static_data_spec.rb
|
96
96
|
- static-data.gemspec
|
97
|
-
homepage:
|
97
|
+
homepage: https://github.com/kindjar/static-data
|
98
98
|
licenses:
|
99
99
|
- MIT
|
100
100
|
post_install_message:
|