mockup_model 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,21 @@
1
+ README
2
+ ======
3
+
4
+
5
+ Summary
6
+ -------
7
+ A class that pretends to be an active record model, useful for mockups.
8
+
9
+
10
+ Installation
11
+ ------------
12
+ `gem install mockup_model`
13
+
14
+
15
+ Usage
16
+ -----
17
+
18
+
19
+ Description
20
+ -----------
21
+ A class that pretends to be an active record model, useful for mockups.
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../rake/lib', __FILE__))
2
+ Dir.glob(File.expand_path('../rake/tasks/**/*.{rake,task,rb}', __FILE__)) do |task_file|
3
+ begin
4
+ import task_file
5
+ rescue LoadError => e
6
+ warn "Failed to load task file #{task_file}"
7
+ warn " #{e.class} #{e.message}"
8
+ warn " #{e.backtrace.first}"
9
+ end
10
+ end
@@ -0,0 +1,97 @@
1
+ # encoding: utf-8
2
+
3
+
4
+
5
+ require 'active_model/naming'
6
+ require 'active_support/hash_with_indifferent_access'
7
+ require 'mockup_model/version'
8
+
9
+
10
+
11
+ # MockupModel
12
+ # A class that pretends to be an active record model, useful for mockups.
13
+ class MockupModel
14
+ rails_methods = %w[object_id respond_to? hash eql? equal? == send class inspect is_a? kind_of? to_yaml].map{|n|[n,n.to_sym]}.flatten
15
+ (Object.instance_methods - Object.instance_methods.grep(/^__/) - rails_methods).each do |m|
16
+ undef_method m
17
+ end
18
+
19
+ extend ActiveModel::Naming
20
+
21
+ def to_model
22
+ self
23
+ end
24
+
25
+ def to_key
26
+ [self.id]
27
+ end
28
+
29
+ def to_param
30
+ self.id
31
+ end
32
+
33
+ def valid?() true end
34
+ def new_record?() true end
35
+ def destroyed?() true end
36
+
37
+ def errors
38
+ obj = Object.new
39
+ def obj.[](key) [] end
40
+ def obj.full_messages() [] end
41
+ obj
42
+ end
43
+
44
+ def self.find(*)
45
+ new
46
+ end
47
+
48
+ def self.create(attrs={})
49
+ new(attrs)
50
+ end
51
+
52
+ attr_reader :attributes
53
+ def initialize(attrs={})
54
+ @attributes = HashWithIndifferentAccess.new(attrs)
55
+ end
56
+
57
+ def [](name)
58
+ @attributes[name]
59
+ end
60
+
61
+ def []=(name, value)
62
+ @attributes[name] = value
63
+ end
64
+
65
+ def respond_to_missing?(name, includeprivate=false)
66
+ true
67
+ end
68
+
69
+ def method_missing(name, *args)
70
+ case name.to_s
71
+ when /=$/ # assignment (obj.foo = value)
72
+ @attributes[name.to_s[0..-2]] = args.first
73
+ when /\?$/ # interrogation (obj.foo?)
74
+ raise ArgumentError, "Wrong number of arguments (method: #{name})" unless args.empty?
75
+ !!@attributes[name.to_s[0..-2]]
76
+ when /^[A-Z]\w*/i # reader (obj.foo)
77
+ raise ArgumentError, "Wrong number of arguments (method: #{name})" unless args.empty?
78
+ @attributes[name]
79
+ else
80
+ super
81
+ end
82
+ end
83
+
84
+ def save
85
+ true
86
+ end
87
+
88
+ def save!
89
+ true
90
+ end
91
+
92
+ def inspect
93
+ sprintf "\#<%s %s>",
94
+ self.class.name,
95
+ @attributes.map { |pair| "%s=%p" % pair }.join(" ")
96
+ end
97
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ begin
4
+ require 'rubygems/version' # newer rubygems use this
5
+ rescue LoadError
6
+ require 'gem/version' # older rubygems use this
7
+ end
8
+
9
+ class PseudoModel
10
+
11
+ # The version of the PseudoModel gem
12
+ Version = Gem::Version.new("0.0.1")
13
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "mockup_model"
5
+ s.version = "0.0.1"
6
+ s.authors = ["Stefan Rusterholz", "Swiss Life Select Schweiz"]
7
+ s.email = "stefan.rusterholz@gmail.com"
8
+ s.homepage = "https://github.com/apeiros/mockup_model"
9
+
10
+ s.description = <<-DESCRIPTION.gsub(/^ /, '').chomp
11
+ A class that pretends to be an active record model, useful for mockups.
12
+ DESCRIPTION
13
+ s.summary = <<-SUMMARY.gsub(/^ /, '').chomp
14
+ A class that pretends to be an active record model, useful for mockups.
15
+ SUMMARY
16
+
17
+ s.files =
18
+ Dir['bin/**/*'] +
19
+ Dir['lib/**/*'] +
20
+ Dir['rake/**/*'] +
21
+ Dir['test/**/*'] +
22
+ Dir['*.gemspec'] +
23
+ %w[
24
+ Rakefile
25
+ README.markdown
26
+ ]
27
+
28
+ if File.directory?('bin') then
29
+ s.executables = Dir.chdir('bin') { Dir.glob('**/*').select { |f| File.executable?(f) } }
30
+ end
31
+
32
+ s.required_ruby_version = ">= 1.9.2"
33
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1")
34
+ s.rubygems_version = "1.3.1"
35
+ s.specification_version = 3
36
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mockup_model
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Stefan Rusterholz
9
+ - Swiss Life Select Schweiz
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-05-16 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description: A class that pretends to be an active record model, useful for mockups.
16
+ email: stefan.rusterholz@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/mockup_model/version.rb
22
+ - lib/mockup_model.rb
23
+ - mockup_model.gemspec
24
+ - Rakefile
25
+ - README.markdown
26
+ homepage: https://github.com/apeiros/mockup_model
27
+ licenses: []
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.9.2
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>'
42
+ - !ruby/object:Gem::Version
43
+ version: 1.3.1
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 1.8.25
47
+ signing_key:
48
+ specification_version: 3
49
+ summary: A class that pretends to be an active record model, useful for mockups.
50
+ test_files: []
51
+ has_rdoc: