parlour-datamapper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9362701728a52bfa5104ee2775038bb0dfb199ec9dc387a960039b71b9557e0e
4
+ data.tar.gz: 566e265169a2907668851578165dd038e886263d675c073c259316bf2e725f14
5
+ SHA512:
6
+ metadata.gz: 942cf668b5e20c9acf219aaadf9877d214a9175923849bbc46825d73097ee4f39ae52c989c55ad448efd24c1c94c14669d12c3502f9a51260adeec2b9f6359fc
7
+ data.tar.gz: aec598d94860a522d6555f758969153e734c41b0c8f999e7a62a3ed0e57dee856648d25c6d36201e5848ec9b6c414640a5d2fe89c1e35d1621e37310bcb396d7
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ Gemfile.lock
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in parlour-datamapper.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Aaron Christiansen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ # parlour-datamapper
2
+ A simple Parlour extension to generate types for DataMapper keys. (Associations
3
+ are currently not supported.)
4
+
5
+ ## Usage
6
+ Ensure you've required this gem and loaded the program code which defines your
7
+ DataMapper models in your `.parlour` file, then add the `ParlourDataMapper`
8
+ plugin to `plugins`. This plugin takes no configuration.
9
+
10
+ An example `.parlour`:
11
+
12
+ ```yaml
13
+ output_file: out.rbi
14
+
15
+ requires:
16
+ - parlour-datamapper
17
+
18
+ relative_requires:
19
+ - src/main.rb # load models
20
+
21
+ plugins:
22
+ ParlourDataMapper: {}
23
+ ```
@@ -0,0 +1,55 @@
1
+ require 'parlour'
2
+ require 'data_mapper'
3
+
4
+ class ParlourDataMapper < Parlour::Plugin
5
+ VERSION = '0.1.0'
6
+
7
+ def generate(root)
8
+ # Get all resources
9
+ resources = ObjectSpace.each_object(Class).select do |x|
10
+ x.included_modules.include?(DataMapper::Resource)
11
+ end
12
+
13
+ # Generate namespaces for each
14
+ resources.each do |resource|
15
+ root.path(resource) do |klass|
16
+ # Iterate over each object property for this resource
17
+ resource.properties.each do |prop|
18
+ type_string = PROPERTIES_TO_TYPES[prop.class]
19
+
20
+ # Define the getter
21
+ klass.create_method(
22
+ name: prop.name.to_s,
23
+ returns: type_string
24
+ )
25
+
26
+ # Define the setter
27
+ klass.create_method(
28
+ name: "#{prop.name}=",
29
+ parameters: [
30
+ Parlour::RbiGenerator::Parameter.new(
31
+ name: 'value',
32
+ type: type_string
33
+ )
34
+ ],
35
+ returns: type_string
36
+ )
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ PROPERTIES_TO_TYPES = {
43
+ DataMapper::Property::String => 'String',
44
+ DataMapper::Property::Text => 'String',
45
+ DataMapper::Property::Integer => 'Integer',
46
+ DataMapper::Property::Decimal => 'Float',
47
+ DataMapper::Property::Float => 'Float',
48
+ DataMapper::Property::Numeric => 'Numeric',
49
+ DataMapper::Property::Boolean => 'T::Boolean',
50
+ DataMapper::Property::Date => 'Date',
51
+ DataMapper::Property::DateTime => 'DateTime',
52
+ DataMapper::Property::Time => 'Time',
53
+ DataMapper::Property::Serial => 'Integer'
54
+ }
55
+ end
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require_relative "lib/parlour-datamapper"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "parlour-datamapper"
7
+ spec.version = ParlourDataMapper::VERSION
8
+ spec.authors = ["Aaron Christiansen"]
9
+ spec.email = ["aaronc20000@gmail.com"]
10
+
11
+ spec.summary = "Parlour plugin for generating types for data_mapper"
12
+ spec.homepage = "https://github.com/AaronC81/parlour-datamapper"
13
+ spec.license = "MIT"
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "parlour", "~> 0.5.1"
25
+
26
+ spec.add_development_dependency "bundler", "~> 2.0"
27
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: parlour-datamapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Christiansen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-07-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: parlour
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ description:
42
+ email:
43
+ - aaronc20000@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - lib/parlour-datamapper.rb
53
+ - parlour-datamapper.gemspec
54
+ homepage: https://github.com/AaronC81/parlour-datamapper
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubygems_version: 3.0.2
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Parlour plugin for generating types for data_mapper
77
+ test_files: []