fedux_org-stdlib 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fedux_org-stdlib.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Max Meyer
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # FeduxOrg::Stdlib
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fedux_org-stdlib'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fedux_org-stdlib
18
+
19
+ ## Usage
20
+
21
+ You need to require the files... More is comming.
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fedux_org/stdlib/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fedux_org-stdlib"
8
+ spec.version = FeduxOrg::Stdlib::VERSION
9
+ spec.authors = ["Max Meyer"]
10
+ spec.email = ["dev@fedux.org"]
11
+ spec.description = %q{collection of use full libraries}
12
+ spec.summary = %q{collection of use full libraries}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,117 @@
1
+ module FeduxOrg
2
+ module Stdlib
3
+ module Models
4
+ class BaseModel
5
+
6
+ include Comparable
7
+
8
+ @instances = ::Set.new
9
+
10
+ attr_reader :name
11
+
12
+ def self.inherited(base)
13
+ base.instance_variable_set(:@instances, Set.new)
14
+ end
15
+
16
+ def initialize(name)
17
+ @name = name.to_sym
18
+ @enabled = false
19
+ end
20
+
21
+ #enable action
22
+ def enable
23
+ @enabled = true
24
+ end
25
+
26
+ #check if action is enabled
27
+ def enabled?(val=true)
28
+ @enabled == val
29
+ end
30
+
31
+ def name?(name)
32
+ @name == name
33
+ end
34
+
35
+ def <=>(other)
36
+ name <=> other.name
37
+ end
38
+
39
+ def eql?(other)
40
+ name == other.name
41
+ end
42
+
43
+ class << self
44
+ #attr_accessor :instances
45
+
46
+ def register(element)
47
+ @instances << element
48
+
49
+ element
50
+ end
51
+
52
+ def create( *args, &block )
53
+ if block_given?
54
+ register( new( *args, &block ) )
55
+ else
56
+ register( new( *args ) )
57
+ end
58
+ end
59
+
60
+ def find( val )
61
+ @instances.find { |i| i.name == val.to_s.to_sym }
62
+ end
63
+
64
+ def delete( val )
65
+ element = find( val.to_s.to_sym )
66
+ raise Exceptions::InstanceNotFound unless element
67
+ @instances.delete element
68
+
69
+ element
70
+ end
71
+
72
+ def clear
73
+ @instances = Set.new
74
+ end
75
+
76
+ def all
77
+ @instances.to_a
78
+ end
79
+
80
+ #return all names as string
81
+ def all_names_as_string(connector=", ")
82
+ find_all(enabled: true).map(&:name).sort.join(connector)
83
+ end
84
+
85
+ #enables a specific instance
86
+ def enable(name)
87
+ find(name: name).enable
88
+ end
89
+
90
+ #finds a single instance
91
+ def find( criteria={} )
92
+ find_all( criteria ).first
93
+ end
94
+
95
+ #finds all instances
96
+ def find_all( criteria={} )
97
+ PuppetGenerator::Models.logger.debug(self) { "Criteria for search: #{ criteria }" }
98
+ criteria = { name: criteria.to_sym } if criteria.kind_of? Symbol or criteria.kind_of? String
99
+
100
+ PuppetGenerator::Models.logger.debug(self) { "Instances to be searched for: #{ @instances.map { |i| "#{i.name} (#{i.class})" }.join(", ") }" }
101
+ @instances.find_all do |i|
102
+ criteria.all? do |c,v|
103
+
104
+ PuppetGenerator::Models.logger.debug(self) { "Check method for search: #{ c }" }
105
+ i.send( "#{c}?".to_sym , v )
106
+ end
107
+ end
108
+
109
+ rescue NameError => e
110
+ raise Exceptions::InvalidSearchCriteria, e.message
111
+ end
112
+ end
113
+
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,58 @@
1
+ module FeduxOrg
2
+ module Stdlib
3
+ module Models
4
+ # model for import action
5
+ module ClassBasedModel
6
+
7
+ def self.included(base)
8
+ base.extend ClassMethods
9
+ end
10
+
11
+ module ClassMethods
12
+
13
+ def require_path(name)
14
+ File.join( PuppetGenerator.gem_load_path, model_name.pluralize.underscore , name.to_s )
15
+ end
16
+
17
+ def exception_for_model
18
+ "PuppetGenerator::Exceptions::Invalid#{model_name.singularize}".constantize
19
+ rescue
20
+ raise Exceptions::ExceptionNeedsToBeImplemented, "Exception \"Exceptions::Invalid#{model_name}\" does not exist."
21
+ end
22
+
23
+ def check_klass( klass , method)
24
+ raise exception_for_model, "A valid \"#{model_name}\"-class needs to respond to \"#{ method }\"." unless klass.new.respond_to? method
25
+ end
26
+
27
+ def build_class_constant(name)
28
+ "PuppetGenerator::#{model_name.pluralize}::#{name.to_s.camelcase}".constantize
29
+ rescue
30
+ raise exception_for_model , "The filename needs to be snakecase and needs to be convertible to the action class name: filename in camelcase."
31
+ end
32
+
33
+ def check_method
34
+ raise Exceptions::MethodNeedsToBeImplemented, "Method \"check_method\" does not exist."
35
+ end
36
+
37
+ def suffix
38
+ '.rb'
39
+ end
40
+
41
+ def load_from_filesystem
42
+ files = Dir.glob( path_to_instances )
43
+
44
+ files.each do |f|
45
+ instance_name = name( f )
46
+
47
+ require require_path( instance_name )
48
+
49
+ instance_klass = build_class_constant( instance_name )
50
+ check_klass( instance_klass, check_method )
51
+ create( instance_name , instance_klass.new )
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,65 @@
1
+ module FeduxOrg
2
+ module Stdlib
3
+ module Models
4
+ # model for import action
5
+ module FilesystemBasedModel
6
+
7
+ def self.included(base)
8
+ base.extend ClassMethods
9
+ end
10
+
11
+ module ClassMethods
12
+
13
+ #initialize model
14
+ def init
15
+ load_from_filesystem
16
+ end
17
+
18
+ private
19
+
20
+ def module_name
21
+ name = fqcn
22
+ name.pop
23
+
24
+ name.join('::')
25
+ end
26
+
27
+ def fqcn
28
+ self.to_s.split(/::/)
29
+ end
30
+
31
+ def model_name
32
+ fqcn.last
33
+ end
34
+
35
+ def suffix
36
+ raise Exceptions::MethodNeedsToBeImplemented
37
+ end
38
+
39
+ def path_to_instances
40
+ path = File.expand_path("../../#{model_name.pluralize.underscore}", __FILE__ )
41
+
42
+ File.join(path,"*#{suffix}")
43
+ end
44
+
45
+ def name(path)
46
+ name = File.basename(path, suffix ).to_sym
47
+ raise Exceptions::UnauthorizedUseOfKeyword if forbidden_keywords.include? name
48
+
49
+ name
50
+ end
51
+
52
+ def load_from_filesystem
53
+ raise Exceptions::MethodNeedsToBeImplemented
54
+ end
55
+
56
+ def forbidden_keywords
57
+ [ ]
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,5 @@
1
+ module FeduxOrg
2
+ module Stdlib
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ require "fedux_org/stdlib/version"
2
+
3
+ module FeduxOrg
4
+ module Stdlib; end
5
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fedux_org-stdlib
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Max Meyer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: collection of use full libraries
47
+ email:
48
+ - dev@fedux.org
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.md
56
+ - README.md
57
+ - Rakefile
58
+ - fedux_org-stdlib.gemspec
59
+ - lib/fedux_org/stdlib.rb
60
+ - lib/fedux_org/stdlib/models/base.rb
61
+ - lib/fedux_org/stdlib/models/class_based_model.rb
62
+ - lib/fedux_org/stdlib/models/filesystem_based_model.rb
63
+ - lib/fedux_org/stdlib/version.rb
64
+ homepage: ''
65
+ licenses:
66
+ - MIT
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.23
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: collection of use full libraries
89
+ test_files: []
90
+ has_rdoc: