paramount 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3b8900d40c977a2d738b2cd638d105930ec990b8
4
+ data.tar.gz: ada9b75334455c3b4ff7ebc3a416f35113322c18
5
+ SHA512:
6
+ metadata.gz: 4b2232621a9012ac4c87a97baea6210d6a9b9fb9b452ab9f09c5e7fec68ef81546f7df843e9c53fc7c8fa83b7836a6cc9ecfd0565dae5fecc93bd29c08ea4844
7
+ data.tar.gz: 6224dfec9259268ea2e5fa4bd5807b1be25c541dc4b286324a6d21d9b2691446c9aef76dfbcd649569f115105240cc1fa60a341da6b2b9589578c017839a03eb
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in paramount.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Charles Sistovaris
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Paramount
2
+ Take controll of your params in a dedicated Form Object
3
+
4
+ ## Installation
5
+ Add the following line to your application's Gemfile & bundle it!
6
+
7
+ ```ruby
8
+ gem 'paramount'
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ $ bin/rails g paramount Book
14
+
15
+ This will create a new file in app/forms
16
+
17
+ ```ruby
18
+ class BookForm < Paramount::Model
19
+
20
+ attribute :title
21
+
22
+ def assign
23
+ model.attributes= attributes #.except(:notify_me, :author_name, :geolocate, :etc)
24
+ # assign_association
25
+ end
26
+
27
+ private
28
+ def assign_association
29
+ # (model.author || model.build_author).name = author_name
30
+ end
31
+ end
32
+ ```
33
+
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it ( https://github.com/charly/paramount/fork )
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,7 @@
1
+ class ParamountGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path("../templates", __FILE__)
3
+
4
+ def create_model_file
5
+ template "form.rb", File.join('app/forms', class_path, "#{file_name}_fomr.rb")
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ class <%= class_name %>Form < Paramount::Model
2
+
3
+ def self.model_name
4
+ ActiveModel::Name.new(self, nil, "<%= class_name %>")
5
+ end
6
+
7
+ <% class_name.constantize.new.attributes.except(:id, :created_at, :updated_at).each do |attr, val| %>
8
+ attribute :<%= attr -%>
9
+ <% end %>
10
+
11
+
12
+ private
13
+
14
+ def assign
15
+ model.attributes= attributes #.except(:notify_me, :author_name, :geolocate, :etc)
16
+ # assign_association
17
+ end
18
+
19
+ def assign_association
20
+ # (model.author || model.build_author).name = author_name
21
+ end
22
+
23
+
24
+ end
@@ -0,0 +1,5 @@
1
+ require "paramount/version"
2
+
3
+ module Paramount
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,49 @@
1
+ module Paramount
2
+ class Model
3
+ include ActiveModel::Model
4
+ include Virtus.model
5
+
6
+ attr_accessor :model
7
+
8
+ # def self.model_name
9
+ # raise "self.model_name needs to be defined"
10
+ # end
11
+
12
+ def self.model_class
13
+ @klass ||= model_name.name.constantize
14
+ end
15
+
16
+ # This 'factory' meant for show/edit takes no params and
17
+ # uses the model attributes to seed the virtus attributes
18
+ # usage in controller : BookParam.find(params[:id])
19
+ def self.find(id)
20
+ model = model_class.find(id)
21
+ new(model.attributes, model)
22
+ end
23
+
24
+ def initialize(params = nil, model = nil)
25
+ @model= model
26
+ params ||= model.attributes
27
+ super(params)
28
+ end
29
+
30
+ def id
31
+ model.id
32
+ end
33
+
34
+ def save
35
+ assign
36
+ model.save
37
+ end
38
+ alias update save
39
+
40
+ def submit
41
+ valid? ? persist! : false
42
+ end
43
+
44
+ def persisted?
45
+ model.new_record? ? false : true
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module Paramount
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'paramount/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "paramount"
8
+ spec.version = Paramount::VERSION
9
+ spec.authors = ["Charles Sistovaris"]
10
+ spec.email = ["charlysisto@gmail.com"]
11
+ spec.summary = %q{Mount your parameteres on a dedicated object.}
12
+ spec.description = %q{Mount your parameteres on a dedicated object to cerate & update your models and finally give power to the building parts of you controller}
13
+ spec.homepage = "https://github.com/charly/paramount"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "activesupport", "~> 4"
22
+ spec.add_dependency "virtus", "~> 1"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paramount
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Charles Sistovaris
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: virtus
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Mount your parameteres on a dedicated object to cerate & update your
70
+ models and finally give power to the building parts of you controller
71
+ email:
72
+ - charlysisto@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/generators/paramount_generator.rb
83
+ - lib/generators/templates/form.rb
84
+ - lib/paramount.rb
85
+ - lib/paramount/model.rb
86
+ - lib/paramount/version.rb
87
+ - paramount.gemspec
88
+ homepage: https://github.com/charly/paramount
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.4.3
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Mount your parameteres on a dedicated object.
112
+ test_files: []