-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced some metaprograming techniques to make objects better to i…
…nteract with. Should be able to use setter methods now but haven't tested yet.
- Loading branch information
Tom Skarbek Wazynski
committed
Mar 30, 2015
1 parent
0209214
commit a572abc
Showing
26 changed files
with
919 additions
and
319 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ Gem::Specification.new do |spec| | |
spec.authors = ["Tom Skarbek Wazynski"] | ||
spec.email = ["[email protected]"] | ||
spec.summary = %q{Allows you to connect to Lancaster University Badge API to manipulate badges, issue badges and display badges.} | ||
spec.description = %q{Allows you to connect to Lancaster University Badge API to manipulate badges, issue badges and display badges.} | ||
spec.homepage = "http://innovationhub.lancaster.ac.uk" | ||
spec.license = "MIT" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#lib/badgeapi/badgeapi_object.rb | ||
|
||
module Badgeapi | ||
class BadgeapiObject | ||
class << self | ||
|
||
def define_attribute_methods attribute_names | ||
attribute_names.each do |name| | ||
define_method name.to_s do | ||
return instance_variable_get("@#{name}".to_sym) | ||
end | ||
|
||
define_method "#{name}=" do |val| | ||
instance_variable_set("@#{name}".to_sym, val) | ||
end | ||
end | ||
end | ||
|
||
attr_reader :attribute_names | ||
|
||
def initialize attributes = {} | ||
if instance_of? BadgeapiObject | ||
raise Error, | ||
"#{self.class} is an abstract class and cannot be instantiated" | ||
end | ||
|
||
self.attributes = attributes | ||
yield self if block_given? | ||
end | ||
|
||
def from_response attributes | ||
record = new | ||
|
||
attributes.each do |name, value| | ||
record.instance_variable_set "@#{name}", value | ||
#"@#{name}" = value.to_s | ||
end | ||
|
||
# record.persist! if record.respond_to? :persist! | ||
record | ||
end | ||
|
||
|
||
def from_json attributes = {} | ||
attributes.map { |attributes| new(attributes) } | ||
end | ||
|
||
attr_reader :attributes | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.