venomi 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab55ad61fa60519fcc71df09779dec55261f432b
4
- data.tar.gz: 0a009dfba2c1202572d3f56c52c3c6bc7e192b3c
3
+ metadata.gz: ddfc04a06214a2d1493f1c0cd68959115f2b8e64
4
+ data.tar.gz: 3ae0fec69397ea89bf515707dd9c534a9eaf1404
5
5
  SHA512:
6
- metadata.gz: 62ca4a26053259c2193c2a08c524d944c6e43a858b22fd0cb72ceb3b14f06a1475ac247a863adcb7b1ba805f54566d0375a08b2d8f1a20bae3d5ddfc3e7796f7
7
- data.tar.gz: 5b971504da103e810dfb87902adbbdf4110541c12664728e078a0deaa8a3e607b1933b1fc987ab09401e5e51a5a049b5ce8824e3711411936c887264852eff80
6
+ metadata.gz: 1238996bb5132f1fa6a76df4a552381fa7df4b1fa6ba75f8cc23a885335457e6ea3580593a4db92b61d92744eb4400863afefda39cdb914f4d0580240988ca3f
7
+ data.tar.gz: bcea754bcf97742e0ce50896bd7683d5b2e3301cb26f9eabda23b8822088f912b44dbe08237c33574257033921532f7641d2c4088b67159554747ca7a9d308b4
data/README.md CHANGED
@@ -5,6 +5,7 @@ United I18n backend simple with mongoid provider and adds translation functional
5
5
  ## Dependency
6
6
 
7
7
  ```ruby
8
+ gem 'rails-i18n'
8
9
  gem 'mongoid'
9
10
  gem 'rails_admin'
10
11
  ```
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- Dir['lib/tasks/*.rake'].each { |rake| load rake }
1
+ Dir.glob('lib/tasks/*.rake').each {|rake| import rake}
2
2
 
3
3
  require "bundler/gem_tasks"
4
4
  require "rspec/core/rake_task"
@@ -0,0 +1,80 @@
1
+ require 'pathname'
2
+ require 'fileutils'
3
+ require 'tempfile'
4
+ include FileUtils
5
+
6
+ module Venomi
7
+ module Generators
8
+ module Utils
9
+ module InstanceMethods
10
+ @@gemfile_path = "#{Rails.root.to_s}/Gemfile"
11
+
12
+ def yes_no(question)
13
+ isValid = true
14
+ question += " [Y/N] "
15
+ while isValid
16
+ answer = ask(question, :yellow) do |yn|
17
+ yn.limit = 1, yn.validate = /[yn]/i
18
+ end
19
+ answer.downcase!
20
+ isValid = (answer == "y" or answer == "n")? false : true
21
+ end
22
+ answer
23
+ end
24
+
25
+ def library_available?(gem_name)
26
+ begin
27
+ require gem_name
28
+ return true
29
+ rescue LoadError
30
+ return false
31
+ end
32
+ end
33
+
34
+ def libraries_available?(*gems)
35
+ isAvailable = true
36
+ gems.each do |gem|
37
+ return false unless library_available?(gem)
38
+ end
39
+ isAvailable
40
+ end
41
+
42
+ def file?(path)
43
+ File.exist?(path)
44
+ end
45
+
46
+ def install_gem(gem_name, version = nil)
47
+ gem = "gem '" + gem_configurename + "'"
48
+ gem += ( ", '~> " + version +"'") if version
49
+
50
+ unless file_include?(@@gemfile_path, gem)
51
+ open(@@gemfile_path, 'a') { |f| f.puts gem }
52
+ end
53
+
54
+ system 'bundle install'
55
+ end
56
+
57
+ def replace(path, pattern, new_line)
58
+ t_file = Tempfile.new('temp.rb')
59
+ File.open(path, 'r') do |f|
60
+ f.each_line do |line|
61
+ t_file.puts (line.include? pattern)? new_line : line
62
+ end
63
+ end
64
+ t_file.close
65
+ FileUtils.mv(t_file.path, path)
66
+ end
67
+
68
+ def file_include?(path, include)
69
+ File.open(path, 'r') do |f|
70
+ f.each_line do |line|
71
+ return true if line.include? include
72
+ end
73
+ end
74
+ false
75
+ end
76
+
77
+ end
78
+ end
79
+ end
80
+ end
@@ -1,23 +1,31 @@
1
1
  require 'rails/generators/base'
2
2
  require 'venomi/rails_admin'
3
+ require 'generators/utils'
3
4
 
4
5
  module Venomi
5
6
  module Generators
6
7
  class InstallGenerator < Rails::Generators::Base
8
+ include Venomi::Generators::Utils::InstanceMethods
7
9
  source_root File.expand_path("../../templates", __FILE__)
8
10
 
9
- desc 'Venomi installation generator'
10
-
11
11
  def copy_initializer
12
- template "translation.rb", "app/models/translation.rb"
13
- template "locale.rb", "config/initializers/locale.rb"
14
- template "mongoid.rb", "lib/i18n/backend/mongoid.rb"
12
+ if libraries_available?("mongoid", "rails-i18n")
13
+ template "mongoid.rb", "lib/i18n/backend/mongoid.rb"
14
+ template "translation.rb", "app/models/translation.rb"
15
+ template "locale.rb", "config/initializers/locale.rb"
16
+ else
17
+ say("Mongoid or rails-i18n aren't installed!", :yellow)
18
+ end
15
19
  end
16
20
 
17
21
  def install
18
22
  case self.behavior
19
23
  when :invoke
20
- Venomi::RailsAdmin.configure
24
+ if libraries_available?("mongoid","rails_admin")
25
+ Venomi::RailsAdmin.configure
26
+ else
27
+ say("Rails-admin isn`t required or installed!", :yellow)
28
+ end
21
29
  when :revoke
22
30
  Venomi::RailsAdmin.rollback
23
31
  end
@@ -1,6 +1,7 @@
1
1
  require 'pathname'
2
2
  require 'fileutils'
3
3
  require 'tempfile'
4
+ require 'generators/utils'
4
5
  include FileUtils
5
6
 
6
7
  module Venomi
@@ -8,52 +9,41 @@ module Venomi
8
9
 
9
10
  if defined? ::Rails
10
11
  @rails_root = Rails.root.to_s
11
- @rails_admin_root = @rails_root + "/config/initializers/rails_admin.rb"
12
+ @rails_admin_root = "#{@rails_root}/config/initializers/rails_admin.rb"
12
13
  else
13
- @gem_root = Pathname.new File.expand_path('../../', __FILE__)
14
- @rails_admin_root = @gem_root.to_s + "/debug/initializers/rails_admin.rb"
14
+ # Debug
15
+ @gem_root = Pathname.new File.expand_path('../../', __FILE__).to_s
16
+ @rails_admin_root = "#{@gem_root}/debug/initializers/rails_admin.rb"
15
17
  end
16
18
 
17
- def self.configure
18
- unless file_include?(@rails_admin_root, "config.model Translation do")
19
- replace(@rails_admin_root, "RailsAdmin.config do |config|", ("RailsAdmin.config do |config|\n" + @translation))
20
- end
19
+ class << self
20
+ include Venomi::Generators::Utils::InstanceMethods
21
21
 
22
- unless file_include?(@rails_admin_root, " new do")
23
- replace(@rails_admin_root, " new", @new)
24
- end
22
+ def configure
23
+ if file?(@rails_admin_root)
24
+ unless file_include?(@rails_admin_root, "config.model Translation do")
25
+ replace(@rails_admin_root, "RailsAdmin.config do |config|", ("RailsAdmin.config do |config|\n" + @translation))
26
+ end
25
27
 
26
- unless file_include?(@rails_admin_root, " delete do")
27
- replace(@rails_admin_root, " delete", @delete)
28
- end
29
- end
28
+ unless file_include?(@rails_admin_root, " new do")
29
+ replace(@rails_admin_root, " new", @new)
30
+ end
30
31
 
31
- def self.rollback
32
- text = File.read(@rails_admin_root)
33
- text.gsub!(@delete, " delete\n")
34
- text.gsub!(@new, " new\n")
35
- text.gsub!(@translation, "")
36
- File.open(@rails_admin_root, "w") {|file| file.puts text }
37
- end
38
-
39
- def self.replace(path, pattern, new_line)
40
- t_file = Tempfile.new('temp.rb')
41
- File.open(path, 'r') do |f|
42
- f.each_line do |line|
43
- t_file.puts (line.include? pattern)? new_line : line
32
+ unless file_include?(@rails_admin_root, " delete do")
33
+ replace(@rails_admin_root, " delete", @delete)
34
+ end
44
35
  end
45
36
  end
46
- t_file.close
47
- FileUtils.mv(t_file.path, path)
48
- end
49
37
 
50
- def self.file_include?(path, include)
51
- File.open(path, 'r') do |f|
52
- f.each_line do |line|
53
- return true if line.include? include
38
+ def rollback
39
+ if file? @rails_admin_root
40
+ text = File.read(@rails_admin_root)
41
+ text.gsub!(@delete, " delete\n")
42
+ text.gsub!(@new, " new\n")
43
+ text.gsub!(@translation, "")
44
+ File.open(@rails_admin_root, "w") {|file| file.puts text }
54
45
  end
55
46
  end
56
- false
57
47
  end
58
48
 
59
49
  @new = <<-MSG
@@ -1,3 +1,3 @@
1
1
  module Venomi
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/venomi.gemspec CHANGED
@@ -20,6 +20,9 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency 'rspec', '~> 3.4.0'
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
-
23
+
24
24
  spec.add_dependency 'bundler', '~> 1.7'
25
+ spec.add_dependency 'rails_admin', '~> 1.0'
26
+ spec.add_dependency 'mongoid'
27
+ spec.add_dependency 'rails-i18n'
25
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: venomi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandr Turchyn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-28 00:00:00.000000000 Z
11
+ date: 2016-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -52,6 +52,48 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rails_admin
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mongoid
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rails-i18n
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
55
97
  description: United I18n backend simple with mongoid provider and adds translation
56
98
  functionality to Rails Admin.
57
99
  email:
@@ -65,7 +107,6 @@ files:
65
107
  - ".gitignore"
66
108
  - ".rspec"
67
109
  - ".travis.yml"
68
- - CODE_OF_CONDUCT.md
69
110
  - Gemfile
70
111
  - LICENSE.txt
71
112
  - README.md
@@ -76,6 +117,7 @@ files:
76
117
  - lib/generators/templates/locale.rb
77
118
  - lib/generators/templates/mongoid.rb
78
119
  - lib/generators/templates/translation.rb
120
+ - lib/generators/utils.rb
79
121
  - lib/generators/venomi/install_generator.rb
80
122
  - lib/tasks/venomi.rake
81
123
  - lib/venomi.rb
data/CODE_OF_CONDUCT.md DELETED
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at lexfox777@gmail.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/