arbitrium 0.2.1 → 1.0.0

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: f6eb17eeec355a479c42cc6163894e9cbcbe18e1
4
- data.tar.gz: 8f6d89419ef27bc67f729dd187a02cac9b2e603c
3
+ metadata.gz: 07f0370650dc517751f82305b914467deff9dd8b
4
+ data.tar.gz: 0c5b7f18c64daac63bea6b4f9e9290d4232883b2
5
5
  SHA512:
6
- metadata.gz: 4d5f50cf476ae0ca6a29050de60e0eebb77e785de092007fb8b61d69c661dae88307c1340f83fbb7d346b7e5e010a4428cbb04a91366fdde4ac79776891714a2
7
- data.tar.gz: 35617595350d81bd11b1ca0ed2bcb9e6d5627dac253a5929038e4e57d44bbf0288a24278980fe66ee61f0793bb83dbd51c469e43390cb5465d0c38af60c9e1f6
6
+ metadata.gz: faaba03ff8431e0cac29ee717b6a14ba8fe2fc8cc1ea6fe86b599f422ad737f6bef758915f6528427f9cf4e1526ee1469cfefa0529d7e19e3728bcddb53558f7
7
+ data.tar.gz: 3c1f2352b07960d6276485faecca4cc43f7c4005a9d330adcef3a5ff7f2c62aa3b7fd9863a7b627985a721497b8d748b4b40249b294d42e1c5b3848021e308c7
data/README.md CHANGED
@@ -19,14 +19,62 @@ Or install it yourself as:
19
19
  $ gem install arbitrium
20
20
 
21
21
  ## Usage
22
+ #### There are two different uses for this gem.
23
+ ##### Command Line File/Class Creator
22
24
 
23
- To use this gem simply call Arbitrium::Result.new and pass in a boolean whether the build failed or not, a corresponding message, and then the optional object.
25
+ Once you have the gem installed type `bundle exec arbitrium -h` to see the different options.
24
26
 
25
- ## Development
27
+ Example Usage:
28
+ ```
29
+ bundle exec arbitrium -f place/where/I/want/file.rb -m run -a Fake,Name
30
+ # Results in the following file being created: [link.to.file]
31
+ bundle exec arbitrium -f place/where/I/want/file.rb
32
+ # Results in the following file being created: [link.to.file]
33
+ ```
34
+
35
+ When using the command line generator make sure that you are always using the path from your current position in the file structure.
36
+
37
+ ##### Using Arbitrium::Result
38
+ In your method that they want to have the Result object call `Arbitrium::Result.new()` and pass in your arguments.
39
+
40
+ Important things to note:
41
+ 1. You must pass at least two arguments
42
+ 2. The first argument must be a boolean type
43
+ 3. The second argument must be a string type
44
+ Any deviation from data types will result in an error being raised.
45
+
46
+ What a successful result may look like:
47
+ ```
48
+ result = Arbitrium::Result.new(user.save, user.errors.messages.join(', '), user)
49
+
50
+ result.successful? # true
51
+ result.failed? # false
52
+ result.message # ''
53
+ result.object # User object
26
54
 
27
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
55
+ # You can also call the class method default_success which takes an optional object
56
+ result = Arbitrium::Result.default_success(OptionalObject)
28
57
 
29
- 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+ result.successful? # true
59
+ result.message # 'Completed Succesfully.'
60
+ result.object # OptionalObject
61
+ ```
62
+
63
+ What a failed result may look like:
64
+ ```
65
+ result = Arbitrium::Result.new(false, 'Failed to successfully do my job')
66
+
67
+ result.successful? # false
68
+ result.message # Failed to successfully do my job
69
+ result.object # nil
70
+
71
+ # You can also call the class method default_failure which takes an optional object
72
+ result = Arbitrium::Result.default_success
73
+
74
+ result.failed? # true
75
+ result.message # 'Failed to complete.'
76
+ result.object # nil
77
+ ```
30
78
 
31
79
  ## Contributing
32
80
 
@@ -16,8 +16,8 @@ Gem::Specification.new do |spec|
16
16
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
17
  f.match(%r{^(test|spec|features)/})
18
18
  end
19
- spec.bindir = "exe"
20
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.bindir = "bin"
20
+ spec.executables << 'arbitrium'
21
21
  spec.require_paths = ["lib"]
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.14"
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/arbitrium'
3
+ require_relative '../lib/arbitrium/file_creator'
4
+ require 'optparse'
5
+
6
+ options = { pwd: Dir.pwd, file: nil, method_name: 'perform', module_array: [] }
7
+
8
+ parser =
9
+ OptionParser.new do |opts|
10
+ opts.banner = "Usage: arbitrium [options]"
11
+ opts.on('-fMANDATORY', '--file=MANDATORY', 'File with path from current directory') { |file| options[:file] = file }
12
+ opts.on('-m', '--method=OPTIONAL', 'Name of actionable method') { |method| options[:method_name] = method }
13
+ opts.on('-a', '--module_array=OPTIONAL', 'Modules that the class is nested under seperated by a comma') { |module_array| options[:module_array] = module_array.split(',').map(&:strip) }
14
+ opts.on('-h', '--help') { puts opts; exit }
15
+ end
16
+
17
+ args = parser.order!(ARGV) {}
18
+ parser.parse!(args)
19
+
20
+ Arbitrium::FileCreator.perform(options)
@@ -3,12 +3,5 @@
3
3
  require "bundler/setup"
4
4
  require "arbitrium"
5
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
6
  require "irb"
14
7
  IRB.start(__FILE__)
data/bin/setup CHANGED
@@ -4,5 +4,3 @@ IFS=$'\n\t'
4
4
  set -vx
5
5
 
6
6
  bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,4 +1,7 @@
1
- Dir[File.dirname(__FILE__) + '/lib/*.rb'].each { |file| require file }
1
+ require_relative 'arbitrium/result'
2
+ require_relative 'arbitrium/version'
3
+ require_relative 'arbitrium/file_creator'
4
+
2
5
 
3
6
  module Arbitrium
4
7
  end
@@ -0,0 +1,92 @@
1
+ module Arbitrium
2
+ class FileCreator
3
+ attr_reader :file_with_path, :method_name, :pwd, :module_array
4
+
5
+ def self.perform(options)
6
+ new(options).perform
7
+ end
8
+
9
+ options = { pwd: Dir.pwd, file: nil, method_name: 'perform', module_array: [] }
10
+
11
+
12
+ def initialize(options)
13
+ puts options
14
+ @file_with_path = options[:file]
15
+ @method_name = options[:method_name]
16
+ @pwd = options[:pwd]
17
+ @module_array = options[:module_array]
18
+ end
19
+
20
+ def perform
21
+ puts module_array
22
+ puts create_file ? "Successfully created file in #{full_path_with_file}" : "Failed to create file!"
23
+ end
24
+
25
+ private
26
+
27
+ def create_file
28
+ File.open(full_path_with_file, 'w') do |file|
29
+ file.write(<<~EOF
30
+ #{file_header}
31
+ #{add_spaces} def self.#{method_name}()
32
+ #{add_spaces} new().#{method_name}
33
+ #{add_spaces} end
34
+
35
+ #{add_spaces} def initialize()
36
+ #{add_spaces} # insert instance variables here
37
+ #{add_spaces} end
38
+
39
+ #{add_spaces} def #{method_name}
40
+ #{add_spaces} # define tasks needed to complete here
41
+ #{add_spaces} # next, define result of tasks
42
+ #{add_spaces} Arbitrium::Result.new()
43
+ #{add_spaces} end
44
+
45
+ #{add_spaces} private
46
+ #{add_spaces} # define methods from perform here
47
+ #{file_footer}
48
+ end
49
+ EOF
50
+ )
51
+ end
52
+ end
53
+
54
+ def full_path_with_file
55
+ pwd + modified_file_with_path
56
+ end
57
+
58
+ def modified_file_with_path
59
+ return if file_with_path[0] == '/'
60
+
61
+ '/' + file_with_path
62
+ end
63
+
64
+ def file_header
65
+ "#{module_header}\n#{class_header}"
66
+ end
67
+
68
+ def module_header
69
+ module_array.map.with_index { |module_name, i| "#{add_spaces(i)}module #{module_name}" }.join("\n")
70
+ end
71
+
72
+ def class_header
73
+ module_array.empty? ? "class #{class_name}" : "\n#{add_spaces(module_array.length)} class #{class_name}"
74
+ end
75
+
76
+ def add_spaces(value = module_array.length)
77
+ ' ' * value
78
+ end
79
+
80
+ def class_name
81
+ class_portion_of_path.split('_').map(&:capitalize).join('')
82
+ end
83
+
84
+ def class_portion_of_path
85
+ file_with_path[0...file_with_path.length-3].match(/([^\/]+)$/)[0]
86
+ end
87
+
88
+ def file_footer
89
+ module_array.map.with_index { |_, i| puts i; "#{add_spaces((module_array.length - i))}end" }.join("\n")
90
+ end
91
+ end
92
+ end
@@ -6,18 +6,42 @@ module Arbitrium
6
6
  new(true, 'Completed successfully.', object)
7
7
  end
8
8
 
9
+ def self.default_failure(object = nil)
10
+ new(false, 'Failed to complete.', object)
11
+ end
12
+
9
13
  def initialize(success, message, object = nil)
10
14
  @success = success
11
15
  @message = message
12
16
  @object = object
17
+
18
+ raise 'Error! Incorrect data types for arguments expected (boolean, string, object)!' unless valid?
13
19
  end
14
20
 
15
- def success?
21
+ def successful?
16
22
  self.success
17
23
  end
18
24
 
19
- def failure?
20
- !success?
25
+ def failed?
26
+ !successful?
27
+ end
28
+
29
+ def valid?
30
+ check_validity
31
+ end
32
+
33
+ private
34
+
35
+ def check_validity
36
+ check_success_class && check_message_class
37
+ end
38
+
39
+ def check_success_class
40
+ success.is_a?(TrueClass) || success.is_a?(FalseClass)
41
+ end
42
+
43
+ def check_message_class
44
+ message.is_a?(String)
21
45
  end
22
46
  end
23
47
  end
@@ -1,3 +1,3 @@
1
1
  module Arbitrium
2
- VERSION = "0.2.1"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arbitrium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lollar
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-01 00:00:00.000000000 Z
11
+ date: 2017-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,7 +58,8 @@ description: This gem was inspired by the overabundance of logic that I continua
58
58
  in scope and will be modeled after the way that I like to write service object classes.
59
59
  email:
60
60
  - lollar.mchl@gmail.com
61
- executables: []
61
+ executables:
62
+ - arbitrium
62
63
  extensions: []
63
64
  extra_rdoc_files: []
64
65
  files:
@@ -69,9 +70,11 @@ files:
69
70
  - README.md
70
71
  - Rakefile
71
72
  - arbitrium.gemspec
73
+ - bin/arbitrium
72
74
  - bin/console
73
75
  - bin/setup
74
76
  - lib/arbitrium.rb
77
+ - lib/arbitrium/file_creator.rb
75
78
  - lib/arbitrium/result.rb
76
79
  - lib/arbitrium/version.rb
77
80
  homepage: https://github.com/lollar/arbitrium