props-activerecord 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +2 -0
- data/Rakefile +1 -1
- data/lib/props/activerecord.rb +32 -0
- data/lib/props/activerecord/models.rb +48 -0
- data/lib/props/activerecord/schema.rb +24 -0
- data/lib/props/activerecord/version.rb +20 -2
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 247bc4451a1641dee16bbf5a91ff53281b753d92
|
4
|
+
data.tar.gz: d3264b0a4ebb670e5822ba2e7320869a31b9af74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83ca48dc53e14d46073b732a3c28d49f92648fa721ff0ec20215123885eb1e1b18033d121dc420f88d5dc8fd53771b028464226b3df76beaa0c41c11f95d838a
|
7
|
+
data.tar.gz: eb51d35bb869f26148cf39287bbf3a58352234eacf9c03ac6de530cdecacd96ab3e2d72a37af76770f3d49c74642073ed3fdbf2bb7df4c7e04ffe417dc939176
|
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
data/lib/props/activerecord.rb
CHANGED
@@ -5,8 +5,40 @@
|
|
5
5
|
## this is an addon/plugin/extension for the props gems (that is, will NOT work stand-alone)
|
6
6
|
|
7
7
|
|
8
|
+
# rubygems / 3rd party libs
|
9
|
+
require 'active_record' ## todo: add sqlite3? etc.
|
10
|
+
|
8
11
|
# our own code
|
9
12
|
|
10
13
|
require 'props/activerecord/version' # version always goes first
|
14
|
+
require 'props/activerecord/schema'
|
15
|
+
require 'props/activerecord/models'
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
module ConfDb
|
20
|
+
|
21
|
+
def self.create
|
22
|
+
CreateDb.new.up
|
23
|
+
end
|
24
|
+
|
25
|
+
# delete ALL records (use with care!)
|
26
|
+
def self.delete!
|
27
|
+
puts '*** deleting props table records/data...'
|
28
|
+
Prop.delete_all
|
29
|
+
end # method delete!
|
30
|
+
|
31
|
+
## def self.stats ## remove ? -- duplicate - use tables - why?? why not????
|
32
|
+
## puts "#{Model::Prop} props"
|
33
|
+
## end
|
34
|
+
|
35
|
+
def self.tables
|
36
|
+
puts "#{Prop.count} props"
|
37
|
+
end
|
38
|
+
|
39
|
+
end # module ConfDb
|
40
|
+
|
41
|
+
|
11
42
|
|
43
|
+
puts ConfDb.banner if $DEBUG || (defined?($RUBYLIBS_DEBUG) && $RUBYLIBS_DEBUG) # say hello
|
12
44
|
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ConfDb
|
4
|
+
module Model
|
5
|
+
|
6
|
+
|
7
|
+
class Prop < ActiveRecord::Base
|
8
|
+
|
9
|
+
### todo/fix: move create_from_fixture! method to textutils ??? - why? why not?
|
10
|
+
## yes - move to textutils! - fixture concept/notion is part of textutils
|
11
|
+
|
12
|
+
def self.create_from_fixture!( name, path )
|
13
|
+
key = "db.#{fixture_name_to_prop_key(name)}.version"
|
14
|
+
|
15
|
+
value = "txt.#{File.mtime(path).strftime('%Y.%m.%d')}"
|
16
|
+
|
17
|
+
Prop.create!( key: key, value: value )
|
18
|
+
end
|
19
|
+
|
20
|
+
### todo:
|
21
|
+
## add latest scope -> order props by creation date desc!!!!
|
22
|
+
|
23
|
+
## add dump -> dump latest props to console via puts
|
24
|
+
## check - dump already taken by activerecord??
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
# helper
|
29
|
+
# change at/2012_13/bl to at.2012/13.bl
|
30
|
+
# or quali_2012_13_europe_c to quali.2012/13.europe.c
|
31
|
+
|
32
|
+
def self.fixture_name_to_prop_key( name )
|
33
|
+
prop_key = name.gsub( '/', '.' )
|
34
|
+
prop_key = prop_key.gsub( /(\d{4})_(\d{2})/, '\1/\2' ) # 2012_13 => 2012/13
|
35
|
+
prop_key = prop_key.gsub( '_', '.' )
|
36
|
+
prop_key
|
37
|
+
end
|
38
|
+
|
39
|
+
end # class Prop
|
40
|
+
|
41
|
+
end # module Model
|
42
|
+
|
43
|
+
##### add convenience module alias in plural e.g. lets you use include ConfDb::Models
|
44
|
+
Models = Model
|
45
|
+
##### add convenience class alias e.g lets you use Prop instead of Model::Prop
|
46
|
+
Prop = Model::Prop
|
47
|
+
|
48
|
+
end # module ConfDb
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module ConfDb
|
4
|
+
|
5
|
+
class CreateDb < ActiveRecord::Migration
|
6
|
+
|
7
|
+
def up
|
8
|
+
|
9
|
+
create_table :props do |t|
|
10
|
+
t.string :key, null: false
|
11
|
+
t.string :value, null: false
|
12
|
+
t.string :kind # e.g. version|user|sys(tem)|db etc. # note: can NOT use type - already used by ActiveRecord
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def down
|
19
|
+
raise ActiveRecord::IrreversibleMigration
|
20
|
+
end
|
21
|
+
|
22
|
+
end # class CreateDb
|
23
|
+
|
24
|
+
end # module ConfDb
|
@@ -1,6 +1,24 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module ConfDb
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
MAJOR = 0 ## todo: namespace inside version or something - why? why not??
|
6
|
+
MINOR = 1
|
7
|
+
PATCH = 0
|
8
|
+
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
9
|
+
|
10
|
+
def self.version
|
11
|
+
VERSION
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.banner
|
15
|
+
# todo: add RUBY_PATCHLEVEL or RUBY_PATCH_LEVEL??
|
16
|
+
"confdb/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.root
|
20
|
+
"#{File.expand_path( File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) )}"
|
21
|
+
end
|
22
|
+
|
23
|
+
end # module ConfDb
|
6
24
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: props-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.1.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.1.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,6 +81,8 @@ files:
|
|
81
81
|
- README.md
|
82
82
|
- Rakefile
|
83
83
|
- lib/props/activerecord.rb
|
84
|
+
- lib/props/activerecord/models.rb
|
85
|
+
- lib/props/activerecord/schema.rb
|
84
86
|
- lib/props/activerecord/version.rb
|
85
87
|
homepage: https://github.com/rubylibs/props-activerecord
|
86
88
|
licenses:
|