local_model 0.1.12 → 0.1.13
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.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +4 -2
- data/Rakefile +7 -4
- data/bin/local_model +5 -0
- data/lib/local_model/generators/initialize.rb +32 -0
- data/lib/local_model/helpers/pluralized_words.rb +0 -1
- data/lib/local_model/templates/data_accessor.erb +61 -0
- data/lib/local_model/templates/generate_model.erb +20 -0
- data/lib/local_model/templates/initializer.erb +7 -0
- data/lib/local_model/version.rb +1 -1
- data/lib/local_model.rb +1 -0
- data/local_model.gemspec +5 -2
- metadata +12 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e778e1ced2f3d028e36ac5363e110343ee1f290fe97f23fcf2005ee3a38cfdb
|
4
|
+
data.tar.gz: b5d80e4c968830806dfc33e23f7bd72000c1382c59bb22dc96b952cf9a949766
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc73cfe46da4e2fd03918604b0a80dba92d678a7ab8101671b777855b31a16fc07c20469fa7a5d01b9acc179f07c99448467d58193193ee7088d92c105999d70
|
7
|
+
data.tar.gz: 470ed0d894f193ea64e63cb2bea0a06949769080712a91454470315cceae74d9172f5fe3944daf4ac4186de563b05ac4acdc78f556d1f74baba7ec41314ee38e
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
local_model (0.1.
|
4
|
+
local_model (0.1.12)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -31,6 +31,7 @@ GEM
|
|
31
31
|
diff-lcs (>= 1.2.0, < 2.0)
|
32
32
|
rspec-support (~> 3.10.0)
|
33
33
|
rspec-support (3.10.2)
|
34
|
+
thor (1.2.1)
|
34
35
|
|
35
36
|
PLATFORMS
|
36
37
|
x86_64-linux
|
@@ -42,6 +43,7 @@ DEPENDENCIES
|
|
42
43
|
pry (~> 0.14.1)
|
43
44
|
rake (~> 13.0)
|
44
45
|
rspec (~> 3.10)
|
46
|
+
thor (~> 1.2)
|
45
47
|
|
46
48
|
BUNDLED WITH
|
47
|
-
2.
|
49
|
+
2.3.14
|
data/Rakefile
CHANGED
@@ -5,9 +5,12 @@ RSpec::Core::RakeTask.new(:spec)
|
|
5
5
|
|
6
6
|
task :default => :spec
|
7
7
|
|
8
|
-
desc "
|
9
|
-
task :
|
10
|
-
require 'pry'
|
8
|
+
desc "environment"
|
9
|
+
task :environment do
|
11
10
|
require_relative './lib/local_model.rb'
|
12
|
-
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "run file generator"
|
14
|
+
task :generate => :environment do
|
15
|
+
LocalModel::Generator.new.invoke_all
|
13
16
|
end
|
data/bin/local_model
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'thor/group'
|
3
|
+
|
4
|
+
module LocalModel
|
5
|
+
module Generators
|
6
|
+
class Initialize < Thor::Group
|
7
|
+
include Thor::Actions
|
8
|
+
|
9
|
+
class_option :namespace, default: "InMemory"
|
10
|
+
|
11
|
+
desc 'Create required files'
|
12
|
+
|
13
|
+
def self.source_root
|
14
|
+
File.dirname(__FILE__) + '/../'
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_initializer
|
18
|
+
@namespace_classname = options[:namespace]
|
19
|
+
template('templates/initializer.erb', 'config/initializers/local_model.rb')
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_data_accessor
|
23
|
+
template('templates/data_accessor.erb', 'lib/data_accessor.rb')
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_model_generator
|
27
|
+
@class_namespace_snake = LocalModel::Functions.camel_to_snake(@namespace_classname)
|
28
|
+
template('templates/generate_model.erb', 'lib/tasks/local_model.rake')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module DataAccessor
|
2
|
+
class Base
|
3
|
+
class Accessors
|
4
|
+
LOCAL = :local
|
5
|
+
ACTIVE_RECORD = :active_record
|
6
|
+
|
7
|
+
NAMESPACES = {
|
8
|
+
LOCAL => <%= @namespace_classname %>,
|
9
|
+
ACTIVE_RECORD => Object
|
10
|
+
}
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
@@strategy = ENV["USE_LOCAL_MODELS"] ? Accessors::LOCAL : Accessors::ACTIVE_RECORD
|
15
|
+
@@exceptions = Set.new([])
|
16
|
+
|
17
|
+
def self.set_strategy(strat)
|
18
|
+
if strat.to_sym == :local
|
19
|
+
@@strategy = Accessors::LOCAL
|
20
|
+
else
|
21
|
+
@@strategy = Accessors::ACTIVE_RECORD
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.klass(klass_name)
|
26
|
+
namespace = get_namespace_for(klass_name)
|
27
|
+
namespaced_klass_name = "#{namespace}::#{klass_name.to_s}"
|
28
|
+
namespaced_klass = Object.const_get(namespaced_klass_name)
|
29
|
+
end
|
30
|
+
private_class_method :klass
|
31
|
+
|
32
|
+
def self.get_namespace
|
33
|
+
Accessors::NAMESPACES[@@strategy]
|
34
|
+
end
|
35
|
+
private_class_method :get_namespace
|
36
|
+
|
37
|
+
def self.get_namespace_for(klass)
|
38
|
+
exception_strategy = @@strategy == Accessors::ACTIVE_RECORD ? Accessors::LOCAL : Accessors::ACTIVE_RECORD
|
39
|
+
exception_namespace = Accessors::NAMESPACES[exception_strategy]
|
40
|
+
if @@exceptions.include?(klass.to_s.to_sym)
|
41
|
+
exception_namespace
|
42
|
+
else
|
43
|
+
get_namespace
|
44
|
+
end
|
45
|
+
end
|
46
|
+
private_class_method :get_namespace_for
|
47
|
+
|
48
|
+
def self.set_exceptions(exceptions)
|
49
|
+
@@exceptions = Set.new(exceptions.map(&:to_sym))
|
50
|
+
end
|
51
|
+
|
52
|
+
# Example - find user
|
53
|
+
# def self.find_user(id)
|
54
|
+
# ref = klass(:User)
|
55
|
+
# ref.find(id)
|
56
|
+
# end
|
57
|
+
# private_class_method :find_user
|
58
|
+
|
59
|
+
# MARK: PUBLIC GETTERS
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
namespace :local_model do
|
3
|
+
|
4
|
+
desc "Generate LocalModel model"
|
5
|
+
task :create_model, [:klass_name] => :environment do |_t, args|
|
6
|
+
klass_name = args[:klass_name]
|
7
|
+
model_code = <<~RUBY
|
8
|
+
class <%= @namespace_classname %>::#{klass_name} < LocalModel::CSV
|
9
|
+
schema do |t|
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
RUBY
|
14
|
+
|
15
|
+
dir = Rails.root.join('lib', '<%= @class_namespace_snake%>')
|
16
|
+
Dir.mkdir(dir) unless File.exists?(dir)
|
17
|
+
filename = "#{dir}/#{klass_name.underscore}.rb"
|
18
|
+
File.open(filename, 'w') { |f| f.write(model_code) }
|
19
|
+
end
|
20
|
+
end
|
data/lib/local_model/version.rb
CHANGED
data/lib/local_model.rb
CHANGED
@@ -14,6 +14,7 @@ require_relative './local_model/helpers/functions'
|
|
14
14
|
require_relative './local_model/helpers/pluralized_words'
|
15
15
|
require_relative './local_model/model'
|
16
16
|
require_relative './local_model/csv'
|
17
|
+
require_relative './local_model/generators/initialize'
|
17
18
|
|
18
19
|
module LocalModel
|
19
20
|
class Error < StandardError; end
|
data/local_model.gemspec
CHANGED
@@ -30,8 +30,11 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
31
31
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
32
32
|
end
|
33
|
-
spec.bindir = "exe"
|
34
|
-
spec.
|
33
|
+
# spec.bindir = "exe"
|
34
|
+
spec.bindir = "bin"
|
35
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
36
|
+
spec.executables << 'local_model'
|
37
|
+
# spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
35
38
|
spec.require_paths = ["lib"]
|
36
39
|
|
37
40
|
spec.add_development_dependency "bundler", "~> 2.2"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: local_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Micah Shute
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
11
|
+
date: 2022-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,7 +56,10 @@ description: This is meant to help facilitate an API-first strategy when creatin
|
|
56
56
|
web apps with RoR
|
57
57
|
email:
|
58
58
|
- micah.shute@gmail.com
|
59
|
-
executables:
|
59
|
+
executables:
|
60
|
+
- console
|
61
|
+
- local_model
|
62
|
+
- setup
|
60
63
|
extensions: []
|
61
64
|
extra_rdoc_files: []
|
62
65
|
files:
|
@@ -70,6 +73,7 @@ files:
|
|
70
73
|
- README.md
|
71
74
|
- Rakefile
|
72
75
|
- bin/console
|
76
|
+
- bin/local_model
|
73
77
|
- bin/setup
|
74
78
|
- lib/local_model.rb
|
75
79
|
- lib/local_model/adapters/boolean_adapter.rb
|
@@ -82,10 +86,14 @@ files:
|
|
82
86
|
- lib/local_model/csv.rb
|
83
87
|
- lib/local_model/errors/record_invalid.rb
|
84
88
|
- lib/local_model/errors/record_not_found.rb
|
89
|
+
- lib/local_model/generators/initialize.rb
|
85
90
|
- lib/local_model/helpers/functions.rb
|
86
91
|
- lib/local_model/helpers/pluralized_words.rb
|
87
92
|
- lib/local_model/model.rb
|
88
93
|
- lib/local_model/sandbox.rb
|
94
|
+
- lib/local_model/templates/data_accessor.erb
|
95
|
+
- lib/local_model/templates/generate_model.erb
|
96
|
+
- lib/local_model/templates/initializer.erb
|
89
97
|
- lib/local_model/version.rb
|
90
98
|
- local_model.gemspec
|
91
99
|
homepage: https://github.com/micahshute/local_model
|