morse_active_record_helpers 0.1.2

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: be0ea1e7f768c683381dc7ca3ccfe96a084ed13e
4
+ data.tar.gz: e42ed60c5ff6da04d753eced21221c4446a1e840
5
+ SHA512:
6
+ metadata.gz: 318dd3d45f803aef9004f2d8937f550f4723cd3525eeff501437e498b80d200318b6dae31579d4ffdd4ef128e0711e8f2f0889415ddf3044141240cd8901bf59
7
+ data.tar.gz: fdb27a50d9267333e983c2792215f38cb6b19e371be31a958faf1e243fc74876255c5e81faa4768174bbb25e35cd5ac3a46ba9dd2d1e8b0856b0df07606dd88b
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in morse_active_record_helpers.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,17 @@
1
+ guard :rspec, cmd: "bundle exec rspec" do
2
+ require "guard/rspec/dsl"
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ # Feel free to open issues for suggestions and improvements
6
+
7
+ # RSpec files
8
+ rspec = dsl.rspec
9
+ watch(rspec.spec_helper) { rspec.spec_dir }
10
+ watch(rspec.spec_support) { rspec.spec_dir }
11
+ watch(rspec.spec_files)
12
+
13
+ # Ruby files
14
+ ruby = dsl.ruby
15
+ dsl.watch_spec_files_for(ruby.lib_files)
16
+
17
+ end
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # MorseActiveRecordHelpers
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/morse_active_record_helpers`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'morse_active_record_helpers'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install morse_active_record_helpers
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/morse_active_record_helpers/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "morse_active_record_helpers"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module MorseActiveRecordHelpers
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,95 @@
1
+ require "morse_active_record_helpers/version"
2
+
3
+ module MorseActiveRecordHelpers
4
+
5
+ def associated_object_exists(klass,fn,required=true)
6
+ id=self.send(fn)
7
+ id_setter=(fn.to_s+'=').to_sym
8
+ unless klass.find_by_id(id)
9
+ self.send(id_setter,nil)
10
+ id=nil
11
+ end
12
+ if required==true and id.nil?
13
+ errors.add(fn,"does not exist")
14
+ return false
15
+ end
16
+ end
17
+
18
+ def blank_to_nil(thing)
19
+ if self.send(thing).blank?
20
+ self.send(thing.to_s+'=',nil)
21
+ end
22
+ end
23
+
24
+ def process_attachment(options={})
25
+ options={:model_name=>:asset, :uploader_name=>:attachment}.merge(options)
26
+ model_name=options[:model_name]
27
+ uploader_name=options[:uploader_name]
28
+ klass=eval(model_name.to_s.camelize)
29
+ if self.send(uploader_name)
30
+ a=klass.new(uploader_name=>self.send(uploader_name))
31
+ if a.save
32
+ self.send(model_name,a)
33
+ self.send(uploader_name,nil)
34
+ save
35
+ else
36
+ errors.add(uploader_name,'had a problem saving')
37
+ end
38
+ end
39
+ if klass.find_by_id(self.id)
40
+ self.reload
41
+ end
42
+ end
43
+
44
+ def survive_if(thing)
45
+ if self.send(thing)==true
46
+ errors.add(:base,"Cannot destroy while #{thing} is true")
47
+ false
48
+ elsif self.send(thing).is_a?(Array) and self.send(thing).any?
49
+ errors.add(:base,"Cannot destroy while #{thing} has members")
50
+ false
51
+ end
52
+ end
53
+
54
+ def correct_chronological_order(start, finish)
55
+ if self.send(start) && self.send(finish)
56
+ if self.send(start) > self.send(finish)
57
+ errors.add(:base,"#{finish} can not be before #{start}")
58
+ return false
59
+ end
60
+ end
61
+ end
62
+
63
+ def there_can_be_only_one(thing)
64
+ if new_record?
65
+ enemies=self.class.where("#{thing} = ?",true)
66
+ else
67
+ enemies=self.class.where("#{thing} = ? and id != ? ",true,id)
68
+ end
69
+ if enemies.any?
70
+ enemies.each do |e|
71
+ e.default_land=false
72
+ e.save
73
+ end
74
+ end
75
+ end
76
+
77
+ def there_must_be_one(thing)
78
+ existing=self.class.where("#{thing} = ?",true)
79
+ if existing.empty?
80
+ self.send("#{thing}=",true)
81
+ end
82
+ end
83
+
84
+ def validate_integer_or_default(thing,default)
85
+ unless self.send(thing)
86
+ self.send("#{thing}=",default)
87
+ end
88
+ end
89
+
90
+ def validate_mandatory_boolean(thing,message="must be true")
91
+ unless self.send(thing)==true
92
+ errors.add(thing,message)
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'morse_active_record_helpers/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "morse_active_record_helpers"
8
+ spec.version = MorseActiveRecordHelpers::VERSION
9
+ spec.authors = ["Terry S"]
10
+ spec.email = ["itsterry@gmail.com"]
11
+
12
+ if spec.respond_to?(:metadata)
13
+ #spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
14
+ end
15
+
16
+ spec.summary = "Module to provide some nice helpers for Active Record Models"
17
+ spec.homepage = "https://github.com/morsedigital/morse_active_record_helpers"
18
+ spec.license = "MIT"
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.8"
25
+ spec.add_development_dependency "coveralls", "~> 0.8"
26
+ spec.add_development_dependency "guard-rspec", "~> 4.5"
27
+ spec.add_development_dependency "rb-fsevent", "~> 0.9"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.2"
30
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: morse_active_record_helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Terry S
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rb-fsevent
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.2'
97
+ description:
98
+ email:
99
+ - itsterry@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - Guardfile
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - lib/morse_active_record_helpers.rb
114
+ - lib/morse_active_record_helpers/version.rb
115
+ - morse_active_record_helpers-0.1.0.gem
116
+ - morse_active_record_helpers.gemspec
117
+ homepage: https://github.com/morsedigital/morse_active_record_helpers
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.4.8
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Module to provide some nice helpers for Active Record Models
141
+ test_files: []