yuba 0.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 065c02ba0b6ba7a96764c3557e3f3abad4e2252d
4
+ data.tar.gz: 13c440a52f8042fcd001d6d1305e233184c8aca2
5
+ SHA512:
6
+ metadata.gz: 107fbf7894edb031119725bd8f9844d78e52dbc3fc9f763cc0b60a244f50868b45949b2ffec47847e92a780598ee5af07e0a835adbcc15e339868ded43b275b8
7
+ data.tar.gz: c9494157393285ba6b41d231ef56338411c890b96711010278053d6fdb00d71a6f4626ff1b564c1ba6bcecfebb3ea89c14e1f943dbdf83d12298ba5dddb33a10
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 willnet
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Yuba
2
+
3
+ This gem is now under construction. It doesn't work now.
4
+
5
+ Yuba add new layers to rails.
6
+
7
+ - Service
8
+ - Form
9
+ - ViewModel
10
+
11
+ ## Usage
12
+
13
+ How to use my plugin.
14
+
15
+ ## Installation
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'yuba'
20
+ ```
21
+
22
+ And then execute:
23
+ ```bash
24
+ $ bundle
25
+ ```
26
+
27
+ Or install it yourself as:
28
+ ```bash
29
+ $ gem install yuba
30
+ ```
31
+
32
+ ## Contributing
33
+ Contribution directions go here.
34
+
35
+ ## License
36
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Yuba'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+
33
+ task default: :test
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :yuba do
3
+ # # Task goes here
4
+ # end
data/lib/yuba.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Yuba
2
+ autoload :Form, 'yuba/form'
3
+ autoload :Service, 'yuba/service'
4
+ autoload :ViewModel, 'yuba/view_model'
5
+ end
data/lib/yuba/form.rb ADDED
@@ -0,0 +1,60 @@
1
+ module Yuba
2
+ class Form
3
+ autoload :Attribute, 'yuba/form/attribute'
4
+ autoload :Attributes, 'yuba/form/attributes'
5
+ autoload :Collection, 'yuba/form/collection'
6
+
7
+ include ActiveModel::Model
8
+ class_attribute :_model_attribute
9
+ class_attribute :attributes
10
+
11
+ class << self
12
+ # TODO: reformのようにネストできるようにしたい
13
+ def attribute(name, type: 'string', &block)
14
+ mod = Module.new do
15
+ define_method(name) do
16
+ attributes[name.to_s]
17
+ end
18
+ define_method("#{name}=") do |value|
19
+ write_attribute(name.to_s, value, block)
20
+ end
21
+ end
22
+ include mod
23
+ end
24
+
25
+ def collection(name)
26
+ end
27
+
28
+ def model(name)
29
+ self._model_attribute = name
30
+ end
31
+
32
+ def build(**args)
33
+ new(**args)
34
+ end
35
+ end
36
+
37
+ def save
38
+ valid? && persist
39
+ end
40
+
41
+ def persist
42
+ end
43
+
44
+ def model
45
+ send(_model_attribute)
46
+ end
47
+
48
+ def model_name
49
+ model&.model_name
50
+ end
51
+
52
+ private
53
+
54
+ def write_attribute(name, value, block)
55
+ # TODO: convert value by type of attribute
56
+ value = Attributes.new(value, &block) if block
57
+ attributes[name] = value
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,9 @@
1
+ module Yuba
2
+ class Form
3
+ class Attribute
4
+ def initialize(name)
5
+ @name = name
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,44 @@
1
+ module Yuba
2
+ module Form
3
+ class Attributes
4
+ class_attribute :attributes
5
+ self.attributes = {}
6
+
7
+ def initialize(value)
8
+ yield if block_given?
9
+ deep_assign(value)
10
+ end
11
+
12
+ def attribute(name, type: string, &block)
13
+ mod = Module.new do
14
+ define_method(name) do
15
+ attributes[name.to_s]
16
+ end
17
+ define_method("#{name}=") do |value|
18
+ write_attribute(name.to_s, value, block)
19
+ end
20
+ end
21
+ include mod
22
+ end
23
+
24
+ private
25
+
26
+ def write_attribute(name, value, block)
27
+ # TODO: convert value by type of attribute
28
+ value = Attributes.new(value, &block) if block
29
+ attributes[name] = value
30
+ end
31
+
32
+ def deep_assign(value)
33
+ raise ArgumentError unless value.is_a? Hash
34
+ value.each do |k,v|
35
+ if v.is_a? Hash
36
+ deep_assign(v)
37
+ else
38
+ attributes[name.to_s] = v
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,37 @@
1
+ module Yuba
2
+ class Service
3
+ class << self
4
+ def call(**args)
5
+ service = new
6
+ return_value = args.present? ? service.call(**args) : service.call
7
+ if return_value.respond_to?(:success?)
8
+ return_value
9
+ else
10
+ result.success(form: service.form)
11
+ end
12
+ end
13
+ end
14
+
15
+ def build_form(**args)
16
+ form_class.build(**args)
17
+ end
18
+
19
+ def form_class
20
+ Object.const_get(form_class_name)
21
+ end
22
+
23
+ def view_model_class
24
+ Object.const_get(form_class_name)
25
+ end
26
+
27
+ private
28
+
29
+ def form_class_name
30
+ self.class.name.sub(/::.+Service/, 'Form')
31
+ end
32
+
33
+ def view_model_class_name
34
+ self.class.name.sub(/Service\z/, 'ViewModel')
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Yuba
2
+ VERSION = '0.0.1.pre'
3
+ end
@@ -0,0 +1,26 @@
1
+ module Yuba
2
+ class ViewModel
3
+ class << self
4
+ def success(**args)
5
+ new(args.merge(success: true))
6
+ end
7
+ end
8
+
9
+ def initialize(success: true, **args)
10
+ @success = success
11
+ args.each { |k,v| self.class.send(:define_method, k) { v } }
12
+ end
13
+
14
+ def success?
15
+ @success
16
+ end
17
+
18
+ def failure?
19
+ !@success
20
+ end
21
+
22
+ def to_model
23
+ form
24
+ end
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yuba
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre
5
+ platform: ruby
6
+ authors:
7
+ - willnet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Add New Layers to Rails. Form, Service, ViewModel.
42
+ email:
43
+ - netwillnet@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - lib/tasks/crepe_tasks.rake
52
+ - lib/yuba.rb
53
+ - lib/yuba/form.rb
54
+ - lib/yuba/form/attribute.rb
55
+ - lib/yuba/form/attributes.rb
56
+ - lib/yuba/service.rb
57
+ - lib/yuba/version.rb
58
+ - lib/yuba/view_model.rb
59
+ homepage: https://github.com/willnet/yuba
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">"
75
+ - !ruby/object:Gem::Version
76
+ version: 1.3.1
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.6.11
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Add New Layers to Rails
83
+ test_files: []